1 --- common/network/TcpSocket.cxx.orig 2010-02-12 03:19:32.000000000 -0600
2 +++ common/network/TcpSocket.cxx 2011-04-11 10:58:52.000000000 -0500
10 + // - localhostOnly will mean "127.0.0.1 only", no IPv6
11 + if (use_ipv6 = !localhostOnly)
21 - if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
22 - throw SocketException("unable to create listening socket", errorNumber);
23 + if ((fd = socket(af, SOCK_STREAM, 0)) < 0) {
24 + // - Socket creation failed
26 + // - We were trying to make an IPv6-capable socket - try again, but IPv4-only
29 + fd = socket(af, SOCK_STREAM, 0);
32 + throw SocketException("unable to create listening socket", errorNumber);
34 + // - Socket creation succeeded
36 + // - We made an IPv6-capable socket, and we need it to do IPv4 too
38 + setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
43 // - By default, close the socket on exec()
46 // - Bind it to the desired port
47 struct sockaddr_in addr;
48 - memset(&addr, 0, sizeof(addr));
49 - addr.sin_family = AF_INET;
51 - if (localhostOnly) {
52 - addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
53 - } else if (listenaddr != NULL) {
54 + struct sockaddr_in6 addr6;
55 + struct sockaddr *sa;
59 + sa_len = sizeof(addr6);
60 + memset(&addr6, 0, sa_len);
61 + addr6.sin6_family = af;
62 + addr6.sin6_port = htons(port);
63 + sa = (struct sockaddr*) &addr6;
65 + sa_len = sizeof(addr);
66 + memset(&addr, 0, sa_len);
67 + addr.sin_family = af;
68 + addr.sin_port = htons(port);
70 + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
71 + else if (listenaddr != NULL) {
73 - if (inet_aton(listenaddr, &addr.sin_addr) == 0)
74 + if (inet_aton(listenaddr, &addr.sin_addr) == 0)
76 - /* Some systems (e.g. Windows) do not have inet_aton, sigh */
77 - if ((addr.sin_addr.s_addr = inet_addr(listenaddr)) == INADDR_NONE)
78 + /* Some systems (e.g. Windows) do not have inet_aton, sigh */
79 + if ((addr.sin_addr.s_addr = inet_addr(listenaddr)) == INADDR_NONE)
83 - throw Exception("invalid network interface address: %s", listenaddr);
86 - addr.sin_addr.s_addr = htonl(INADDR_ANY); /* Bind to 0.0.0.0 by default. */
88 - addr.sin_port = htons(port);
89 - if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
92 + throw Exception("invalid network interface address: %s", listenaddr);
95 + addr.sin_addr.s_addr = htonl(INADDR_ANY); /* Bind to 0.0.0.0 by default. */
96 + sa = (struct sockaddr*) &addr;
98 + if (bind(fd, sa, sa_len) < 0) {
101 throw SocketException("unable to bind listening socket", e);