Magellan Linux

Annotation of /trunk/vnc/patches/vnc-ipv6.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations) (download)
Tue May 8 20:52:56 2007 UTC (17 years, 1 month ago) by niro
File size: 2102 byte(s)
-import

1 niro 153 --- common/network/TcpSocket.cxx.ipv6 2006-10-13 11:31:37.000000000 +0100
2     +++ common/network/TcpSocket.cxx 2006-10-13 12:05:40.000000000 +0100
3     @@ -106,11 +106,29 @@
4     TcpSocket::TcpSocket(const char *host, int port)
5     : closeFd(true)
6     {
7     + struct sockaddr_storage addr;
8     + size_t addrlen;
9     + struct addrinfo *hostai;
10     int sock;
11    
12     - // - Create a socket
13     initSockets();
14     - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
15     +
16     + if (getaddrinfo(host, NULL, NULL, &hostai)) {
17     + int e = errorNumber;
18     + throw SocketException("unable to resolve host by name", e);
19     + }
20     +
21     + addrlen = hostai->ai_addrlen;
22     + memset(&addr, 0, sizeof(addr));
23     + memcpy(&addr, hostai->ai_addr, addrlen);
24     + freeaddrinfo(hostai);
25     + if (addr.ss_family == AF_INET)
26     + ((struct sockaddr_in *)&addr)->sin_port = htons(port);
27     + else if (addr.ss_family == AF_INET6)
28     + ((struct sockaddr_in6 *)&addr)->sin6_port = htons(port);
29     +
30     + // - Create a socket
31     + if ((sock = socket(addr.ss_family, SOCK_STREAM, 0)) < 0)
32     throw SocketException("unable to create socket", errorNumber);
33    
34     #ifndef WIN32
35     @@ -118,30 +136,9 @@
36     fcntl(sock, F_SETFD, FD_CLOEXEC);
37     #endif
38    
39     - // - Connect it to something
40     -
41     - // Try processing the host as an IP address
42     - struct sockaddr_in addr;
43     - memset(&addr, 0, sizeof(addr));
44     - addr.sin_family = AF_INET;
45     - addr.sin_addr.s_addr = inet_addr(host);
46     - addr.sin_port = htons(port);
47     - if ((int)addr.sin_addr.s_addr == -1) {
48     - // Host was not an IP address - try resolving as DNS name
49     - struct hostent *hostinfo;
50     - hostinfo = gethostbyname(host);
51     - if (hostinfo && hostinfo->h_addr) {
52     - addr.sin_addr.s_addr = ((struct in_addr *)hostinfo->h_addr)->s_addr;
53     - } else {
54     - int e = errorNumber;
55     - closesocket(sock);
56     - throw SocketException("unable to resolve host by name", e);
57     - }
58     - }
59     -
60     // Attempt to connect to the remote host
61     for (;;) {
62     - if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
63     + if (connect(sock, (struct sockaddr *)&addr, addrlen) != 0) {
64     int e = errorNumber;
65     if (e == EINTR)
66     continue;
67