Patch: Using OSXvnc over IPv6
Shadow Hawkins on Tuesday, 01 March 2005 13:04:09
I use the following small patch to enable OSXvnc to accept IPv6 and IPv4 connections.
Index: main.c
===================================================================
RCS file: /cvsroot/osxvnc/OSXvnc/OSXvnc-server/main.c,v
retrieving revision 1.16
diff -u -r1.16 main.c
--- main.c20 Jan 2005 16:42:45 -00001.16
+++ main.c1 Mar 2005 11:54:20 -0000
@@ -460,21 +460,21 @@
static void *listenerRun(void *ignore) {
int listen_fd, client_fd;
- struct sockaddr_in sin, peer;
+ struct sockaddr_in6 sin, peer;
pthread_t client_thread;
rfbClientPtr cl;
int len, value;
bzero(&sin, sizeof(sin));
- sin.sin_len = sizeof(sin);
- sin.sin_family = AF_INET;
+ sin.sin6_len = sizeof(sin);
+ sin.sin6_family = AF_INET6;
if (rfbLocalhostOnly)
- sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ sin.sin6_addr = in6addr_loopback;
else
- sin.sin_addr.s_addr = htonl(INADDR_ANY);
- sin.sin_port = htons(rfbPort);
+ sin.sin6_addr = in6addr_any;
+ sin.sin6_port = htons(rfbPort);
- if ((listen_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
+ if ((listen_fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
return NULL;
}
value = 1;
Index: rfbserver.c
===================================================================
RCS file: /cvsroot/osxvnc/OSXvnc/OSXvnc-server/rfbserver.c,v
retrieving revision 1.12
diff -u -r1.12 rfbserver.c
--- rfbserver.c1 Feb 2005 18:01:00 -00001.12
+++ rfbserver.c1 Mar 2005 11:54:21 -0000
@@ -107,27 +107,26 @@
*/
rfbClientPtr rfbReverseConnection(char *host, int port) {
int sock;
- struct sockaddr_in sin;
+ struct sockaddr_in6 sin;
+ struct addrinfo *res, hint;
+ int errCode;
rfbClientPtr cl;
bzero(&sin, sizeof(sin));
- sin.sin_len = sizeof(sin);
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = inet_addr(host);
- sin.sin_port = htons(port);
- if ((int)sin.sin_addr.s_addr == -1) {
- struct hostent *hostinfo;
- hostinfo = gethostbyname(host);
- if (hostinfo && hostinfo->h_addr) {
- sin.sin_addr.s_addr = ((struct in_addr *)hostinfo->h_addr)->s_addr;
- }
- else {
- rfbLog("Error resolving reverse host %s\n", host);
+ sin.sin6_len = sizeof(sin);
+ sin.sin6_family = AF_INET6;
+ sin.sin6_port = htons(port);
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_family = PF_INET6;
+ hint.ai_socktype = SOCK_STREAM;
+ if ((errCode = getaddrinfo(host, NULL, &hint, &res)) != 0) {
+ rfbLog("Error resolving reverse host %s: %s\n", host, gai_strerror(errCode));
return NULL;
- }
}
+ sin.sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
+ freeaddrinfo(res);
- if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
+ if ((sock = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
rfbLog("Error creating reverse socket\n");
return NULL;
}
@@ -155,8 +154,9 @@
rfbProtocolVersionMsg pv;
rfbClientPtr cl;
BoxRec box;
- struct sockaddr_in addr;
- int i, addrlen = sizeof(struct sockaddr_in);
+ struct sockaddr_in6 addr;
+ int i, addrlen = sizeof(struct sockaddr_in6);
+ char host[NI_MAXHOST];
/*
{
@@ -175,7 +175,9 @@
cl->sock = sock;
getpeername(sock, (struct sockaddr *)&addr, &addrlen);
- cl->host = strdup(inet_ntoa(addr.sin_addr));
+ host[0] = 0;
+ getnameinfo((struct sockaddr *)&addr, addrlen, host, sizeof(host), NULL, 0, 0);
+ cl->host = strdup(host);
pthread_mutex_init(&cl->outputMutex, NULL);
Posting is only allowed when you are logged in. |