author | clanger |
Wed, 02 Nov 2016 11:52:51 +0100 | |
changeset 41834 | 99c4f72c0a91 |
parent 41771 | 18c9669e76ca |
child 42475 | c80ab3b11401 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36115 | 2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
25 |
#include <dlfcn.h> |
2 | 26 |
#include <errno.h> |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
27 |
#include <net/if.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
28 |
#include <netinet/tcp.h> // defines TCP_NODELAY |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
29 |
#include <stdlib.h> |
2 | 30 |
#include <string.h> |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
31 |
#include <sys/ioctl.h> |
40937
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
32 |
#include <sys/time.h> |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
33 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
34 |
#if defined(__linux__) |
2 | 35 |
#include <arpa/inet.h> |
36 |
#include <net/route.h> |
|
37 |
#include <sys/utsname.h> |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
38 |
#endif |
2 | 39 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
40 |
#if defined(__solaris__) |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
41 |
#include <inet/nd.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
42 |
#include <limits.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
43 |
#include <stropts.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
44 |
#include <sys/filio.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
45 |
#include <sys/sockio.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
46 |
#endif |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
47 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
48 |
#include "net_util.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
49 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
50 |
#include "java_net_SocketOptions.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
51 |
#include "java_net_InetAddress.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
52 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
53 |
#if defined(__linux__) && !defined(IPV6_FLOWINFO_SEND) |
2 | 54 |
#define IPV6_FLOWINFO_SEND 33 |
55 |
#endif |
|
56 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
57 |
#if defined(__solaris__) && !defined(MAXINT) |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
58 |
#define MAXINT INT_MAX |
23028
0554f6183d11
8035876: AIX build issues after '8034174: Remove use of JVM_* functions from java.net code'
simonis
parents:
23015
diff
changeset
|
59 |
#endif |
0554f6183d11
8035876: AIX build issues after '8034174: Remove use of JVM_* functions from java.net code'
simonis
parents:
23015
diff
changeset
|
60 |
|
2 | 61 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
62 |
* EXCLBIND socket options only on Solaris |
2 | 63 |
*/ |
64 |
#if defined(__solaris__) && !defined(TCP_EXCLBIND) |
|
65 |
#define TCP_EXCLBIND 0x21 |
|
66 |
#endif |
|
67 |
#if defined(__solaris__) && !defined(UDP_EXCLBIND) |
|
68 |
#define UDP_EXCLBIND 0x0101 |
|
69 |
#endif |
|
70 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
71 |
void setDefaultScopeID(JNIEnv *env, struct sockaddr *him) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
72 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
73 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
74 |
static jclass ni_class = NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
75 |
static jfieldID ni_defaultIndexID; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
76 |
if (ni_class == NULL) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
77 |
jclass c = (*env)->FindClass(env, "java/net/NetworkInterface"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
78 |
CHECK_NULL(c); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
79 |
c = (*env)->NewGlobalRef(env, c); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
80 |
CHECK_NULL(c); |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
81 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); |
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
82 |
CHECK_NULL(ni_defaultIndexID); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
83 |
ni_class = c; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
84 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
85 |
int defaultIndex; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
86 |
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)him; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
87 |
if (sin6->sin6_family == AF_INET6 && (sin6->sin6_scope_id == 0)) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
88 |
defaultIndex = (*env)->GetStaticIntField(env, ni_class, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
89 |
ni_defaultIndexID); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
90 |
sin6->sin6_scope_id = defaultIndex; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
91 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
92 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
93 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
94 |
|
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
95 |
int getDefaultScopeID(JNIEnv *env) { |
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
96 |
int defaultIndex = 0; |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
97 |
static jclass ni_class = NULL; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
98 |
static jfieldID ni_defaultIndexID; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
99 |
if (ni_class == NULL) { |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
100 |
jclass c = (*env)->FindClass(env, "java/net/NetworkInterface"); |
12856
712335896cc4
7171591: getDefaultScopeID() in src/solaris/native/java/net/net_util_md.c should return a value
khazra
parents:
12688
diff
changeset
|
101 |
CHECK_NULL_RETURN(c, 0); |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
102 |
c = (*env)->NewGlobalRef(env, c); |
12856
712335896cc4
7171591: getDefaultScopeID() in src/solaris/native/java/net/net_util_md.c should return a value
khazra
parents:
12688
diff
changeset
|
103 |
CHECK_NULL_RETURN(c, 0); |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
104 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); |
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
105 |
CHECK_NULL_RETURN(ni_defaultIndexID, 0); |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
106 |
ni_class = c; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
107 |
} |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
108 |
defaultIndex = (*env)->GetStaticIntField(env, ni_class, |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
109 |
ni_defaultIndexID); |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
110 |
return defaultIndex; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
111 |
} |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
112 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
113 |
#define RESTARTABLE(_cmd, _result) do { \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
114 |
do { \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
115 |
_result = _cmd; \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
116 |
} while((_result == -1) && (errno == EINTR)); \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
117 |
} while(0) |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
118 |
|
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
119 |
int NET_SocketAvailable(int s, jint *pbytes) { |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
120 |
int result; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
121 |
RESTARTABLE(ioctl(s, FIONREAD, pbytes), result); |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
122 |
// note: ioctl can return 0 when successful, NET_SocketAvailable |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
123 |
// is expected to return 0 on failure and 1 on success. |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
124 |
return (result == -1) ? 0 : 1; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
125 |
} |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
126 |
|
2 | 127 |
#ifdef __solaris__ |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
128 |
static int init_tcp_max_buf, init_udp_max_buf; |
2 | 129 |
static int tcp_max_buf; |
130 |
static int udp_max_buf; |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
131 |
static int useExclBind = 0; |
2 | 132 |
|
133 |
/* |
|
134 |
* Get the specified parameter from the specified driver. The value |
|
135 |
* of the parameter is assumed to be an 'int'. If the parameter |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
136 |
* cannot be obtained return -1 |
2 | 137 |
*/ |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
138 |
int net_getParam(char *driver, char *param) |
2 | 139 |
{ |
140 |
struct strioctl stri; |
|
141 |
char buf [64]; |
|
142 |
int s; |
|
143 |
int value; |
|
144 |
||
145 |
s = open (driver, O_RDWR); |
|
146 |
if (s < 0) { |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
147 |
return -1; |
2 | 148 |
} |
149 |
strncpy (buf, param, sizeof(buf)); |
|
150 |
stri.ic_cmd = ND_GET; |
|
151 |
stri.ic_timout = 0; |
|
152 |
stri.ic_dp = buf; |
|
153 |
stri.ic_len = sizeof(buf); |
|
154 |
if (ioctl (s, I_STR, &stri) < 0) { |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
155 |
value = -1; |
2 | 156 |
} else { |
157 |
value = atoi(buf); |
|
158 |
} |
|
159 |
close (s); |
|
160 |
return value; |
|
161 |
} |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
162 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
163 |
/* |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
164 |
* Iterative way to find the max value that SO_SNDBUF or SO_RCVBUF |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
165 |
* for Solaris versions that do not support the ioctl() in net_getParam(). |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
166 |
* Ugly, but only called once (for each sotype). |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
167 |
* |
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
168 |
* As an optimization, we make a guess using the default values for Solaris |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
169 |
* assuming they haven't been modified with ndd. |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
170 |
*/ |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
171 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
172 |
#define MAX_TCP_GUESS 1024 * 1024 |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
173 |
#define MAX_UDP_GUESS 2 * 1024 * 1024 |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
174 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
175 |
#define FAIL_IF_NOT_ENOBUFS if (errno != ENOBUFS) return -1 |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
176 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
177 |
static int findMaxBuf(int fd, int opt, int sotype) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
178 |
int a = 0; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
179 |
int b = MAXINT; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
180 |
int initial_guess; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
181 |
int limit = -1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
182 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
183 |
if (sotype == SOCK_DGRAM) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
184 |
initial_guess = MAX_UDP_GUESS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
185 |
} else { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
186 |
initial_guess = MAX_TCP_GUESS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
187 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
188 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
189 |
if (setsockopt(fd, SOL_SOCKET, opt, &initial_guess, sizeof(int)) == 0) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
190 |
initial_guess++; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
191 |
if (setsockopt(fd, SOL_SOCKET, opt, &initial_guess,sizeof(int)) < 0) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
192 |
FAIL_IF_NOT_ENOBUFS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
193 |
return initial_guess - 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
194 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
195 |
a = initial_guess; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
196 |
} else { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
197 |
FAIL_IF_NOT_ENOBUFS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
198 |
b = initial_guess - 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
199 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
200 |
do { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
201 |
int mid = a + (b-a)/2; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
202 |
if (setsockopt(fd, SOL_SOCKET, opt, &mid, sizeof(int)) == 0) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
203 |
limit = mid; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
204 |
a = mid + 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
205 |
} else { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
206 |
FAIL_IF_NOT_ENOBUFS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
207 |
b = mid - 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
208 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
209 |
} while (b >= a); |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
210 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
211 |
return limit; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
212 |
} |
2 | 213 |
#endif |
214 |
||
215 |
#ifdef __linux__ |
|
216 |
static int vinit = 0; |
|
217 |
static int kernelV24 = 0; |
|
218 |
static int vinit24 = 0; |
|
219 |
||
220 |
int kernelIsV24 () { |
|
221 |
if (!vinit24) { |
|
222 |
struct utsname sysinfo; |
|
223 |
if (uname(&sysinfo) == 0) { |
|
224 |
sysinfo.release[3] = '\0'; |
|
225 |
if (strcmp(sysinfo.release, "2.4") == 0) { |
|
226 |
kernelV24 = JNI_TRUE; |
|
227 |
} |
|
228 |
} |
|
229 |
vinit24 = 1; |
|
230 |
} |
|
231 |
return kernelV24; |
|
232 |
} |
|
233 |
||
234 |
int getScopeID (struct sockaddr *him) { |
|
235 |
struct sockaddr_in6 *hext = (struct sockaddr_in6 *)him; |
|
236 |
return hext->sin6_scope_id; |
|
237 |
} |
|
238 |
||
239 |
int cmpScopeID (unsigned int scope, struct sockaddr *him) { |
|
240 |
struct sockaddr_in6 *hext = (struct sockaddr_in6 *)him; |
|
241 |
return hext->sin6_scope_id == scope; |
|
242 |
} |
|
243 |
||
244 |
#else |
|
245 |
||
246 |
int getScopeID (struct sockaddr *him) { |
|
247 |
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him; |
|
248 |
return him6->sin6_scope_id; |
|
249 |
} |
|
250 |
||
251 |
int cmpScopeID (unsigned int scope, struct sockaddr *him) { |
|
252 |
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him; |
|
253 |
return him6->sin6_scope_id == scope; |
|
254 |
} |
|
255 |
||
256 |
#endif |
|
257 |
||
258 |
void |
|
259 |
NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, |
|
260 |
const char *defaultDetail) { |
|
41578 | 261 |
JNU_ThrowByNameWithMessageAndLastError(env, name, defaultDetail); |
2 | 262 |
} |
263 |
||
264 |
void |
|
265 |
NET_ThrowCurrent(JNIEnv *env, char *msg) { |
|
266 |
NET_ThrowNew(env, errno, msg); |
|
267 |
} |
|
268 |
||
269 |
void |
|
270 |
NET_ThrowNew(JNIEnv *env, int errorNumber, char *msg) { |
|
271 |
char fullMsg[512]; |
|
272 |
if (!msg) { |
|
273 |
msg = "no further information"; |
|
274 |
} |
|
275 |
switch(errorNumber) { |
|
276 |
case EBADF: |
|
277 |
jio_snprintf(fullMsg, sizeof(fullMsg), "socket closed: %s", msg); |
|
278 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", fullMsg); |
|
279 |
break; |
|
280 |
case EINTR: |
|
281 |
JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", msg); |
|
282 |
break; |
|
283 |
default: |
|
284 |
errno = errorNumber; |
|
285 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", msg); |
|
286 |
break; |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
||
291 |
jfieldID |
|
292 |
NET_GetFileDescriptorID(JNIEnv *env) |
|
293 |
{ |
|
294 |
jclass cls = (*env)->FindClass(env, "java/io/FileDescriptor"); |
|
295 |
CHECK_NULL_RETURN(cls, NULL); |
|
296 |
return (*env)->GetFieldID(env, cls, "fd", "I"); |
|
297 |
} |
|
298 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
299 |
#if defined(DONT_ENABLE_IPV6) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
300 |
jint IPv6_supported() |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
301 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
302 |
return JNI_FALSE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
303 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
304 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
305 |
#else /* !DONT_ENABLE_IPV6 */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
306 |
|
2 | 307 |
jint IPv6_supported() |
308 |
{ |
|
309 |
int fd; |
|
310 |
void *ipv6_fn; |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
311 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
312 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
2 | 313 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
314 |
fd = socket(AF_INET6, SOCK_STREAM, 0) ; |
2 | 315 |
if (fd < 0) { |
316 |
/* |
|
317 |
* TODO: We really cant tell since it may be an unrelated error |
|
318 |
* for now we will assume that AF_INET6 is not available |
|
319 |
*/ |
|
320 |
return JNI_FALSE; |
|
321 |
} |
|
322 |
||
323 |
/* |
|
324 |
* If fd 0 is a socket it means we've been launched from inetd or |
|
325 |
* xinetd. If it's a socket then check the family - if it's an |
|
326 |
* IPv4 socket then we need to disable IPv6. |
|
327 |
*/ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
328 |
if (getsockname(0, &sa.sa, &sa_len) == 0) { |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
329 |
if (sa.sa.sa_family != AF_INET6) { |
38459
6cf90640c38c
8048518: File Descriptor Leak in src/java.base/unix/native/libnet/net_util_md.c
chegar
parents:
36115
diff
changeset
|
330 |
close(fd); |
2 | 331 |
return JNI_FALSE; |
332 |
} |
|
333 |
} |
|
334 |
||
335 |
/** |
|
336 |
* Linux - check if any interface has an IPv6 address. |
|
337 |
* Don't need to parse the line - we just need an indication. |
|
338 |
*/ |
|
339 |
#ifdef __linux__ |
|
340 |
{ |
|
341 |
FILE *fP = fopen("/proc/net/if_inet6", "r"); |
|
342 |
char buf[255]; |
|
343 |
char *bufP; |
|
344 |
||
345 |
if (fP == NULL) { |
|
346 |
close(fd); |
|
347 |
return JNI_FALSE; |
|
348 |
} |
|
349 |
bufP = fgets(buf, sizeof(buf), fP); |
|
350 |
fclose(fP); |
|
351 |
if (bufP == NULL) { |
|
352 |
close(fd); |
|
353 |
return JNI_FALSE; |
|
354 |
} |
|
355 |
} |
|
356 |
#endif |
|
357 |
||
358 |
/** |
|
359 |
* On Solaris 8 it's possible to create INET6 sockets even |
|
360 |
* though IPv6 is not enabled on all interfaces. Thus we |
|
361 |
* query the number of IPv6 addresses to verify that IPv6 |
|
362 |
* has been configured on at least one interface. |
|
363 |
* |
|
364 |
* On Linux it doesn't matter - if IPv6 is built-in the |
|
365 |
* kernel then IPv6 addresses will be bound automatically |
|
366 |
* to all interfaces. |
|
367 |
*/ |
|
368 |
#ifdef __solaris__ |
|
369 |
||
370 |
#ifdef SIOCGLIFNUM |
|
371 |
{ |
|
372 |
struct lifnum numifs; |
|
373 |
||
374 |
numifs.lifn_family = AF_INET6; |
|
375 |
numifs.lifn_flags = 0; |
|
376 |
if (ioctl(fd, SIOCGLIFNUM, (char *)&numifs) < 0) { |
|
377 |
/** |
|
378 |
* SIOCGLIFNUM failed - assume IPv6 not configured |
|
379 |
*/ |
|
380 |
close(fd); |
|
381 |
return JNI_FALSE; |
|
382 |
} |
|
383 |
/** |
|
384 |
* If no IPv6 addresses then return false. If count > 0 |
|
385 |
* it's possible that all IPv6 addresses are "down" but |
|
386 |
* that's okay as they may be brought "up" while the |
|
387 |
* VM is running. |
|
388 |
*/ |
|
389 |
if (numifs.lifn_count == 0) { |
|
390 |
close(fd); |
|
391 |
return JNI_FALSE; |
|
392 |
} |
|
393 |
} |
|
394 |
#else |
|
395 |
/* SIOCGLIFNUM not defined in build environment ??? */ |
|
396 |
close(fd); |
|
397 |
return JNI_FALSE; |
|
398 |
#endif |
|
399 |
||
400 |
#endif /* __solaris */ |
|
401 |
||
402 |
/* |
|
403 |
* OK we may have the stack available in the kernel, |
|
404 |
* we should also check if the APIs are available. |
|
405 |
*/ |
|
406 |
ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton"); |
|
11032
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
407 |
close(fd); |
2 | 408 |
if (ipv6_fn == NULL ) { |
409 |
return JNI_FALSE; |
|
11032
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
410 |
} else { |
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
411 |
return JNI_TRUE; |
2 | 412 |
} |
413 |
} |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
414 |
#endif /* DONT_ENABLE_IPV6 */ |
2 | 415 |
|
36115 | 416 |
jint reuseport_supported() |
417 |
{ |
|
418 |
/* Do a simple dummy call, and try to figure out from that */ |
|
419 |
int one = 1; |
|
420 |
int rv, s; |
|
421 |
s = socket(PF_INET, SOCK_STREAM, 0); |
|
422 |
if (s < 0) { |
|
423 |
return JNI_FALSE; |
|
424 |
} |
|
425 |
rv = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (void *)&one, sizeof(one)); |
|
426 |
if (rv != 0) { |
|
427 |
rv = JNI_FALSE; |
|
428 |
} else { |
|
429 |
rv = JNI_TRUE; |
|
430 |
} |
|
431 |
close(s); |
|
432 |
return rv; |
|
433 |
} |
|
434 |
||
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
435 |
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
436 |
const char* hostname, |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
437 |
int gai_error) |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
438 |
{ |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
439 |
int size; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
440 |
char *buf; |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
441 |
const char *format = "%s: %s"; |
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
442 |
const char *error_string = gai_strerror(gai_error); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
443 |
if (error_string == NULL) |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
444 |
error_string = "unknown error"; |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
445 |
|
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
446 |
size = strlen(format) + strlen(hostname) + strlen(error_string) + 2; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
447 |
buf = (char *) malloc(size); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
448 |
if (buf) { |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
449 |
jstring s; |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
450 |
sprintf(buf, format, hostname, error_string); |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
451 |
s = JNU_NewStringPlatform(env, buf); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
452 |
if (s != NULL) { |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
453 |
jobject x = JNU_NewObjectByName(env, |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
454 |
"java/net/UnknownHostException", |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
455 |
"(Ljava/lang/String;)V", s); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
456 |
if (x != NULL) |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
457 |
(*env)->Throw(env, x); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
458 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
459 |
free(buf); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
460 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
461 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
462 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
463 |
#if defined(__linux__) |
2 | 464 |
|
465 |
/* following code creates a list of addresses from the kernel |
|
466 |
* routing table that are routed via the loopback address. |
|
467 |
* We check all destination addresses against this table |
|
468 |
* and override the scope_id field to use the relevant value for "lo" |
|
469 |
* in order to work-around the Linux bug that prevents packets destined |
|
470 |
* for certain local addresses from being sent via a physical interface. |
|
471 |
*/ |
|
472 |
||
473 |
struct loopback_route { |
|
474 |
struct in6_addr addr; /* destination address */ |
|
475 |
int plen; /* prefix length */ |
|
476 |
}; |
|
477 |
||
478 |
static struct loopback_route *loRoutes = 0; |
|
479 |
static int nRoutes = 0; /* number of routes */ |
|
480 |
static int loRoutes_size = 16; /* initial size */ |
|
481 |
static int lo_scope_id = 0; |
|
482 |
||
483 |
static void initLoopbackRoutes(); |
|
484 |
||
485 |
void printAddr (struct in6_addr *addr) { |
|
486 |
int i; |
|
487 |
for (i=0; i<16; i++) { |
|
488 |
printf ("%02x", addr->s6_addr[i]); |
|
489 |
} |
|
490 |
printf ("\n"); |
|
491 |
} |
|
492 |
||
493 |
static jboolean needsLoopbackRoute (struct in6_addr* dest_addr) { |
|
494 |
int byte_count; |
|
495 |
int extra_bits, i; |
|
496 |
struct loopback_route *ptr; |
|
497 |
||
498 |
if (loRoutes == 0) { |
|
499 |
initLoopbackRoutes(); |
|
500 |
} |
|
501 |
||
502 |
for (ptr = loRoutes, i=0; i<nRoutes; i++, ptr++) { |
|
503 |
struct in6_addr *target_addr=&ptr->addr; |
|
504 |
int dest_plen = ptr->plen; |
|
505 |
byte_count = dest_plen >> 3; |
|
506 |
extra_bits = dest_plen & 0x3; |
|
507 |
||
508 |
if (byte_count > 0) { |
|
509 |
if (memcmp(target_addr, dest_addr, byte_count)) { |
|
510 |
continue; /* no match */ |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
if (extra_bits > 0) { |
|
515 |
unsigned char c1 = ((unsigned char *)target_addr)[byte_count]; |
|
516 |
unsigned char c2 = ((unsigned char *)&dest_addr)[byte_count]; |
|
517 |
unsigned char mask = 0xff << (8 - extra_bits); |
|
518 |
if ((c1 & mask) != (c2 & mask)) { |
|
519 |
continue; |
|
520 |
} |
|
521 |
} |
|
522 |
return JNI_TRUE; |
|
523 |
} |
|
524 |
return JNI_FALSE; |
|
525 |
} |
|
526 |
||
527 |
||
528 |
static void initLoopbackRoutes() { |
|
529 |
FILE *f; |
|
530 |
char srcp[8][5]; |
|
531 |
char hopp[8][5]; |
|
532 |
int dest_plen, src_plen, use, refcnt, metric; |
|
533 |
unsigned long flags; |
|
534 |
char dest_str[40]; |
|
535 |
struct in6_addr dest_addr; |
|
536 |
char device[16]; |
|
14320
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
537 |
struct loopback_route *loRoutesTemp; |
2 | 538 |
|
539 |
if (loRoutes != 0) { |
|
540 |
free (loRoutes); |
|
541 |
} |
|
542 |
loRoutes = calloc (loRoutes_size, sizeof(struct loopback_route)); |
|
543 |
if (loRoutes == 0) { |
|
544 |
return; |
|
545 |
} |
|
546 |
/* |
|
547 |
* Scan /proc/net/ipv6_route looking for a matching |
|
548 |
* route. |
|
549 |
*/ |
|
550 |
if ((f = fopen("/proc/net/ipv6_route", "r")) == NULL) { |
|
551 |
return ; |
|
552 |
} |
|
553 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
554 |
"%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
555 |
"%4s%4s%4s%4s%4s%4s%4s%4s " |
|
556 |
"%08x %08x %08x %08lx %8s", |
|
557 |
dest_str, &dest_str[5], &dest_str[10], &dest_str[15], |
|
558 |
&dest_str[20], &dest_str[25], &dest_str[30], &dest_str[35], |
|
559 |
&dest_plen, |
|
560 |
srcp[0], srcp[1], srcp[2], srcp[3], |
|
561 |
srcp[4], srcp[5], srcp[6], srcp[7], |
|
562 |
&src_plen, |
|
563 |
hopp[0], hopp[1], hopp[2], hopp[3], |
|
564 |
hopp[4], hopp[5], hopp[6], hopp[7], |
|
565 |
&metric, &use, &refcnt, &flags, device) == 31) { |
|
566 |
||
567 |
/* |
|
568 |
* Some routes should be ignored |
|
569 |
*/ |
|
570 |
if ( (dest_plen < 0 || dest_plen > 128) || |
|
571 |
(src_plen != 0) || |
|
572 |
(flags & (RTF_POLICY | RTF_FLOW)) || |
|
573 |
((flags & RTF_REJECT) && dest_plen == 0) ) { |
|
574 |
continue; |
|
575 |
} |
|
576 |
||
577 |
/* |
|
578 |
* Convert the destination address |
|
579 |
*/ |
|
580 |
dest_str[4] = ':'; |
|
581 |
dest_str[9] = ':'; |
|
582 |
dest_str[14] = ':'; |
|
583 |
dest_str[19] = ':'; |
|
584 |
dest_str[24] = ':'; |
|
585 |
dest_str[29] = ':'; |
|
586 |
dest_str[34] = ':'; |
|
587 |
dest_str[39] = '\0'; |
|
588 |
||
589 |
if (inet_pton(AF_INET6, dest_str, &dest_addr) < 0) { |
|
590 |
/* not an Ipv6 address */ |
|
591 |
continue; |
|
592 |
} |
|
593 |
if (strcmp(device, "lo") != 0) { |
|
594 |
/* Not a loopback route */ |
|
595 |
continue; |
|
596 |
} else { |
|
597 |
if (nRoutes == loRoutes_size) { |
|
14320
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
598 |
loRoutesTemp = realloc (loRoutes, loRoutes_size * |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
599 |
sizeof (struct loopback_route) * 2); |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
600 |
|
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
601 |
if (loRoutesTemp == 0) { |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
602 |
free(loRoutes); |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
603 |
fclose (f); |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
604 |
return; |
2 | 605 |
} |
14320
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
606 |
loRoutes=loRoutesTemp; |
2 | 607 |
loRoutes_size *= 2; |
608 |
} |
|
609 |
memcpy (&loRoutes[nRoutes].addr,&dest_addr,sizeof(struct in6_addr)); |
|
610 |
loRoutes[nRoutes].plen = dest_plen; |
|
611 |
nRoutes ++; |
|
612 |
} |
|
613 |
} |
|
614 |
||
615 |
fclose (f); |
|
616 |
{ |
|
617 |
/* now find the scope_id for "lo" */ |
|
618 |
||
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
619 |
char devname[21]; |
2 | 620 |
char addr6p[8][5]; |
621 |
int plen, scope, dad_status, if_idx; |
|
622 |
||
623 |
if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) { |
|
11514
0cefabc1c81f
7123415: Some cases of network interface indexes being read incorrectly
chegar
parents:
11032
diff
changeset
|
624 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", |
2 | 625 |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
626 |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
|
627 |
&if_idx, &plen, &scope, &dad_status, devname) == 13) { |
|
628 |
||
629 |
if (strcmp(devname, "lo") == 0) { |
|
630 |
/* |
|
631 |
* Found - so just return the index |
|
632 |
*/ |
|
633 |
fclose(f); |
|
634 |
lo_scope_id = if_idx; |
|
635 |
return; |
|
636 |
} |
|
637 |
} |
|
638 |
fclose(f); |
|
639 |
} |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
/* |
|
644 |
* Following is used for binding to local addresses. Equivalent |
|
645 |
* to code above, for bind(). |
|
646 |
*/ |
|
647 |
||
648 |
struct localinterface { |
|
649 |
int index; |
|
650 |
char localaddr [16]; |
|
651 |
}; |
|
652 |
||
653 |
static struct localinterface *localifs = 0; |
|
654 |
static int localifsSize = 0; /* size of array */ |
|
655 |
static int nifs = 0; /* number of entries used in array */ |
|
656 |
||
657 |
/* not thread safe: make sure called once from one thread */ |
|
658 |
||
659 |
static void initLocalIfs () { |
|
660 |
FILE *f; |
|
661 |
unsigned char staddr [16]; |
|
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
662 |
char ifname [33]; |
2 | 663 |
struct localinterface *lif=0; |
664 |
int index, x1, x2, x3; |
|
665 |
unsigned int u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,ua,ub,uc,ud,ue,uf; |
|
666 |
||
667 |
if ((f = fopen("/proc/net/if_inet6", "r")) == NULL) { |
|
668 |
return ; |
|
669 |
} |
|
670 |
while (fscanf (f, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x " |
|
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
671 |
"%d %x %x %x %32s",&u0,&u1,&u2,&u3,&u4,&u5,&u6,&u7, |
2 | 672 |
&u8,&u9,&ua,&ub,&uc,&ud,&ue,&uf, |
673 |
&index, &x1, &x2, &x3, ifname) == 21) { |
|
674 |
staddr[0] = (unsigned char)u0; |
|
675 |
staddr[1] = (unsigned char)u1; |
|
676 |
staddr[2] = (unsigned char)u2; |
|
677 |
staddr[3] = (unsigned char)u3; |
|
678 |
staddr[4] = (unsigned char)u4; |
|
679 |
staddr[5] = (unsigned char)u5; |
|
680 |
staddr[6] = (unsigned char)u6; |
|
681 |
staddr[7] = (unsigned char)u7; |
|
682 |
staddr[8] = (unsigned char)u8; |
|
683 |
staddr[9] = (unsigned char)u9; |
|
684 |
staddr[10] = (unsigned char)ua; |
|
685 |
staddr[11] = (unsigned char)ub; |
|
686 |
staddr[12] = (unsigned char)uc; |
|
687 |
staddr[13] = (unsigned char)ud; |
|
688 |
staddr[14] = (unsigned char)ue; |
|
689 |
staddr[15] = (unsigned char)uf; |
|
690 |
nifs ++; |
|
691 |
if (nifs > localifsSize) { |
|
692 |
localifs = (struct localinterface *) realloc ( |
|
693 |
localifs, sizeof (struct localinterface)* (localifsSize+5)); |
|
694 |
if (localifs == 0) { |
|
695 |
nifs = 0; |
|
696 |
fclose (f); |
|
697 |
return; |
|
698 |
} |
|
699 |
lif = localifs + localifsSize; |
|
700 |
localifsSize += 5; |
|
701 |
} else { |
|
702 |
lif ++; |
|
703 |
} |
|
704 |
memcpy (lif->localaddr, staddr, 16); |
|
705 |
lif->index = index; |
|
706 |
} |
|
707 |
fclose (f); |
|
708 |
} |
|
709 |
||
710 |
/* return the scope_id (interface index) of the |
|
711 |
* interface corresponding to the given address |
|
712 |
* returns 0 if no match found |
|
713 |
*/ |
|
714 |
||
715 |
static int getLocalScopeID (char *addr) { |
|
716 |
struct localinterface *lif; |
|
717 |
int i; |
|
718 |
if (localifs == 0) { |
|
719 |
initLocalIfs(); |
|
720 |
} |
|
721 |
for (i=0, lif=localifs; i<nifs; i++, lif++) { |
|
722 |
if (memcmp (addr, lif->localaddr, 16) == 0) { |
|
723 |
return lif->index; |
|
724 |
} |
|
725 |
} |
|
726 |
return 0; |
|
727 |
} |
|
728 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
729 |
void platformInit () { |
2 | 730 |
initLoopbackRoutes(); |
731 |
initLocalIfs(); |
|
732 |
} |
|
733 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
734 |
#elif defined(_AIX) |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
735 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
736 |
/* Initialize stubs for blocking I/O workarounds (see src/solaris/native/java/net/linux_close.c) */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
737 |
extern void aix_close_init(); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
738 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
739 |
void platformInit () { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
740 |
aix_close_init(); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
741 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
742 |
|
2 | 743 |
#else |
744 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
745 |
void platformInit () {} |
2 | 746 |
|
747 |
#endif |
|
748 |
||
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
749 |
void parseExclusiveBindProperty(JNIEnv *env) { |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
750 |
#ifdef __solaris__ |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
751 |
jstring s, flagSet; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
752 |
jclass iCls; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
753 |
jmethodID mid; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
754 |
|
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
755 |
s = (*env)->NewStringUTF(env, "sun.net.useExclusiveBind"); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
756 |
CHECK_NULL(s); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
757 |
iCls = (*env)->FindClass(env, "java/lang/System"); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
758 |
CHECK_NULL(iCls); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
759 |
mid = (*env)->GetStaticMethodID(env, iCls, "getProperty", |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
760 |
"(Ljava/lang/String;)Ljava/lang/String;"); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
761 |
CHECK_NULL(mid); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
762 |
flagSet = (*env)->CallStaticObjectMethod(env, iCls, mid, s); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
763 |
if (flagSet != NULL) { |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
764 |
useExclBind = 1; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
765 |
} |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
766 |
#endif |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
767 |
} |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
768 |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
769 |
JNIEXPORT jint JNICALL |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
770 |
NET_EnableFastTcpLoopback(int fd) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
771 |
return 0; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
772 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
773 |
|
2 | 774 |
/* In the case of an IPv4 Inetaddress this method will return an |
775 |
* IPv4 mapped address where IPv6 is available and v4MappedAddress is TRUE. |
|
776 |
* Otherwise it will return a sockaddr_in structure for an IPv4 InetAddress. |
|
777 |
*/ |
|
778 |
JNIEXPORT int JNICALL |
|
779 |
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, |
|
780 |
int *len, jboolean v4MappedAddress) { |
|
781 |
jint family; |
|
16870 | 782 |
family = getInetAddress_family(env, iaObj); |
2 | 783 |
/* needs work. 1. family 2. clean up him6 etc deallocate memory */ |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
784 |
if (ipv6_available() && !(family == java_net_InetAddress_IPv4 && |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
785 |
v4MappedAddress == JNI_FALSE)) { |
2 | 786 |
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him; |
787 |
jbyte caddr[16]; |
|
788 |
jint address; |
|
789 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
790 |
if (family == java_net_InetAddress_IPv4) { |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
791 |
// convert to IPv4-mapped address |
2 | 792 |
memset((char *) caddr, 0, 16); |
16870 | 793 |
address = getInetAddress_addr(env, iaObj); |
2 | 794 |
if (address == INADDR_ANY) { |
795 |
/* we would always prefer IPv6 wildcard address |
|
796 |
caddr[10] = 0xff; |
|
797 |
caddr[11] = 0xff; */ |
|
798 |
} else { |
|
799 |
caddr[10] = 0xff; |
|
800 |
caddr[11] = 0xff; |
|
801 |
caddr[12] = ((address >> 24) & 0xff); |
|
802 |
caddr[13] = ((address >> 16) & 0xff); |
|
803 |
caddr[14] = ((address >> 8) & 0xff); |
|
804 |
caddr[15] = (address & 0xff); |
|
805 |
} |
|
806 |
} else { |
|
20821 | 807 |
getInet6Address_ipaddress(env, iaObj, (char *)caddr); |
2 | 808 |
} |
809 |
memset((char *)him6, 0, sizeof(struct sockaddr_in6)); |
|
810 |
him6->sin6_port = htons(port); |
|
811 |
memcpy((void *)&(him6->sin6_addr), caddr, sizeof(struct in6_addr) ); |
|
812 |
him6->sin6_family = AF_INET6; |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
813 |
*len = sizeof(struct sockaddr_in6); |
2 | 814 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
815 |
#if defined(_ALLBSD_SOURCE) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
816 |
// XXXBSD: should we do something with scope id here ? see below linux comment |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
817 |
/* MMM: Come back to this! */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
818 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
819 |
|
2 | 820 |
/* |
821 |
* On Linux if we are connecting to a link-local address |
|
822 |
* we need to specify the interface in the scope_id (2.4 kernel only) |
|
823 |
* |
|
824 |
* If the scope was cached the we use the cached value. If not cached but |
|
825 |
* specified in the Inet6Address we use that, but we first check if the |
|
826 |
* address needs to be routed via the loopback interface. In this case, |
|
827 |
* we override the specified value with that of the loopback interface. |
|
828 |
* If no cached value exists and no value was specified by user, then |
|
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
829 |
* we try to determine a value from the routing table. In all these |
2 | 830 |
* cases the used value is cached for further use. |
831 |
*/ |
|
832 |
#ifdef __linux__ |
|
833 |
if (IN6_IS_ADDR_LINKLOCAL(&(him6->sin6_addr))) { |
|
834 |
int cached_scope_id = 0, scope_id = 0; |
|
835 |
||
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
836 |
if (ia6_cachedscopeidID) { |
2 | 837 |
cached_scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID); |
838 |
/* if cached value exists then use it. Otherwise, check |
|
839 |
* if scope is set in the address. |
|
840 |
*/ |
|
841 |
if (!cached_scope_id) { |
|
842 |
if (ia6_scopeidID) { |
|
20821 | 843 |
scope_id = getInet6Address_scopeid(env, iaObj); |
2 | 844 |
} |
845 |
if (scope_id != 0) { |
|
846 |
/* check user-specified value for loopback case |
|
847 |
* that needs to be overridden |
|
848 |
*/ |
|
849 |
if (kernelIsV24() && needsLoopbackRoute (&him6->sin6_addr)) { |
|
850 |
cached_scope_id = lo_scope_id; |
|
851 |
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id); |
|
852 |
} |
|
853 |
} else { |
|
854 |
/* |
|
855 |
* Otherwise consult the IPv6 routing tables to |
|
856 |
* try determine the appropriate interface. |
|
857 |
*/ |
|
858 |
if (kernelIsV24()) { |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
859 |
cached_scope_id = getDefaultIPv6Interface(&(him6->sin6_addr)); |
2 | 860 |
} else { |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
861 |
cached_scope_id = getLocalScopeID((char *)&(him6->sin6_addr)); |
2 | 862 |
if (cached_scope_id == 0) { |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
863 |
cached_scope_id = getDefaultIPv6Interface(&(him6->sin6_addr)); |
2 | 864 |
} |
865 |
} |
|
866 |
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id); |
|
867 |
} |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
/* |
|
872 |
* If we have a scope_id use the extended form |
|
873 |
* of sockaddr_in6. |
|
874 |
*/ |
|
875 |
||
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
876 |
struct sockaddr_in6 *him6 = |
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
877 |
(struct sockaddr_in6 *)him; |
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
878 |
him6->sin6_scope_id = cached_scope_id != 0 ? |
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
879 |
cached_scope_id : scope_id; |
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
880 |
*len = sizeof(struct sockaddr_in6); |
2 | 881 |
} |
882 |
#else |
|
883 |
/* handle scope_id for solaris */ |
|
884 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
885 |
if (family != java_net_InetAddress_IPv4) { |
2 | 886 |
if (ia6_scopeidID) { |
20821 | 887 |
him6->sin6_scope_id = getInet6Address_scopeid(env, iaObj); |
2 | 888 |
} |
889 |
} |
|
890 |
#endif |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
891 |
} else { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
892 |
struct sockaddr_in *him4 = (struct sockaddr_in *)him; |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
893 |
jint address; |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
894 |
if (family == java_net_InetAddress_IPv6) { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
895 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable"); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
896 |
return -1; |
2 | 897 |
} |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
898 |
memset((char *)him4, 0, sizeof(struct sockaddr_in)); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
899 |
address = getInetAddress_addr(env, iaObj); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
900 |
him4->sin_port = htons((short) port); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
901 |
him4->sin_addr.s_addr = htonl(address); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
902 |
him4->sin_family = AF_INET; |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
903 |
*len = sizeof(struct sockaddr_in); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
904 |
} |
2 | 905 |
return 0; |
906 |
} |
|
907 |
||
908 |
void |
|
909 |
NET_SetTrafficClass(struct sockaddr *him, int trafficClass) { |
|
910 |
if (him->sa_family == AF_INET6) { |
|
911 |
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him; |
|
912 |
him6->sin6_flowinfo = htonl((trafficClass & 0xff) << 20); |
|
913 |
} |
|
914 |
} |
|
915 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
911
diff
changeset
|
916 |
JNIEXPORT jint JNICALL |
2 | 917 |
NET_GetPortFromSockaddr(struct sockaddr *him) { |
918 |
if (him->sa_family == AF_INET6) { |
|
919 |
return ntohs(((struct sockaddr_in6*)him)->sin6_port); |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
920 |
} else { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
921 |
return ntohs(((struct sockaddr_in*)him)->sin_port); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
922 |
} |
2 | 923 |
} |
924 |
||
925 |
int |
|
926 |
NET_IsIPv4Mapped(jbyte* caddr) { |
|
927 |
int i; |
|
928 |
for (i = 0; i < 10; i++) { |
|
929 |
if (caddr[i] != 0x00) { |
|
930 |
return 0; /* false */ |
|
931 |
} |
|
932 |
} |
|
933 |
||
934 |
if (((caddr[10] & 0xff) == 0xff) && ((caddr[11] & 0xff) == 0xff)) { |
|
935 |
return 1; /* true */ |
|
936 |
} |
|
937 |
return 0; /* false */ |
|
938 |
} |
|
939 |
||
940 |
int |
|
941 |
NET_IPv4MappedToIPv4(jbyte* caddr) { |
|
942 |
return ((caddr[12] & 0xff) << 24) | ((caddr[13] & 0xff) << 16) | ((caddr[14] & 0xff) << 8) |
|
943 |
| (caddr[15] & 0xff); |
|
944 |
} |
|
945 |
||
946 |
int |
|
947 |
NET_IsEqual(jbyte* caddr1, jbyte* caddr2) { |
|
948 |
int i; |
|
949 |
for (i = 0; i < 16; i++) { |
|
950 |
if (caddr1[i] != caddr2[i]) { |
|
951 |
return 0; /* false */ |
|
952 |
} |
|
953 |
} |
|
954 |
return 1; |
|
955 |
} |
|
956 |
||
12688
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
957 |
int NET_IsZeroAddr(jbyte* caddr) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
958 |
int i; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
959 |
for (i = 0; i < 16; i++) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
960 |
if (caddr[i] != 0) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
961 |
return 0; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
962 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
963 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
964 |
return 1; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
965 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
966 |
|
2 | 967 |
/* |
968 |
* Map the Java level socket option to the platform specific |
|
969 |
* level and option name. |
|
970 |
*/ |
|
971 |
int |
|
972 |
NET_MapSocketOption(jint cmd, int *level, int *optname) { |
|
973 |
static struct { |
|
974 |
jint cmd; |
|
975 |
int level; |
|
976 |
int optname; |
|
977 |
} const opts[] = { |
|
978 |
{ java_net_SocketOptions_TCP_NODELAY, IPPROTO_TCP, TCP_NODELAY }, |
|
979 |
{ java_net_SocketOptions_SO_OOBINLINE, SOL_SOCKET, SO_OOBINLINE }, |
|
980 |
{ java_net_SocketOptions_SO_LINGER, SOL_SOCKET, SO_LINGER }, |
|
981 |
{ java_net_SocketOptions_SO_SNDBUF, SOL_SOCKET, SO_SNDBUF }, |
|
982 |
{ java_net_SocketOptions_SO_RCVBUF, SOL_SOCKET, SO_RCVBUF }, |
|
983 |
{ java_net_SocketOptions_SO_KEEPALIVE, SOL_SOCKET, SO_KEEPALIVE }, |
|
984 |
{ java_net_SocketOptions_SO_REUSEADDR, SOL_SOCKET, SO_REUSEADDR }, |
|
36115 | 985 |
{ java_net_SocketOptions_SO_REUSEPORT, SOL_SOCKET, SO_REUSEPORT }, |
2 | 986 |
{ java_net_SocketOptions_SO_BROADCAST, SOL_SOCKET, SO_BROADCAST }, |
987 |
{ java_net_SocketOptions_IP_TOS, IPPROTO_IP, IP_TOS }, |
|
988 |
{ java_net_SocketOptions_IP_MULTICAST_IF, IPPROTO_IP, IP_MULTICAST_IF }, |
|
989 |
{ java_net_SocketOptions_IP_MULTICAST_IF2, IPPROTO_IP, IP_MULTICAST_IF }, |
|
990 |
{ java_net_SocketOptions_IP_MULTICAST_LOOP, IPPROTO_IP, IP_MULTICAST_LOOP }, |
|
991 |
}; |
|
992 |
||
993 |
int i; |
|
994 |
||
995 |
if (ipv6_available()) { |
|
996 |
switch (cmd) { |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
997 |
// Different multicast options if IPv6 is enabled |
2 | 998 |
case java_net_SocketOptions_IP_MULTICAST_IF: |
999 |
case java_net_SocketOptions_IP_MULTICAST_IF2: |
|
1000 |
*level = IPPROTO_IPV6; |
|
1001 |
*optname = IPV6_MULTICAST_IF; |
|
1002 |
return 0; |
|
1003 |
||
1004 |
case java_net_SocketOptions_IP_MULTICAST_LOOP: |
|
1005 |
*level = IPPROTO_IPV6; |
|
1006 |
*optname = IPV6_MULTICAST_LOOP; |
|
1007 |
return 0; |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1008 |
#if (defined(__solaris__) || defined(MACOSX)) |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1009 |
// Map IP_TOS request to IPV6_TCLASS |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1010 |
case java_net_SocketOptions_IP_TOS: |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1011 |
*level = IPPROTO_IPV6; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1012 |
*optname = IPV6_TCLASS; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1013 |
return 0; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1014 |
#endif |
2 | 1015 |
} |
1016 |
} |
|
1017 |
||
1018 |
/* |
|
1019 |
* Map the Java level option to the native level |
|
1020 |
*/ |
|
1021 |
for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) { |
|
1022 |
if (cmd == opts[i].cmd) { |
|
1023 |
*level = opts[i].level; |
|
1024 |
*optname = opts[i].optname; |
|
1025 |
return 0; |
|
1026 |
} |
|
1027 |
} |
|
1028 |
||
1029 |
/* not found */ |
|
1030 |
return -1; |
|
1031 |
} |
|
1032 |
||
1033 |
/* |
|
1034 |
* Determine the default interface for an IPv6 address. |
|
1035 |
* |
|
1036 |
* 1. Scans /proc/net/ipv6_route for a matching route |
|
1037 |
* (eg: fe80::/10 or a route for the specific address). |
|
1038 |
* This will tell us the interface to use (eg: "eth0"). |
|
1039 |
* |
|
1040 |
* 2. Lookup /proc/net/if_inet6 to map the interface |
|
1041 |
* name to an interface index. |
|
1042 |
* |
|
1043 |
* Returns :- |
|
1044 |
* -1 if error |
|
1045 |
* 0 if no matching interface |
|
1046 |
* >1 interface index to use for the link-local address. |
|
1047 |
*/ |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1048 |
#if defined(__linux__) |
2 | 1049 |
int getDefaultIPv6Interface(struct in6_addr *target_addr) { |
1050 |
FILE *f; |
|
1051 |
char srcp[8][5]; |
|
1052 |
char hopp[8][5]; |
|
1053 |
int dest_plen, src_plen, use, refcnt, metric; |
|
1054 |
unsigned long flags; |
|
1055 |
char dest_str[40]; |
|
1056 |
struct in6_addr dest_addr; |
|
1057 |
char device[16]; |
|
1058 |
jboolean match = JNI_FALSE; |
|
1059 |
||
1060 |
/* |
|
1061 |
* Scan /proc/net/ipv6_route looking for a matching |
|
1062 |
* route. |
|
1063 |
*/ |
|
1064 |
if ((f = fopen("/proc/net/ipv6_route", "r")) == NULL) { |
|
1065 |
return -1; |
|
1066 |
} |
|
1067 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
1068 |
"%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
1069 |
"%4s%4s%4s%4s%4s%4s%4s%4s " |
|
1070 |
"%08x %08x %08x %08lx %8s", |
|
1071 |
dest_str, &dest_str[5], &dest_str[10], &dest_str[15], |
|
1072 |
&dest_str[20], &dest_str[25], &dest_str[30], &dest_str[35], |
|
1073 |
&dest_plen, |
|
1074 |
srcp[0], srcp[1], srcp[2], srcp[3], |
|
1075 |
srcp[4], srcp[5], srcp[6], srcp[7], |
|
1076 |
&src_plen, |
|
1077 |
hopp[0], hopp[1], hopp[2], hopp[3], |
|
1078 |
hopp[4], hopp[5], hopp[6], hopp[7], |
|
1079 |
&metric, &use, &refcnt, &flags, device) == 31) { |
|
1080 |
||
1081 |
/* |
|
1082 |
* Some routes should be ignored |
|
1083 |
*/ |
|
1084 |
if ( (dest_plen < 0 || dest_plen > 128) || |
|
1085 |
(src_plen != 0) || |
|
1086 |
(flags & (RTF_POLICY | RTF_FLOW)) || |
|
1087 |
((flags & RTF_REJECT) && dest_plen == 0) ) { |
|
1088 |
continue; |
|
1089 |
} |
|
1090 |
||
1091 |
/* |
|
1092 |
* Convert the destination address |
|
1093 |
*/ |
|
1094 |
dest_str[4] = ':'; |
|
1095 |
dest_str[9] = ':'; |
|
1096 |
dest_str[14] = ':'; |
|
1097 |
dest_str[19] = ':'; |
|
1098 |
dest_str[24] = ':'; |
|
1099 |
dest_str[29] = ':'; |
|
1100 |
dest_str[34] = ':'; |
|
1101 |
dest_str[39] = '\0'; |
|
1102 |
||
1103 |
if (inet_pton(AF_INET6, dest_str, &dest_addr) < 0) { |
|
1104 |
/* not an Ipv6 address */ |
|
1105 |
continue; |
|
1106 |
} else { |
|
1107 |
/* |
|
1108 |
* The prefix len (dest_plen) indicates the number of bits we |
|
1109 |
* need to match on. |
|
1110 |
* |
|
1111 |
* dest_plen / 8 => number of bytes to match |
|
1112 |
* dest_plen % 8 => number of additional bits to match |
|
1113 |
* |
|
1114 |
* eg: fe80::/10 => match 1 byte + 2 additional bits in the |
|
1115 |
* the next byte. |
|
1116 |
*/ |
|
1117 |
int byte_count = dest_plen >> 3; |
|
1118 |
int extra_bits = dest_plen & 0x3; |
|
1119 |
||
1120 |
if (byte_count > 0) { |
|
1121 |
if (memcmp(target_addr, &dest_addr, byte_count)) { |
|
1122 |
continue; /* no match */ |
|
1123 |
} |
|
1124 |
} |
|
1125 |
||
1126 |
if (extra_bits > 0) { |
|
1127 |
unsigned char c1 = ((unsigned char *)target_addr)[byte_count]; |
|
1128 |
unsigned char c2 = ((unsigned char *)&dest_addr)[byte_count]; |
|
1129 |
unsigned char mask = 0xff << (8 - extra_bits); |
|
1130 |
if ((c1 & mask) != (c2 & mask)) { |
|
1131 |
continue; |
|
1132 |
} |
|
1133 |
} |
|
1134 |
||
1135 |
/* |
|
1136 |
* We have a match |
|
1137 |
*/ |
|
1138 |
match = JNI_TRUE; |
|
1139 |
break; |
|
1140 |
} |
|
1141 |
} |
|
1142 |
fclose(f); |
|
1143 |
||
1144 |
/* |
|
1145 |
* If there's a match then we lookup the interface |
|
1146 |
* index. |
|
1147 |
*/ |
|
1148 |
if (match) { |
|
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
1149 |
char devname[21]; |
2 | 1150 |
char addr6p[8][5]; |
1151 |
int plen, scope, dad_status, if_idx; |
|
1152 |
||
1153 |
if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) { |
|
11514
0cefabc1c81f
7123415: Some cases of network interface indexes being read incorrectly
chegar
parents:
11032
diff
changeset
|
1154 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", |
2 | 1155 |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
1156 |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
|
1157 |
&if_idx, &plen, &scope, &dad_status, devname) == 13) { |
|
1158 |
||
1159 |
if (strcmp(devname, device) == 0) { |
|
1160 |
/* |
|
1161 |
* Found - so just return the index |
|
1162 |
*/ |
|
1163 |
fclose(f); |
|
1164 |
return if_idx; |
|
1165 |
} |
|
1166 |
} |
|
1167 |
fclose(f); |
|
1168 |
} else { |
|
1169 |
/* |
|
1170 |
* Couldn't open /proc/net/if_inet6 |
|
1171 |
*/ |
|
1172 |
return -1; |
|
1173 |
} |
|
1174 |
} |
|
1175 |
||
1176 |
/* |
|
1177 |
* If we get here it means we didn't there wasn't any |
|
1178 |
* route or we couldn't get the index of the interface. |
|
1179 |
*/ |
|
1180 |
return 0; |
|
1181 |
} |
|
1182 |
#endif |
|
1183 |
||
1184 |
||
1185 |
/* |
|
1186 |
* Wrapper for getsockopt system routine - does any necessary |
|
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
1187 |
* pre/post processing to deal with OS specific oddities :- |
2 | 1188 |
* |
1189 |
* On Linux the SO_SNDBUF/SO_RCVBUF values must be post-processed |
|
1190 |
* to compensate for an incorrect value returned by the kernel. |
|
1191 |
*/ |
|
1192 |
int |
|
1193 |
NET_GetSockOpt(int fd, int level, int opt, void *result, |
|
1194 |
int *len) |
|
1195 |
{ |
|
1196 |
int rv; |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1197 |
socklen_t socklen = *len; |
2 | 1198 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1199 |
rv = getsockopt(fd, level, opt, result, &socklen); |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1200 |
*len = socklen; |
911
9edd1b9607e2
6730740: Fix for 6729881 has apparently broken several 64 bit tests: "Bad address"
chegar
parents:
910
diff
changeset
|
1201 |
|
2 | 1202 |
if (rv < 0) { |
1203 |
return rv; |
|
1204 |
} |
|
1205 |
||
1206 |
#ifdef __linux__ |
|
1207 |
/* |
|
1208 |
* On Linux SO_SNDBUF/SO_RCVBUF aren't symmetric. This |
|
1209 |
* stems from additional socket structures in the send |
|
1210 |
* and receive buffers. |
|
1211 |
*/ |
|
1212 |
if ((level == SOL_SOCKET) && ((opt == SO_SNDBUF) |
|
1213 |
|| (opt == SO_RCVBUF))) { |
|
1214 |
int n = *((int *)result); |
|
1215 |
n /= 2; |
|
1216 |
*((int *)result) = n; |
|
1217 |
} |
|
1218 |
#endif |
|
1219 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1220 |
/* Workaround for Mac OS treating linger value as |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1221 |
* signed integer |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1222 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1223 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1224 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1225 |
struct linger* to_cast = (struct linger*)result; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1226 |
to_cast->l_linger = (unsigned short)to_cast->l_linger; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1227 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1228 |
#endif |
2 | 1229 |
return rv; |
1230 |
} |
|
1231 |
||
1232 |
/* |
|
1233 |
* Wrapper for setsockopt system routine - performs any |
|
1234 |
* necessary pre/post processing to deal with OS specific |
|
1235 |
* issue :- |
|
1236 |
* |
|
1237 |
* On Solaris need to limit the suggested value for SO_SNDBUF |
|
1238 |
* and SO_RCVBUF to the kernel configured limit |
|
1239 |
* |
|
1240 |
* For IP_TOS socket option need to mask off bits as this |
|
1241 |
* aren't automatically masked by the kernel and results in |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1242 |
* an error. |
2 | 1243 |
*/ |
1244 |
int |
|
1245 |
NET_SetSockOpt(int fd, int level, int opt, const void *arg, |
|
1246 |
int len) |
|
1247 |
{ |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1248 |
|
2 | 1249 |
#ifndef IPTOS_TOS_MASK |
1250 |
#define IPTOS_TOS_MASK 0x1e |
|
1251 |
#endif |
|
1252 |
#ifndef IPTOS_PREC_MASK |
|
1253 |
#define IPTOS_PREC_MASK 0xe0 |
|
1254 |
#endif |
|
1255 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1256 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1257 |
#if defined(KIPC_MAXSOCKBUF) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1258 |
int mib[3]; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1259 |
size_t rlen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1260 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1261 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1262 |
int *bufsize; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1263 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1264 |
#ifdef __APPLE__ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1265 |
static int maxsockbuf = -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1266 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1267 |
static long maxsockbuf = -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1268 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1269 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1270 |
|
2 | 1271 |
/* |
1272 |
* IPPROTO/IP_TOS :- |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1273 |
* 1. IPv6 on Solaris/Mac OS: |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1274 |
* Set the TOS OR Traffic Class value to cater for |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1275 |
* IPv6 and IPv4 scenarios. |
2 | 1276 |
* 2. IPv6 on Linux: By default Linux ignores flowinfo |
1277 |
* field so enable IPV6_FLOWINFO_SEND so that flowinfo |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1278 |
* will be examined. We also set the IPv4 TOS option in this case. |
2 | 1279 |
* 3. IPv4: set socket option based on ToS and Precedence |
1280 |
* fields (otherwise get invalid argument) |
|
1281 |
*/ |
|
1282 |
if (level == IPPROTO_IP && opt == IP_TOS) { |
|
1283 |
int *iptos; |
|
1284 |
||
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1285 |
#if defined(__linux__) |
2 | 1286 |
if (ipv6_available()) { |
1287 |
int optval = 1; |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1288 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND, |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1289 |
(void *)&optval, sizeof(optval)) < 0) { |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1290 |
return -1; |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1291 |
} |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1292 |
/* |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1293 |
* Let's also set the IPV6_TCLASS flag. |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1294 |
* Linux appears to allow both IP_TOS and IPV6_TCLASS to be set |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1295 |
* This helps in mixed environments where IPv4 and IPv6 sockets |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1296 |
* are connecting. |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1297 |
*/ |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1298 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1299 |
arg, len) < 0) { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1300 |
return -1; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1301 |
} |
2 | 1302 |
} |
1303 |
#endif |
|
1304 |
||
1305 |
iptos = (int *)arg; |
|
1306 |
*iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK); |
|
1307 |
} |
|
1308 |
||
1309 |
/* |
|
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1310 |
* SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On Solaris we may need to clamp |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1311 |
* the value when it exceeds the system limit. |
2 | 1312 |
*/ |
1313 |
#ifdef __solaris__ |
|
1314 |
if (level == SOL_SOCKET) { |
|
1315 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1316 |
int sotype=0; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1317 |
socklen_t arglen; |
2 | 1318 |
int *bufsize, maxbuf; |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1319 |
int ret; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1320 |
|
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1321 |
/* Attempt with the original size */ |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1322 |
ret = setsockopt(fd, level, opt, arg, len); |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1323 |
if ((ret == 0) || (ret == -1 && errno != ENOBUFS)) |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1324 |
return ret; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1325 |
|
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1326 |
/* Exceeded system limit so clamp and retry */ |
2 | 1327 |
|
1328 |
arglen = sizeof(sotype); |
|
1329 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, |
|
1330 |
&arglen) < 0) { |
|
1331 |
return -1; |
|
1332 |
} |
|
1333 |
||
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1334 |
/* |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1335 |
* We try to get tcp_maxbuf (and udp_max_buf) using |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1336 |
* an ioctl() that isn't available on all versions of Solaris. |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1337 |
* If that fails, we use the search algorithm in findMaxBuf() |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1338 |
*/ |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1339 |
if (!init_tcp_max_buf && sotype == SOCK_STREAM) { |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
1340 |
tcp_max_buf = net_getParam("/dev/tcp", "tcp_max_buf"); |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1341 |
if (tcp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1342 |
tcp_max_buf = findMaxBuf(fd, opt, SOCK_STREAM); |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1343 |
if (tcp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1344 |
return -1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1345 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1346 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1347 |
init_tcp_max_buf = 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1348 |
} else if (!init_udp_max_buf && sotype == SOCK_DGRAM) { |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
1349 |
udp_max_buf = net_getParam("/dev/udp", "udp_max_buf"); |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1350 |
if (udp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1351 |
udp_max_buf = findMaxBuf(fd, opt, SOCK_DGRAM); |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1352 |
if (udp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1353 |
return -1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1354 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1355 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1356 |
init_udp_max_buf = 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1357 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1358 |
|
2 | 1359 |
maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf; |
1360 |
bufsize = (int *)arg; |
|
1361 |
if (*bufsize > maxbuf) { |
|
1362 |
*bufsize = maxbuf; |
|
1363 |
} |
|
1364 |
} |
|
1365 |
} |
|
1366 |
#endif |
|
1367 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1368 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1369 |
if (level == SOL_SOCKET) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1370 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1371 |
/* |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1372 |
* Just try to set the requested size. If it fails we will leave the |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1373 |
* socket option as is. Setting the buffer size means only a hint in |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1374 |
* the jse2/java software layer, see javadoc. In the previous |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1375 |
* solution the buffer has always been truncated to a length of |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1376 |
* 0x100000 Byte, even if the technical limit has not been reached. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1377 |
* This kind of absolute truncation was unexpected in the jck tests. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1378 |
*/ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1379 |
int ret = setsockopt(fd, level, opt, arg, len); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1380 |
if ((ret == 0) || (ret == -1 && errno == ENOBUFS)) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1381 |
// Accept failure because of insufficient buffer memory resources. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1382 |
return 0; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1383 |
} else { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1384 |
// Deliver all other kinds of errors. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1385 |
return ret; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1386 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1387 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1388 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1389 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1390 |
|
2 | 1391 |
/* |
1392 |
* On Linux the receive buffer is used for both socket |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
27178
diff
changeset
|
1393 |
* structures and the packet payload. The implication |
2 | 1394 |
* is that if SO_RCVBUF is too small then small packets |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1395 |
* must be discarded. |
2 | 1396 |
*/ |
1397 |
#ifdef __linux__ |
|
1398 |
if (level == SOL_SOCKET && opt == SO_RCVBUF) { |
|
1399 |
int *bufsize = (int *)arg; |
|
1400 |
if (*bufsize < 1024) { |
|
1401 |
*bufsize = 1024; |
|
1402 |
} |
|
1403 |
} |
|
1404 |
#endif |
|
1405 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1406 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1407 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1408 |
* SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On FreeBSD need to |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1409 |
* ensure that value is <= kern.ipc.maxsockbuf as otherwise we get |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1410 |
* an ENOBUFS error. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1411 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1412 |
if (level == SOL_SOCKET) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1413 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1414 |
#ifdef KIPC_MAXSOCKBUF |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1415 |
if (maxsockbuf == -1) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1416 |
mib[0] = CTL_KERN; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1417 |
mib[1] = KERN_IPC; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1418 |
mib[2] = KIPC_MAXSOCKBUF; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1419 |
rlen = sizeof(maxsockbuf); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1420 |
if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1421 |
maxsockbuf = 1024; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1422 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1423 |
#if 1 |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1424 |
/* XXXBSD: This is a hack to workaround mb_max/mb_max_adj |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1425 |
problem. It should be removed when kern.ipc.maxsockbuf |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1426 |
will be real value. */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1427 |
maxsockbuf = (maxsockbuf/5)*4; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1428 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1429 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1430 |
#elif defined(__OpenBSD__) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1431 |
maxsockbuf = SB_MAX; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1432 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1433 |
maxsockbuf = 64 * 1024; /* XXX: NetBSD */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1434 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1435 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1436 |
bufsize = (int *)arg; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1437 |
if (*bufsize > maxsockbuf) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1438 |
*bufsize = maxsockbuf; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1439 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1440 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1441 |
if (opt == SO_RCVBUF && *bufsize < 1024) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1442 |
*bufsize = 1024; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1443 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1444 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1445 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1446 |
} |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1447 |
#endif |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1448 |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1449 |
#if defined(_ALLBSD_SOURCE) || defined(_AIX) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1450 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1451 |
* On Solaris, SO_REUSEADDR will allow multiple datagram |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1452 |
* sockets to bind to the same port. The network jck tests check |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1453 |
* for this "feature", so we need to emulate it by turning on |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1454 |
* SO_REUSEPORT as well for that combination. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1455 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1456 |
if (level == SOL_SOCKET && opt == SO_REUSEADDR) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1457 |
int sotype; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1458 |
socklen_t arglen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1459 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1460 |
arglen = sizeof(sotype); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1461 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) < 0) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1462 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1463 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1464 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1465 |
if (sotype == SOCK_DGRAM) { |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1466 |
setsockopt(fd, level, SO_REUSEPORT, arg, len); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1467 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1468 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1469 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1470 |
|
2 | 1471 |
return setsockopt(fd, level, opt, arg, len); |
1472 |
} |
|
1473 |
||
1474 |
/* |
|
1475 |
* Wrapper for bind system call - performs any necessary pre/post |
|
1476 |
* processing to deal with OS specific issues :- |
|
1477 |
* |
|
1478 |
* Linux allows a socket to bind to 127.0.0.255 which must be |
|
1479 |
* caught. |
|
1480 |
* |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1481 |
* On Solaris with IPv6 enabled we must use an exclusive |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1482 |
* bind to guarantee a unique port number across the IPv4 and |
2 | 1483 |
* IPv6 port spaces. |
1484 |
* |
|
1485 |
*/ |
|
1486 |
int |
|
1487 |
NET_Bind(int fd, struct sockaddr *him, int len) |
|
1488 |
{ |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1489 |
#if defined(__solaris__) |
2 | 1490 |
int level = -1; |
1491 |
int exclbind = -1; |
|
1492 |
#endif |
|
1493 |
int rv; |
|
31711 | 1494 |
int arg, alen; |
2 | 1495 |
|
1496 |
#ifdef __linux__ |
|
1497 |
/* |
|
1498 |
* ## get bugId for this issue - goes back to 1.2.2 port ## |
|
1499 |
* ## When IPv6 is enabled this will be an IPv4-mapped |
|
1500 |
* ## with family set to AF_INET6 |
|
1501 |
*/ |
|
1502 |
if (him->sa_family == AF_INET) { |
|
1503 |
struct sockaddr_in *sa = (struct sockaddr_in *)him; |
|
1504 |
if ((ntohl(sa->sin_addr.s_addr) & 0x7f0000ff) == 0x7f0000ff) { |
|
1505 |
errno = EADDRNOTAVAIL; |
|
1506 |
return -1; |
|
1507 |
} |
|
1508 |
} |
|
1509 |
#endif |
|
1510 |
||
31711 | 1511 |
#if defined(__solaris__) |
2 | 1512 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1513 |
* Solaris has separate IPv4 and IPv6 port spaces so we |
2 | 1514 |
* use an exclusive bind when SO_REUSEADDR is not used to |
1515 |
* give the illusion of a unified port space. |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1516 |
* This also avoids problems with IPv6 sockets connecting |
2 | 1517 |
* to IPv4 mapped addresses whereby the socket conversion |
1518 |
* results in a late bind that fails because the |
|
1519 |
* corresponding IPv4 port is in use. |
|
1520 |
*/ |
|
31711 | 1521 |
alen = sizeof(arg); |
2 | 1522 |
|
31711 | 1523 |
if (useExclBind || getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, |
1524 |
(char *)&arg, &alen) == 0) { |
|
1525 |
if (useExclBind || arg == 0) { |
|
1526 |
/* |
|
1527 |
* SO_REUSEADDR is disabled or sun.net.useExclusiveBind |
|
1528 |
* property is true so enable TCP_EXCLBIND or |
|
1529 |
* UDP_EXCLBIND |
|
1530 |
*/ |
|
1531 |
alen = sizeof(arg); |
|
1532 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&arg, |
|
1533 |
&alen) == 0) { |
|
1534 |
if (arg == SOCK_STREAM) { |
|
1535 |
level = IPPROTO_TCP; |
|
1536 |
exclbind = TCP_EXCLBIND; |
|
1537 |
} else { |
|
1538 |
level = IPPROTO_UDP; |
|
1539 |
exclbind = UDP_EXCLBIND; |
|
2 | 1540 |
} |
31711 | 1541 |
} |
2 | 1542 |
|
31711 | 1543 |
arg = 1; |
1544 |
setsockopt(fd, level, exclbind, (char *)&arg, |
|
1545 |
sizeof(arg)); |
|
2 | 1546 |
} |
1547 |
} |
|
1548 |
||
1549 |
#endif |
|
1550 |
||
1551 |
rv = bind(fd, him, len); |
|
1552 |
||
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1553 |
#if defined(__solaris__) |
2 | 1554 |
if (rv < 0) { |
1555 |
int en = errno; |
|
1556 |
/* Restore *_EXCLBIND if the bind fails */ |
|
1557 |
if (exclbind != -1) { |
|
1558 |
int arg = 0; |
|
1559 |
setsockopt(fd, level, exclbind, (char *)&arg, |
|
1560 |
sizeof(arg)); |
|
1561 |
} |
|
1562 |
errno = en; |
|
1563 |
} |
|
1564 |
#endif |
|
1565 |
||
1566 |
return rv; |
|
1567 |
} |
|
1568 |
||
1569 |
/** |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1570 |
* Wrapper for poll with timeout on a single file descriptor. |
2 | 1571 |
* |
1572 |
* flags (defined in net_util_md.h can be any combination of |
|
1573 |
* NET_WAIT_READ, NET_WAIT_WRITE & NET_WAIT_CONNECT. |
|
1574 |
* |
|
1575 |
* The function will return when either the socket is ready for one |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1576 |
* of the specified operations or the timeout expired. |
2 | 1577 |
* |
1578 |
* It returns the time left from the timeout (possibly 0), or -1 if it expired. |
|
1579 |
*/ |
|
1580 |
||
1581 |
jint |
|
1582 |
NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout) |
|
1583 |
{ |
|
1584 |
jlong prevTime = JVM_CurrentTimeMillis(env, 0); |
|
1585 |
jint read_rv; |
|
1586 |
||
1587 |
while (1) { |
|
1588 |
jlong newTime; |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1589 |
struct pollfd pfd; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1590 |
pfd.fd = fd; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1591 |
pfd.events = 0; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1592 |
if (flags & NET_WAIT_READ) |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1593 |
pfd.events |= POLLIN; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1594 |
if (flags & NET_WAIT_WRITE) |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1595 |
pfd.events |= POLLOUT; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1596 |
if (flags & NET_WAIT_CONNECT) |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1597 |
pfd.events |= POLLOUT; |
2 | 1598 |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1599 |
errno = 0; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1600 |
read_rv = NET_Poll(&pfd, 1, timeout); |
2 | 1601 |
|
1602 |
newTime = JVM_CurrentTimeMillis(env, 0); |
|
1603 |
timeout -= (newTime - prevTime); |
|
1604 |
if (timeout <= 0) { |
|
1605 |
return read_rv > 0 ? 0 : -1; |
|
1606 |
} |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1607 |
prevTime = newTime; |
2 | 1608 |
|
1609 |
if (read_rv > 0) { |
|
1610 |
break; |
|
1611 |
} |
|
1612 |
||
1613 |
||
1614 |
} /* while */ |
|
1615 |
||
1616 |
return timeout; |
|
1617 |
} |
|
40937
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1618 |
|
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1619 |
long NET_GetCurrentTime() { |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1620 |
struct timeval time; |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1621 |
gettimeofday(&time, NULL); |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1622 |
return (time.tv_sec * 1000 + time.tv_usec / 1000); |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1623 |
} |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1624 |
|
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1625 |
int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime) { |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1626 |
return NET_Timeout0(s, timeout, currentTime); |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1627 |
} |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1628 |
|
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1629 |
int NET_Timeout(int s, long timeout) { |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1630 |
long currentTime = (timeout > 0) ? NET_GetCurrentTime() : 0; |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1631 |
return NET_Timeout0(s, timeout, currentTime); |
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
1632 |
} |