def interface(host):
    """Return an IP address for a client connection given the server host.

    If the server is listening on '0.0.0.0' (INADDR_ANY)
    or '::' (IN6ADDR_ANY), this will return the proper localhost.
    """
    if host == '0.0.0.0':
        # INADDR_ANY, which should respond on localhost.
        return '127.0.0.1'
    if host == '::':
        # IN6ADDR_ANY, which should respond on localhost.
        return '::1'
    return host