Magellan Linux

Contents of /trunk/vnc/patches/vnc-ipv6-2.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 639 - (show annotations) (download)
Tue Jun 3 20:56:41 2008 UTC (15 years, 11 months ago) by niro
File size: 6101 byte(s)
-renamed patch

1 diff -up vnc-4_1_2-unixsrc/common/network/Makefile.am.ipv6 vnc-4_1_2-unixsrc/common/network/Makefile.am
2 --- vnc-4_1_2-unixsrc/common/network/Makefile.am.ipv6 2008-06-02 10:22:17.000000000 +0200
3 +++ vnc-4_1_2-unixsrc/common/network/Makefile.am 2008-06-02 10:52:56.000000000 +0200
4 @@ -1,5 +1,7 @@
5 noinst_LTLIBRARIES = libnetwork.la
6
7 +libnetwork_la_CPPFLAGS = -DHAVE_GETADDRINFO
8 +
9 libnetwork_la_SOURCES = \
10 Socket.h \
11 TcpSocket.cxx \
12 diff -up vnc-4_1_2-unixsrc/common/network/TcpSocket.cxx.ipv6 vnc-4_1_2-unixsrc/common/network/TcpSocket.cxx
13 --- vnc-4_1_2-unixsrc/common/network/TcpSocket.cxx.ipv6 2008-06-02 10:22:17.000000000 +0200
14 +++ vnc-4_1_2-unixsrc/common/network/TcpSocket.cxx 2008-06-02 10:49:04.000000000 +0200
15 @@ -109,50 +109,99 @@ TcpSocket::TcpSocket(int sock, bool clos
16 TcpSocket::TcpSocket(const char *host, int port)
17 : closeFd(true)
18 {
19 - int sock;
20 +#define CAST_ADDR(x) (*((struct x *)&addr))
21 + int sock, err, family, result = -1;
22 + size_t addrlen;
23 + struct sockaddr_storage addr;
24 +#ifdef HAVE_GETADDRINFO
25 + struct addrinfo *ai, *current, hints;
26 +#endif
27
28 // - Create a socket
29 initSockets();
30 - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
31 - throw SocketException("unable to create socket", errorNumber);
32
33 -#ifndef WIN32
34 - // - By default, close the socket on exec()
35 - fcntl(sock, F_SETFD, FD_CLOEXEC);
36 -#endif
37 +#ifdef HAVE_GETADDRINFO
38 + memset(&hints, 0, sizeof(struct addrinfo));
39 + hints.ai_family = AF_UNSPEC;
40 + hints.ai_socktype = SOCK_STREAM;
41 + hints.ai_canonname = NULL;
42 + hints.ai_addr = NULL;
43 + hints.ai_next = NULL;
44 +
45 + if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) {
46 + throw Exception("unable to resolve host by name: %s",
47 + gai_strerror(result));
48 + }
49 +
50 + for (current = ai; current != NULL; current = current->ai_next) {
51 + family = current->ai_family;
52 + if (family != AF_INET && family != AF_INET6)
53 + continue;
54 +
55 + addrlen = current->ai_addrlen;
56 + memcpy(&addr, current->ai_addr, addrlen);
57 +
58 + if (family == AF_INET)
59 + CAST_ADDR(sockaddr_in).sin_port = htons(port);
60 + else
61 + CAST_ADDR(sockaddr_in6).sin6_port = htons(port);
62
63 - // - Connect it to something
64 +#else
65 + family = AF_INET;
66 + addrlen = sizeof(struct sockaddr_in);
67
68 - // Try processing the host as an IP address
69 - struct sockaddr_in addr;
70 - memset(&addr, 0, sizeof(addr));
71 - addr.sin_family = AF_INET;
72 - addr.sin_addr.s_addr = inet_addr(host);
73 - addr.sin_port = htons(port);
74 - if ((int)addr.sin_addr.s_addr == -1) {
75 - // Host was not an IP address - try resolving as DNS name
76 - struct hostent *hostinfo;
77 - hostinfo = gethostbyname(host);
78 - if (hostinfo && hostinfo->h_addr) {
79 - addr.sin_addr.s_addr = ((struct in_addr *)hostinfo->h_addr)->s_addr;
80 - } else {
81 - int e = errorNumber;
82 - closesocket(sock);
83 - throw SocketException("unable to resolve host by name", e);
84 + // Try processing the host as an IP address
85 + memset(&addr, 0, addrlen);
86 + CAST_ADDR(sockaddr_in).sin_family = AF_INET;
87 + CAST_ADDR(sockaddr_in).sin_addr.s_addr = inet_addr(host);
88 + CAST_ADDR(sockaddr_in).sin_port = htons(port);
89 + if ((int)CAST_ADDR(sockaddr_in).sin_addr.s_addr == -1) {
90 + // Host was not an IP address - try resolving as DNS name
91 + struct hostent *hostinfo;
92 + hostinfo = gethostbyname(host);
93 + if (hostinfo && hostinfo->h_addr) {
94 + CAST_ADDR(sockaddr_in).sin_addr.s_addr =
95 + ((struct in_addr *)hostinfo->h_addr)->s_addr;
96 + } else {
97 + err = errorNumber;
98 + throw SocketException("unable to resolve host by name", err);
99 + }
100 + }
101 +#endif
102 + sock = socket (family, SOCK_STREAM, 0);
103 + if (sock == -1) {
104 + err = errorNumber;
105 +#ifdef HAVE_GETADDRINFO
106 + freeaddrinfo(ai);
107 +#endif
108 + throw SocketException("unable to create socket", err);
109 }
110 - }
111
112 - // Attempt to connect to the remote host
113 - for (;;) {
114 - if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
115 - int e = errorNumber;
116 - if (e == EINTR)
117 - continue;
118 + // Attempt to connect to the remote host
119 + while ((result = connect(sock, (struct sockaddr *)&addr, addrlen)) == -1) {
120 + err = errorNumber;
121 + if (err == EINTR)
122 + continue;
123 closesocket(sock);
124 - throw SocketException("unable to connect to host", e);
125 - } else break;
126 + break;
127 + }
128 +#ifdef HAVE_GETADDRINFO
129 + if (result == 0)
130 + break;
131 + else
132 + continue;
133 }
134
135 + freeaddrinfo(ai);
136 +#endif
137 + if (result == -1)
138 + throw SocketException("unable connect to socket", err);
139 +
140 +#ifndef WIN32
141 + // - By default, close the socket on exec()
142 + fcntl(sock, F_SETFD, FD_CLOEXEC);
143 +#endif
144 +
145 // Disable Nagle's algorithm, to reduce latency
146 enableNagles(sock, false);
147
148 diff -up vnc-4_1_2-unixsrc/common/rdr/Exception.cxx.ipv6 vnc-4_1_2-unixsrc/common/rdr/Exception.cxx
149 --- vnc-4_1_2-unixsrc/common/rdr/Exception.cxx.ipv6 2008-06-02 10:23:35.000000000 +0200
150 +++ vnc-4_1_2-unixsrc/common/rdr/Exception.cxx 2008-06-02 10:28:51.000000000 +0200
151 @@ -22,8 +22,23 @@
152 #include <winsock2.h>
153 #endif
154
155 +#include <stdarg.h>
156 +
157 using namespace rdr;
158
159 +Exception::Exception(const char *format, ...) {
160 + va_list ap;
161 + int result;
162 +
163 + va_start(ap, format);
164 + result = vsnprintf(str_, len, format, ap);
165 + va_end(ap);
166 +
167 + /* XXX - ensure that string ends correctly */
168 + if (result > len)
169 + str_[len - 1] = '\0';
170 +}
171 +
172 SystemException::SystemException(const char* s, int err_)
173 : Exception(s), err(err_)
174 {
175 diff -up vnc-4_1_2-unixsrc/common/rdr/Exception.h.ipv6 vnc-4_1_2-unixsrc/common/rdr/Exception.h
176 --- vnc-4_1_2-unixsrc/common/rdr/Exception.h.ipv6 2008-06-02 10:23:05.000000000 +0200
177 +++ vnc-4_1_2-unixsrc/common/rdr/Exception.h 2008-06-02 10:28:41.000000000 +0200
178 @@ -27,13 +27,7 @@ namespace rdr {
179 struct Exception {
180 enum { len = 256 };
181 char str_[len];
182 - Exception(const char* s=0) {
183 - str_[0] = 0;
184 - if (s)
185 - strncat(str_, s, len-1);
186 - else
187 - strcat(str_, "Exception");
188 - }
189 + Exception(const char *format, ...);
190 virtual const char* str() const { return str_; }
191 };
192