1 /* |
1 /* |
2 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
88 int rv; |
88 int rv; |
89 |
89 |
90 #if defined(__solaris__) |
90 #if defined(__solaris__) |
91 rv = connect(fd, 0, 0); |
91 rv = connect(fd, 0, 0); |
92 #else |
92 #else |
93 int len; |
|
94 SOCKETADDRESS sa; |
93 SOCKETADDRESS sa; |
|
94 socklen_t len = isIPv6 ? sizeof(struct sockaddr_in6) : |
|
95 sizeof(struct sockaddr_in); |
95 |
96 |
96 memset(&sa, 0, sizeof(sa)); |
97 memset(&sa, 0, sizeof(sa)); |
97 |
|
98 #ifdef AF_INET6 |
|
99 if (isIPv6) { |
|
100 #if defined(_ALLBSD_SOURCE) |
98 #if defined(_ALLBSD_SOURCE) |
101 sa.sa6.sin6_family = AF_INET6; |
99 sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET; |
102 #else |
100 #else |
103 sa.sa6.sin6_family = AF_UNSPEC; |
101 sa.sa.sa_family = AF_UNSPEC; |
104 #endif |
102 #endif |
105 len = sizeof(struct sockaddr_in6); |
|
106 } else |
|
107 #endif |
|
108 { |
|
109 #if defined(_ALLBSD_SOURCE) |
|
110 sa.sa4.sin_family = AF_INET; |
|
111 #else |
|
112 sa.sa4.sin_family = AF_UNSPEC; |
|
113 #endif |
|
114 len = sizeof(struct sockaddr_in); |
|
115 } |
|
116 |
103 |
117 rv = connect(fd, &sa.sa, len); |
104 rv = connect(fd, &sa.sa, len); |
118 |
105 |
119 #if defined(_ALLBSD_SOURCE) |
106 #if defined(_ALLBSD_SOURCE) |
120 if (rv < 0 && errno == EADDRNOTAVAIL) |
107 if (rv < 0 && errno == EADDRNOTAVAIL) |
124 * 'Setting the address family to AF_UNSPEC might return EAFNOSUPPORT |
111 * 'Setting the address family to AF_UNSPEC might return EAFNOSUPPORT |
125 * but that is acceptable. |
112 * but that is acceptable. |
126 */ |
113 */ |
127 if (rv < 0 && errno == EAFNOSUPPORT) |
114 if (rv < 0 && errno == EAFNOSUPPORT) |
128 rv = errno = 0; |
115 rv = errno = 0; |
129 #endif |
116 #endif // defined(_ALLBSD_SOURCE) || defined(_AIX) |
130 #endif |
117 |
|
118 #endif // defined(__solaris__) |
131 |
119 |
132 if (rv < 0) |
120 if (rv < 0) |
133 handleSocketError(env, errno); |
121 handleSocketError(env, errno); |
134 } |
122 } |
135 |
123 |