diff options
author | Christian Beier <[email protected]> | 2012-03-10 21:31:44 +0100 |
---|---|---|
committer | Christian Beier <[email protected]> | 2012-03-10 21:31:44 +0100 |
commit | 75bfb1f5d396b2908a9615cd02bebfc952baa045 (patch) | |
tree | 9f775fdd6b00f83cdaf7f0fc45601b825fd6521d /libvncserver/sockets.c | |
parent | edc75fa4f4f0dbadf7cb21a7511626dd35a3c330 (diff) | |
download | libtdevnc-75bfb1f5d396b2908a9615cd02bebfc952baa045.tar.gz libtdevnc-75bfb1f5d396b2908a9615cd02bebfc952baa045.zip |
IPv6 support for LibVNCServer, part three: make reverse connections IPv6-capable.
Besided making libvncserver reverseVNC IPv6-aware, this introduces some changes
on the client side as well to make clients listen on IPv6 sockets, too. Like
the server side, this also uses a separate-socket approach.
Diffstat (limited to 'libvncserver/sockets.c')
-rw-r--r-- | libvncserver/sockets.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c index 723e769..1727eb0 100644 --- a/libvncserver/sockets.c +++ b/libvncserver/sockets.c @@ -937,8 +937,46 @@ int rfbConnectToTcpAddr(char *host, int port) { - struct hostent *hp; int sock; +#ifdef LIBVNCSERVER_IPv6 + struct addrinfo hints, *servinfo, *p; + int rv; + char port_str[8]; + + snprintf(port_str, 8, "%d", port); + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if ((rv = getaddrinfo(host, port_str, &hints, &servinfo)) != 0) { + rfbErr("rfbConnectToTcpAddr: error in getaddrinfo: %s\n", gai_strerror(rv)); + return -1; + } + + /* loop through all the results and connect to the first we can */ + for(p = servinfo; p != NULL; p = p->ai_next) { + if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) + continue; + + if (connect(sock, p->ai_addr, p->ai_addrlen) < 0) { + closesocket(sock); + continue; + } + + break; + } + + /* all failed */ + if (p == NULL) { + rfbLogPerror("rfbConnectToTcoAddr: failed to connect\n"); + sock = -1; /* set return value */ + } + + /* all done with this structure now */ + freeaddrinfo(servinfo); +#else + struct hostent *hp; struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); @@ -962,7 +1000,7 @@ rfbConnectToTcpAddr(char *host, closesocket(sock); return -1; } - +#endif return sock; } |