From 68e7696a27b31034876f594f242a229ff2b74fa4 Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Tue, 29 Jun 2010 20:51:08 +0800 Subject: libvncclient: add ipv6 support [jes: pulled the "host" declarations into the conditionally compiled blocks where that variable is used. Also fixed non-IPv6 connections.] Signed-off-by: Vic Lee Signed-off-by: Johannes Schindelin --- libvncclient/sockets.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'libvncclient/sockets.c') diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index 598dd39..ff4fe48 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -336,6 +336,68 @@ ConnectClientToTcpAddr(unsigned int host, int port) return sock; } +int +ConnectClientToTcpAddr6(const char *hostname, int port) +{ +#ifdef LIBVNCSERVER_IPv6 + int sock; + int n; + struct addrinfo hints, *res, *ressave; + char port_s[10]; + int one = 1; + + if (!initSockets()) + return -1; + + snprintf(port_s, 10, "%d", port); + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if ((n = getaddrinfo(hostname, port_s, &hints, &res))) + { + rfbClientErr("ConnectClientToTcpAddr6: getaddrinfo (%s)\n", gai_strerror(n)); + return -1; + } + + ressave = res; + sock = -1; + while (res) + { + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (sock >= 0) + { + if (connect(sock, res->ai_addr, res->ai_addrlen) == 0) + break; + close(sock); + sock = -1; + } + res = res->ai_next; + } + freeaddrinfo(ressave); + + if (sock == -1) + { + rfbClientErr("ConnectClientToTcpAddr6: connect\n"); + return -1; + } + + if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, + (char *)&one, sizeof(one)) < 0) { + rfbClientErr("ConnectToTcpAddr: setsockopt\n"); + close(sock); + return -1; + } + + return sock; + +#else + + rfbClientErr("ConnectClientToTcpAddr6: IPv6 disabled\n"); + return -1; + +#endif +} + int ConnectClientToUnixSock(const char *sockFile) { -- cgit v1.2.3