[Spice-devel] [PATCH 2/2] spice client: add ipv6 support.

Izik Eidus ieidus at redhat.com
Sat Feb 20 01:59:32 PST 2010


On Fri, 19 Feb 2010 12:21:03 +0100
Gerd Hoffmann <kraxel at redhat.com> wrote:

> 
> Signed-off-by: Gerd Hoffmann <kraxel at redhat.com>
> ---
>  client/red_peer.cpp |   89 +++++++++++++++++++++++---------------------------
>  1 files changed, 41 insertions(+), 48 deletions(-)
> 
> diff --git a/client/red_peer.cpp b/client/red_peer.cpp
> index f252ef2..a6afcc2 100644
> --- a/client/red_peer.cpp
> +++ b/client/red_peer.cpp
> @@ -69,60 +69,53 @@ void RedPeer::cleanup()
>      }
>  }
>  
> -uint32_t RedPeer::host_by_name(const char* host)
> +void RedPeer::connect_unsecure(const char* host, int portnr)
>  {
> -    struct addrinfo *result = NULL;
> -    struct sockaddr_in *addr;
> -    uint32_t return_value;
> -    int rc;
> -
> -    rc = getaddrinfo(host, NULL, NULL, &result);
> -    while (result != NULL && result->ai_family != PF_INET)
> -        result = result->ai_next;
> -    if (rc != 0 || result == NULL) {
> -        THROW_ERR(SPICEC_ERROR_CODE_GETHOSTBYNAME_FAILED, "cannot resolve host address %s", host);
> -    }
> -
> -    addr = (sockaddr_in *)result->ai_addr;
> -    return_value = addr->sin_addr.s_addr;
> -
> -    freeaddrinfo(result);
> -
> -    DBG(0, "%s = %u", host, return_value);
> -    return ntohl(return_value);
> -}
> -
> -void RedPeer::connect_unsecure(const char* host, int port)
> -{
> -    struct sockaddr_in addr;
> -    int no_delay;
> -    uint32_t ip;
> +    struct addrinfo ai, *result = NULL, *e;
> +    char uaddr[INET6_ADDRSTRLEN+1];
> +    char uport[33], port[33];
> +    int err = 0, rc, no_delay = 1;
>      ASSERT(_ctx == NULL && _ssl == NULL && _peer == INVALID_SOCKET);
>      try {
> -        ip = host_by_name(host);
> -
> -        addr.sin_port = htons(port);
> -        addr.sin_family = AF_INET;
> -        addr.sin_addr.s_addr = htonl(ip);
> -
> -        Lock lock(_lock);
> -        if ((_peer = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
> -            int err = sock_error();
> -            THROW_ERR(SPICEC_ERROR_CODE_SOCKET_FAILED, "failed to create socket: %s (%d)",
> -                      sock_err_message(err), err);
> +        memset(&ai,0, sizeof(ai));
> +        ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
> +        ai.ai_family = PF_UNSPEC;
> +        ai.ai_socktype = SOCK_STREAM;
> +        snprintf(port, sizeof(port), "%d", portnr);
> +        rc = getaddrinfo(host, port, &ai, &result);
> +        if (rc != 0) {
> +            THROW_ERR(SPICEC_ERROR_CODE_GETHOSTBYNAME_FAILED, "cannot resolve host address %s", host);
>          }
> +        Lock lock(_lock);
> +        _peer = -1;
> +        for (e = result; e != NULL; e = e->ai_next) {
> +            if ((_peer = socket(e->ai_family, e->ai_socktype, e->ai_protocol)) == INVALID_SOCKET) {
> +                int err = sock_error();
> +                THROW_ERR(SPICEC_ERROR_CODE_SOCKET_FAILED, "failed to create socket: %s (%d)",
> +                          sock_err_message(err), err);


Hi, patch look good.

just 2 comments:

first: you probably want to remove static uint32_t host_by_name(const char *host);
from red_peer.h

2: It isnt your fault beacuse it was in the code before (in host_by_name())
but I just wondering isnt this throw should be handled at the catch () { }
of the try, with freeaddrinfo of result?

Thanks.


More information about the Spice-devel mailing list