author | alanb |
Sun, 19 Oct 2014 11:52:53 +0100 | |
changeset 27178 | 885f4428b501 |
parent 26595 | 1f96f8175e05 |
child 41380 | c27cf95dd7e6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
22956
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, 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 |
*/ |
25 |
||
26 |
#include <stdlib.h> |
|
27 |
#include <windows.h> |
|
28 |
#include <winsock2.h> /* needed for htonl */ |
|
29 |
#include <iprtrmib.h> |
|
30 |
#include <assert.h> |
|
31 |
||
32 |
#include "java_net_NetworkInterface.h" |
|
33 |
#include "jni_util.h" |
|
34 |
||
35 |
#include "NetworkInterface.h" |
|
36 |
||
37 |
/* |
|
38 |
* Windows implementation of the java.net.NetworkInterface native methods. |
|
39 |
* This module provides the implementations of getAll, getByName, getByIndex, |
|
40 |
* and getByAddress. |
|
41 |
* |
|
42 |
* Interfaces and addresses are enumerated using the IP helper routines |
|
43 |
* GetIfTable, GetIfAddrTable resp. These routines are available on Windows |
|
44 |
* 98, NT SP+4, 2000, and XP. They are also available on Windows 95 if |
|
45 |
* IE is upgraded to 5.x. |
|
46 |
* |
|
47 |
* Windows does not have any standard for device names so we are forced |
|
48 |
* to use our own convention which is based on the normal Unix naming |
|
49 |
* convention ("lo" for the loopback, eth0, eth1, .. for ethernet devices, |
|
50 |
* tr0, tr1, .. for token ring, and so on). This convention gives us |
|
51 |
* consistency across multiple Windows editions and also consistency with |
|
52 |
* Solaris/Linux device names. Note that we always enumerate in index |
|
53 |
* order and this ensures consistent device number across invocations. |
|
54 |
*/ |
|
55 |
||
56 |
/* various JNI ids */ |
|
57 |
||
58 |
jclass ni_class; /* NetworkInterface */ |
|
59 |
||
60 |
jmethodID ni_ctor; /* NetworkInterface() */ |
|
61 |
||
62 |
jfieldID ni_indexID; /* NetworkInterface.index */ |
|
63 |
jfieldID ni_addrsID; /* NetworkInterface.addrs */ |
|
64 |
jfieldID ni_bindsID; /* NetworkInterface.bindings */ |
|
65 |
jfieldID ni_nameID; /* NetworkInterface.name */ |
|
66 |
jfieldID ni_displayNameID; /* NetworkInterface.displayName */ |
|
67 |
jfieldID ni_childsID; /* NetworkInterface.childs */ |
|
68 |
||
69 |
jclass ni_ibcls; /* InterfaceAddress */ |
|
70 |
jmethodID ni_ibctrID; /* InterfaceAddress() */ |
|
71 |
jfieldID ni_ibaddressID; /* InterfaceAddress.address */ |
|
72 |
jfieldID ni_ibbroadcastID; /* InterfaceAddress.broadcast */ |
|
73 |
jfieldID ni_ibmaskID; /* InterfaceAddress.maskLength */ |
|
74 |
||
75 |
/* |
|
76 |
* Support routines to free netif and netaddr lists |
|
77 |
*/ |
|
78 |
void free_netif(netif *netifP) { |
|
79 |
netif *curr = netifP; |
|
80 |
while (curr != NULL) { |
|
81 |
if (curr->name != NULL) |
|
82 |
free(curr->name); |
|
83 |
if (curr->displayName != NULL) |
|
84 |
free(curr->displayName); |
|
85 |
if (curr->addrs != NULL) |
|
86 |
free_netaddr (curr->addrs); |
|
87 |
netifP = netifP->next; |
|
88 |
free(curr); |
|
89 |
curr = netifP; |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
void free_netaddr(netaddr *netaddrP) { |
|
94 |
netaddr *curr = netaddrP; |
|
95 |
while (curr != NULL) { |
|
96 |
netaddrP = netaddrP->next; |
|
97 |
free(curr); |
|
98 |
curr = netaddrP; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
/* |
|
103 |
* Returns the interface structure from the table with the matching index. |
|
104 |
*/ |
|
105 |
MIB_IFROW *getIF(jint index) { |
|
106 |
MIB_IFTABLE *tableP; |
|
107 |
MIB_IFROW *ifrowP, *ret = NULL; |
|
108 |
ULONG size; |
|
109 |
DWORD i, count; |
|
110 |
jint ifindex; |
|
111 |
||
112 |
/* |
|
113 |
* Ask the IP Helper library to enumerate the adapters |
|
114 |
*/ |
|
115 |
size = sizeof(MIB_IFTABLE); |
|
116 |
tableP = (MIB_IFTABLE *)malloc(size); |
|
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
117 |
if(tableP == NULL) |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
118 |
return NULL; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
119 |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
120 |
count = GetIfTable(tableP, &size, TRUE); |
2 | 121 |
if (count == ERROR_INSUFFICIENT_BUFFER || count == ERROR_BUFFER_OVERFLOW) { |
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
122 |
MIB_IFTABLE* newTableP = (MIB_IFTABLE *)realloc(tableP, size); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
123 |
if (newTableP == NULL) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
124 |
free(tableP); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
125 |
return NULL; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
126 |
} |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
127 |
tableP = newTableP; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
128 |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
129 |
count = GetIfTable(tableP, &size, TRUE); |
2 | 130 |
} |
131 |
||
132 |
if (count != NO_ERROR) { |
|
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
133 |
free(tableP); |
2 | 134 |
return NULL; |
135 |
} |
|
136 |
||
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
137 |
{ |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
138 |
ifrowP = tableP->table; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
139 |
for (i=0; i<tableP->dwNumEntries; i++) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
140 |
/* |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
141 |
* Warning: the real index is obtained by GetFriendlyIfIndex() |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
142 |
*/ |
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
143 |
ifindex = GetFriendlyIfIndex(ifrowP->dwIndex); |
2 | 144 |
if (ifindex == index) { |
145 |
/* |
|
146 |
* Create a copy of the entry so that we can free the table. |
|
147 |
*/ |
|
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
148 |
ret = (MIB_IFROW *) malloc(sizeof(MIB_IFROW)); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
149 |
if (ret == NULL) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
150 |
free(tableP); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
151 |
return NULL; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
152 |
} |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
153 |
memcpy(ret, ifrowP, sizeof(MIB_IFROW)); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
154 |
break; |
2 | 155 |
} |
156 |
||
157 |
/* onto the next interface */ |
|
158 |
ifrowP++; |
|
159 |
} |
|
160 |
free(tableP); |
|
161 |
} |
|
162 |
return ret; |
|
163 |
} |
|
164 |
||
165 |
/* |
|
166 |
* Enumerate network interfaces using IP Helper Library routine GetIfTable. |
|
167 |
* We use GetIfTable rather than other IP helper routines because it's |
|
168 |
* available on 98 & NT SP4+. |
|
169 |
* |
|
170 |
* Returns the number of interfaces found or -1 if error. If no error |
|
171 |
* occurs then netifPP be returned as list of netif structures or NULL |
|
172 |
* if no interfaces are found. |
|
173 |
*/ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
174 |
int enumInterfaces(JNIEnv *env, netif **netifPP) |
2 | 175 |
{ |
176 |
MIB_IFTABLE *tableP; |
|
177 |
MIB_IFROW *ifrowP; |
|
178 |
ULONG size; |
|
179 |
DWORD ret; |
|
180 |
int count; |
|
181 |
netif *netifP; |
|
182 |
DWORD i; |
|
14768
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
183 |
int lo=0, eth=0, tr=0, fddi=0, ppp=0, sl=0, wlan=0, net=0, wlen=0; |
2 | 184 |
|
185 |
/* |
|
186 |
* Ask the IP Helper library to enumerate the adapters |
|
187 |
*/ |
|
188 |
size = sizeof(MIB_IFTABLE); |
|
189 |
tableP = (MIB_IFTABLE *)malloc(size); |
|
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
190 |
if (tableP == NULL) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
191 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure"); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
192 |
return -1; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
193 |
} |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
194 |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
195 |
ret = GetIfTable(tableP, &size, TRUE); |
2 | 196 |
if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW) { |
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
197 |
MIB_IFTABLE * newTableP = (MIB_IFTABLE *)realloc(tableP, size); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
198 |
if (newTableP == NULL) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
199 |
free(tableP); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
200 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure"); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
201 |
return -1; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
202 |
} |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
203 |
tableP = newTableP; |
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
204 |
ret = GetIfTable(tableP, &size, TRUE); |
2 | 205 |
} |
206 |
||
207 |
if (ret != NO_ERROR) { |
|
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
208 |
free(tableP); |
2 | 209 |
|
210 |
JNU_ThrowByName(env, "java/lang/Error", |
|
211 |
"IP Helper Library GetIfTable function failed"); |
|
212 |
||
213 |
return -1; |
|
214 |
} |
|
215 |
||
216 |
/* |
|
217 |
* Iterate through the list of adapters |
|
218 |
*/ |
|
219 |
count = 0; |
|
220 |
netifP = NULL; |
|
221 |
||
222 |
ifrowP = tableP->table; |
|
223 |
for (i=0; i<tableP->dwNumEntries; i++) { |
|
224 |
char dev_name[8]; |
|
225 |
netif *curr; |
|
226 |
||
227 |
/* |
|
228 |
* Generate a name for the device as Windows doesn't have any |
|
229 |
* real concept of a device name. |
|
230 |
*/ |
|
231 |
switch (ifrowP->dwType) { |
|
232 |
case MIB_IF_TYPE_ETHERNET: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
233 |
_snprintf_s(dev_name, 8, _TRUNCATE, "eth%d", eth++); |
2 | 234 |
break; |
235 |
||
236 |
case MIB_IF_TYPE_TOKENRING: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
237 |
_snprintf_s(dev_name, 8, _TRUNCATE, "tr%d", tr++); |
2 | 238 |
break; |
239 |
||
240 |
case MIB_IF_TYPE_FDDI: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
241 |
_snprintf_s(dev_name, 8, _TRUNCATE, "fddi%d", fddi++); |
2 | 242 |
break; |
243 |
||
244 |
case MIB_IF_TYPE_LOOPBACK: |
|
245 |
/* There should only be only IPv4 loopback address */ |
|
246 |
if (lo > 0) { |
|
247 |
continue; |
|
248 |
} |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
249 |
strncpy_s(dev_name, 8, "lo", _TRUNCATE); |
2 | 250 |
lo++; |
251 |
break; |
|
252 |
||
253 |
case MIB_IF_TYPE_PPP: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
254 |
_snprintf_s(dev_name, 8, _TRUNCATE, "ppp%d", ppp++); |
2 | 255 |
break; |
256 |
||
257 |
case MIB_IF_TYPE_SLIP: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
258 |
_snprintf_s(dev_name, 8, _TRUNCATE, "sl%d", sl++); |
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
259 |
break; |
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
260 |
|
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
261 |
case IF_TYPE_IEEE80211: |
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
262 |
_snprintf_s(dev_name, 8, _TRUNCATE, "wlan%d", wlan++); |
2 | 263 |
break; |
264 |
||
265 |
default: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
266 |
_snprintf_s(dev_name, 8, _TRUNCATE, "net%d", net++); |
2 | 267 |
} |
268 |
||
269 |
/* |
|
270 |
* Allocate a netif structure and space for the name and |
|
271 |
* display name (description in this case). |
|
272 |
*/ |
|
273 |
curr = (netif *)calloc(1, sizeof(netif)); |
|
274 |
if (curr != NULL) { |
|
14768
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
275 |
wlen = MultiByteToWideChar(CP_OEMCP, 0, ifrowP->bDescr, |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
276 |
ifrowP->dwDescrLen, NULL, 0); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
277 |
if(wlen == 0) { |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
278 |
// MultiByteToWideChar should not fail |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
279 |
// But in rare case it fails, we allow 'char' to be displayed |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
280 |
curr->displayName = (char *)malloc(ifrowP->dwDescrLen + 1); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
281 |
} else { |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
282 |
curr->displayName = (wchar_t *)malloc(wlen*(sizeof(wchar_t))+1); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
283 |
} |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
284 |
|
2 | 285 |
curr->name = (char *)malloc(strlen(dev_name) + 1); |
286 |
||
287 |
if (curr->name == NULL || curr->displayName == NULL) { |
|
288 |
if (curr->name) free(curr->name); |
|
289 |
if (curr->displayName) free(curr->displayName); |
|
290 |
curr = NULL; |
|
291 |
} |
|
292 |
} |
|
293 |
if (curr == NULL) { |
|
13245
7ab3ef5b9520
7181353: Update error message to distinguish native OOM and java OOM in net
zhouyx
parents:
12542
diff
changeset
|
294 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure"); |
2 | 295 |
free_netif(netifP); |
296 |
free(tableP); |
|
297 |
return -1; |
|
298 |
} |
|
299 |
||
300 |
/* |
|
301 |
* Populate the interface. Note that we need to convert the |
|
302 |
* index into its "friendly" value as otherwise we will expose |
|
303 |
* 32-bit numbers as index values. |
|
304 |
*/ |
|
305 |
strcpy(curr->name, dev_name); |
|
14768
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
306 |
if (wlen == 0) { |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
307 |
// display char type in case of MultiByteToWideChar failure |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
308 |
strncpy(curr->displayName, ifrowP->bDescr, ifrowP->dwDescrLen); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
309 |
curr->displayName[ifrowP->dwDescrLen] = '\0'; |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
310 |
} else { |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
311 |
// call MultiByteToWideChar again to fill curr->displayName |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
312 |
// it should not fail, because we have called it once before |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
313 |
if (MultiByteToWideChar(CP_OEMCP, 0, ifrowP->bDescr, |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
314 |
ifrowP->dwDescrLen, curr->displayName, wlen) == 0) { |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
315 |
JNU_ThrowByName(env, "java/lang/Error", |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
316 |
"Cannot get multibyte char for interface display name"); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
317 |
free_netif(netifP); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
318 |
free(tableP); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
319 |
free(curr->name); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
320 |
free(curr->displayName); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
321 |
free(curr); |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
322 |
return -1; |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
323 |
} else { |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
324 |
curr->displayName[wlen*(sizeof(wchar_t))] = '\0'; |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
325 |
curr->dNameIsUnicode = TRUE; |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
326 |
} |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
327 |
} |
8800c12ef525
6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents:
14342
diff
changeset
|
328 |
|
2 | 329 |
curr->dwIndex = ifrowP->dwIndex; |
330 |
curr->ifType = ifrowP->dwType; |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
331 |
curr->index = GetFriendlyIfIndex(ifrowP->dwIndex); |
2 | 332 |
|
333 |
/* |
|
334 |
* Put the interface at tail of list as GetIfTable(,,TRUE) is |
|
335 |
* returning the interfaces in index order. |
|
336 |
*/ |
|
337 |
count++; |
|
338 |
if (netifP == NULL) { |
|
339 |
netifP = curr; |
|
340 |
} else { |
|
341 |
netif *tail = netifP; |
|
342 |
while (tail->next != NULL) { |
|
343 |
tail = tail->next; |
|
344 |
} |
|
345 |
tail->next = curr; |
|
346 |
} |
|
347 |
||
348 |
/* onto the next interface */ |
|
349 |
ifrowP++; |
|
350 |
} |
|
351 |
||
352 |
/* |
|
353 |
* Free the interface table and return the interface list |
|
354 |
*/ |
|
355 |
if (tableP) { |
|
356 |
free(tableP); |
|
357 |
} |
|
358 |
*netifPP = netifP; |
|
359 |
return count; |
|
360 |
} |
|
361 |
||
362 |
/* |
|
363 |
* Enumerate the IP addresses on an interface using the IP helper library |
|
364 |
* routine GetIfAddrTable and matching based on the index name. There are |
|
365 |
* more efficient routines but we use GetIfAddrTable because it's avaliable |
|
366 |
* on 98 and NT. |
|
367 |
* |
|
368 |
* Returns the count of addresses, or -1 if error. If no error occurs then |
|
369 |
* netaddrPP will return a list of netaddr structures with the IP addresses. |
|
370 |
*/ |
|
371 |
int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP) |
|
372 |
{ |
|
373 |
MIB_IPADDRTABLE *tableP; |
|
374 |
ULONG size; |
|
375 |
DWORD ret; |
|
376 |
DWORD i; |
|
377 |
netaddr *netaddrP; |
|
378 |
int count = 0; |
|
379 |
unsigned long mask; |
|
380 |
||
381 |
/* |
|
382 |
* Use GetIpAddrTable to enumerate the IP Addresses |
|
383 |
*/ |
|
384 |
size = sizeof(MIB_IPADDRTABLE); |
|
385 |
tableP = (MIB_IPADDRTABLE *)malloc(size); |
|
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
386 |
if (tableP == NULL) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
387 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure"); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
388 |
return -1; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
389 |
} |
2 | 390 |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
391 |
ret = GetIpAddrTable(tableP, &size, FALSE); |
2 | 392 |
if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW) { |
17193
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
393 |
MIB_IPADDRTABLE * newTableP = (MIB_IPADDRTABLE *)realloc(tableP, size); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
394 |
if (newTableP == NULL) { |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
395 |
free(tableP); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
396 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure"); |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
397 |
return -1; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
398 |
} |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
399 |
tableP = newTableP; |
8b561b7fb87a
8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents:
16870
diff
changeset
|
400 |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
401 |
ret = GetIpAddrTable(tableP, &size, FALSE); |
2 | 402 |
} |
403 |
if (ret != NO_ERROR) { |
|
404 |
if (tableP) { |
|
405 |
free(tableP); |
|
406 |
} |
|
407 |
JNU_ThrowByName(env, "java/lang/Error", |
|
408 |
"IP Helper Library GetIpAddrTable function failed"); |
|
409 |
return -1; |
|
410 |
} |
|
411 |
||
412 |
/* |
|
413 |
* Iterate through the table to find the addresses with the |
|
414 |
* matching dwIndex. Ignore 0.0.0.0 addresses. |
|
415 |
*/ |
|
416 |
count = 0; |
|
417 |
netaddrP = NULL; |
|
418 |
||
419 |
i = 0; |
|
420 |
while (i<tableP->dwNumEntries) { |
|
421 |
if (tableP->table[i].dwIndex == netifP->dwIndex && |
|
422 |
tableP->table[i].dwAddr != 0) { |
|
423 |
||
424 |
netaddr *curr = (netaddr *)malloc(sizeof(netaddr)); |
|
425 |
if (curr == NULL) { |
|
13245
7ab3ef5b9520
7181353: Update error message to distinguish native OOM and java OOM in net
zhouyx
parents:
12542
diff
changeset
|
426 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure"); |
2 | 427 |
free_netaddr(netaddrP); |
428 |
free(tableP); |
|
429 |
return -1; |
|
430 |
} |
|
431 |
||
432 |
curr->addr.him4.sin_family = AF_INET; |
|
433 |
curr->addr.him4.sin_addr.s_addr = tableP->table[i].dwAddr; |
|
434 |
/* |
|
435 |
* Get netmask / broadcast address |
|
436 |
*/ |
|
437 |
switch (netifP->ifType) { |
|
438 |
case MIB_IF_TYPE_ETHERNET: |
|
439 |
case MIB_IF_TYPE_TOKENRING: |
|
440 |
case MIB_IF_TYPE_FDDI: |
|
441 |
case MIB_IF_TYPE_LOOPBACK: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
442 |
case IF_TYPE_IEEE80211: |
2 | 443 |
/** |
444 |
* Contrary to what it seems to indicate, dwBCastAddr doesn't |
|
445 |
* contain the broadcast address but 0 or 1 depending on whether |
|
446 |
* the broadcast address should set the bits of the host part |
|
447 |
* to 0 or 1. |
|
448 |
* Yes, I know it's stupid, but what can I say, it's MSFTs API. |
|
449 |
*/ |
|
450 |
curr->brdcast.him4.sin_family = AF_INET; |
|
451 |
if (tableP->table[i].dwBCastAddr == 1) |
|
452 |
curr->brdcast.him4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask) | (0xffffffff ^ tableP->table[i].dwMask); |
|
453 |
else |
|
454 |
curr->brdcast.him4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask); |
|
455 |
mask = ntohl(tableP->table[i].dwMask); |
|
456 |
curr->mask = 0; |
|
457 |
while (mask) { |
|
458 |
mask <<= 1; |
|
459 |
curr->mask++; |
|
460 |
} |
|
461 |
break; |
|
462 |
case MIB_IF_TYPE_PPP: |
|
463 |
case MIB_IF_TYPE_SLIP: |
|
464 |
default: |
|
465 |
/** |
|
466 |
* these don't have broadcast/subnet |
|
467 |
*/ |
|
468 |
curr->mask = -1; |
|
469 |
break; |
|
470 |
} |
|
471 |
||
472 |
curr->next = netaddrP; |
|
473 |
netaddrP = curr; |
|
474 |
count++; |
|
475 |
} |
|
476 |
i++; |
|
477 |
} |
|
478 |
||
479 |
*netaddrPP = netaddrP; |
|
480 |
free(tableP); |
|
481 |
return count; |
|
482 |
} |
|
483 |
||
484 |
/* |
|
485 |
* Class: java_net_NetworkInterface |
|
486 |
* Method: init |
|
487 |
* Signature: ()V |
|
488 |
*/ |
|
489 |
JNIEXPORT void JNICALL |
|
490 |
Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls) |
|
491 |
{ |
|
492 |
/* |
|
493 |
* Get the various JNI ids that we require |
|
494 |
*/ |
|
495 |
ni_class = (*env)->NewGlobalRef(env, cls); |
|
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
496 |
CHECK_NULL(ni_class); |
2 | 497 |
ni_nameID = (*env)->GetFieldID(env, ni_class, "name", "Ljava/lang/String;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
498 |
CHECK_NULL(ni_nameID); |
2 | 499 |
ni_displayNameID = (*env)->GetFieldID(env, ni_class, "displayName", "Ljava/lang/String;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
500 |
CHECK_NULL(ni_displayNameID); |
2 | 501 |
ni_indexID = (*env)->GetFieldID(env, ni_class, "index", "I"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
502 |
CHECK_NULL(ni_indexID); |
2 | 503 |
ni_addrsID = (*env)->GetFieldID(env, ni_class, "addrs", "[Ljava/net/InetAddress;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
504 |
CHECK_NULL(ni_addrsID); |
2 | 505 |
ni_bindsID = (*env)->GetFieldID(env, ni_class, "bindings", "[Ljava/net/InterfaceAddress;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
506 |
CHECK_NULL(ni_bindsID); |
2 | 507 |
ni_childsID = (*env)->GetFieldID(env, ni_class, "childs", "[Ljava/net/NetworkInterface;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
508 |
CHECK_NULL(ni_childsID); |
2 | 509 |
ni_ctor = (*env)->GetMethodID(env, ni_class, "<init>", "()V"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
510 |
CHECK_NULL(ni_ctor); |
2 | 511 |
ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
512 |
CHECK_NULL(ni_ibcls); |
2 | 513 |
ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
514 |
CHECK_NULL(ni_ibcls); |
2 | 515 |
ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
516 |
CHECK_NULL(ni_ibctrID); |
2 | 517 |
ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
518 |
CHECK_NULL(ni_ibaddressID); |
2 | 519 |
ni_ibbroadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20851
diff
changeset
|
520 |
CHECK_NULL(ni_ibbroadcastID); |
2 | 521 |
ni_ibmaskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S"); |
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
522 |
CHECK_NULL(ni_ibmaskID); |
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
523 |
|
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
524 |
initInetAddressIDs(env); |
2 | 525 |
} |
526 |
||
527 |
/* |
|
528 |
* Create a NetworkInterface object, populate the name and index, and |
|
529 |
* populate the InetAddress array based on the IP addresses for this |
|
530 |
* interface. |
|
531 |
*/ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
532 |
jobject createNetworkInterface |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
533 |
(JNIEnv *env, netif *ifs, int netaddrCount, netaddr *netaddrP) |
2 | 534 |
{ |
535 |
jobject netifObj; |
|
536 |
jobject name, displayName; |
|
537 |
jobjectArray addrArr, bindsArr, childArr; |
|
538 |
netaddr *addrs; |
|
539 |
jint addr_index; |
|
540 |
jint bind_index; |
|
541 |
||
542 |
/* |
|
543 |
* Create a NetworkInterface object and populate it |
|
544 |
*/ |
|
545 |
netifObj = (*env)->NewObject(env, ni_class, ni_ctor); |
|
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
546 |
CHECK_NULL_RETURN(netifObj, NULL); |
2 | 547 |
name = (*env)->NewStringUTF(env, ifs->name); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
548 |
CHECK_NULL_RETURN(name, NULL); |
2 | 549 |
if (ifs->dNameIsUnicode) { |
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
550 |
displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName, |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
551 |
(jsize)wcslen ((PWCHAR)ifs->displayName)); |
2 | 552 |
} else { |
553 |
displayName = (*env)->NewStringUTF(env, ifs->displayName); |
|
554 |
} |
|
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
555 |
CHECK_NULL_RETURN(displayName, NULL); |
2 | 556 |
(*env)->SetObjectField(env, netifObj, ni_nameID, name); |
557 |
(*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName); |
|
558 |
(*env)->SetIntField(env, netifObj, ni_indexID, ifs->index); |
|
559 |
||
560 |
/* |
|
561 |
* Get the IP addresses for this interface if necessary |
|
562 |
* Note that 0 is a valid number of addresses. |
|
563 |
*/ |
|
564 |
if (netaddrCount < 0) { |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
565 |
netaddrCount = enumAddresses_win(env, ifs, &netaddrP); |
10417 | 566 |
if (netaddrCount == -1) { |
2 | 567 |
return NULL; |
568 |
} |
|
569 |
} |
|
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
570 |
addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL); |
2 | 571 |
if (addrArr == NULL) { |
572 |
free_netaddr(netaddrP); |
|
573 |
return NULL; |
|
574 |
} |
|
575 |
||
576 |
bindsArr = (*env)->NewObjectArray(env, netaddrCount, ni_ibcls, NULL); |
|
577 |
if (bindsArr == NULL) { |
|
578 |
free_netaddr(netaddrP); |
|
579 |
return NULL; |
|
580 |
} |
|
581 |
addrs = netaddrP; |
|
582 |
addr_index = 0; |
|
583 |
bind_index = 0; |
|
584 |
while (addrs != NULL) { |
|
585 |
jobject iaObj, ia2Obj; |
|
586 |
jobject ibObj = NULL; |
|
587 |
if (addrs->addr.him.sa_family == AF_INET) { |
|
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
588 |
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); |
2 | 589 |
if (iaObj == NULL) { |
590 |
free_netaddr(netaddrP); |
|
591 |
return NULL; |
|
592 |
} |
|
593 |
/* default ctor will set family to AF_INET */ |
|
594 |
||
16870 | 595 |
setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr)); |
2 | 596 |
if (addrs->mask != -1) { |
597 |
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); |
|
598 |
if (ibObj == NULL) { |
|
599 |
free_netaddr(netaddrP); |
|
600 |
return NULL; |
|
601 |
} |
|
602 |
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); |
|
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
603 |
ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID); |
2 | 604 |
if (ia2Obj == NULL) { |
605 |
free_netaddr(netaddrP); |
|
606 |
return NULL; |
|
607 |
} |
|
16870 | 608 |
setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr)); |
2 | 609 |
(*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj); |
610 |
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask); |
|
611 |
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); |
|
612 |
} |
|
613 |
} else /* AF_INET6 */ { |
|
614 |
int scope; |
|
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
21409
diff
changeset
|
615 |
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); |
2 | 616 |
if (iaObj) { |
22956 | 617 |
jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); |
20821 | 618 |
if (ret == JNI_FALSE) { |
2 | 619 |
return NULL; |
620 |
} |
|
20821 | 621 |
|
2 | 622 |
scope = addrs->addr.him6.sin6_scope_id; |
623 |
if (scope != 0) { /* zero is default value, no need to set */ |
|
20821 | 624 |
setInet6Address_scopeid(env, iaObj, scope); |
625 |
setInet6Address_scopeifname(env, iaObj, netifObj); |
|
2 | 626 |
} |
627 |
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); |
|
628 |
if (ibObj == NULL) { |
|
629 |
free_netaddr(netaddrP); |
|
630 |
return NULL; |
|
631 |
} |
|
632 |
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); |
|
633 |
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask); |
|
634 |
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); |
|
635 |
} |
|
636 |
} |
|
637 |
(*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj); |
|
638 |
addrs = addrs->next; |
|
639 |
addr_index++; |
|
640 |
} |
|
641 |
(*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr); |
|
642 |
(*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr); |
|
643 |
||
644 |
free_netaddr(netaddrP); |
|
645 |
||
646 |
/* |
|
647 |
* Windows doesn't have virtual interfaces, so child array |
|
648 |
* is always empty. |
|
649 |
*/ |
|
650 |
childArr = (*env)->NewObjectArray(env, 0, ni_class, NULL); |
|
651 |
if (childArr == NULL) { |
|
652 |
return NULL; |
|
653 |
} |
|
654 |
(*env)->SetObjectField(env, netifObj, ni_childsID, childArr); |
|
655 |
||
656 |
/* return the NetworkInterface */ |
|
657 |
return netifObj; |
|
658 |
} |
|
659 |
||
660 |
/* |
|
661 |
* Class: java_net_NetworkInterface |
|
662 |
* Method: getByName0 |
|
663 |
* Signature: (Ljava/lang/String;)Ljava/net/NetworkInterface; |
|
664 |
*/ |
|
665 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0 |
|
666 |
(JNIEnv *env, jclass cls, jstring name) |
|
667 |
{ |
|
668 |
netif *ifList, *curr; |
|
669 |
jboolean isCopy; |
|
670 |
const char *name_utf; |
|
671 |
jobject netifObj = NULL; |
|
672 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
673 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
674 |
if (ipv6_available()) { |
2 | 675 |
return Java_java_net_NetworkInterface_getByName0_XP (env, cls, name); |
676 |
} |
|
677 |
||
678 |
/* get the list of interfaces */ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
679 |
if (enumInterfaces(env, &ifList) < 0) { |
2 | 680 |
return NULL; |
681 |
} |
|
682 |
||
683 |
/* get the name as a C string */ |
|
684 |
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy); |
|
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
685 |
if (name_utf != NULL) { |
2 | 686 |
|
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
687 |
/* Search by name */ |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
688 |
curr = ifList; |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
689 |
while (curr != NULL) { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
690 |
if (strcmp(name_utf, curr->name) == 0) { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
691 |
break; |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
692 |
} |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
693 |
curr = curr->next; |
2 | 694 |
} |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
695 |
|
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
696 |
/* if found create a NetworkInterface */ |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
697 |
if (curr != NULL) {; |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
698 |
netifObj = createNetworkInterface(env, curr, -1, NULL); |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
699 |
} |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
700 |
|
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
701 |
/* release the UTF string */ |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
702 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
703 |
} else { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
704 |
if (!(*env)->ExceptionCheck(env)) |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23010
diff
changeset
|
705 |
JNU_ThrowOutOfMemoryError(env, NULL); |
2 | 706 |
} |
707 |
||
708 |
/* release the interface list */ |
|
709 |
free_netif(ifList); |
|
710 |
||
711 |
return netifObj; |
|
712 |
} |
|
713 |
||
714 |
/* |
|
715 |
* Class: NetworkInterface |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
1094
diff
changeset
|
716 |
* Method: getByIndex0 |
2 | 717 |
* Signature: (I)LNetworkInterface; |
718 |
*/ |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
1094
diff
changeset
|
719 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0 |
2 | 720 |
(JNIEnv *env, jclass cls, jint index) |
721 |
{ |
|
722 |
netif *ifList, *curr; |
|
723 |
jobject netifObj = NULL; |
|
724 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
725 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
726 |
if (ipv6_available()) { |
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
1094
diff
changeset
|
727 |
return Java_java_net_NetworkInterface_getByIndex0_XP (env, cls, index); |
2 | 728 |
} |
729 |
||
730 |
/* get the list of interfaces */ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
731 |
if (enumInterfaces(env, &ifList) < 0) { |
2 | 732 |
return NULL; |
733 |
} |
|
734 |
||
735 |
/* search by index */ |
|
736 |
curr = ifList; |
|
737 |
while (curr != NULL) { |
|
738 |
if (index == curr->index) { |
|
739 |
break; |
|
740 |
} |
|
741 |
curr = curr->next; |
|
742 |
} |
|
743 |
||
744 |
/* if found create a NetworkInterface */ |
|
745 |
if (curr != NULL) { |
|
746 |
netifObj = createNetworkInterface(env, curr, -1, NULL); |
|
747 |
} |
|
748 |
||
749 |
/* release the interface list */ |
|
750 |
free_netif(ifList); |
|
751 |
||
752 |
return netifObj; |
|
753 |
} |
|
754 |
||
755 |
/* |
|
756 |
* Class: java_net_NetworkInterface |
|
757 |
* Method: getByInetAddress0 |
|
758 |
* Signature: (Ljava/net/InetAddress;)Ljava/net/NetworkInterface; |
|
759 |
*/ |
|
760 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0 |
|
761 |
(JNIEnv *env, jclass cls, jobject iaObj) |
|
762 |
{ |
|
763 |
netif *ifList, *curr; |
|
16870 | 764 |
jint addr = getInetAddress_addr(env, iaObj); |
2 | 765 |
jobject netifObj = NULL; |
766 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
767 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
768 |
if (ipv6_available()) { |
2 | 769 |
return Java_java_net_NetworkInterface_getByInetAddress0_XP (env, cls, iaObj); |
770 |
} |
|
771 |
||
772 |
/* get the list of interfaces */ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
773 |
if (enumInterfaces(env, &ifList) < 0) { |
2 | 774 |
return NULL; |
775 |
} |
|
776 |
||
777 |
/* |
|
778 |
* Enumerate the addresses on each interface until we find a |
|
779 |
* matching address. |
|
780 |
*/ |
|
781 |
curr = ifList; |
|
782 |
while (curr != NULL) { |
|
783 |
int count; |
|
784 |
netaddr *addrList; |
|
785 |
netaddr *addrP; |
|
786 |
||
787 |
/* enumerate the addresses on this interface */ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
788 |
count = enumAddresses_win(env, curr, &addrList); |
2 | 789 |
if (count < 0) { |
790 |
free_netif(ifList); |
|
791 |
return NULL; |
|
792 |
} |
|
793 |
||
794 |
/* iterate through each address */ |
|
795 |
addrP = addrList; |
|
796 |
||
797 |
while (addrP != NULL) { |
|
798 |
if ((unsigned long)addr == ntohl(addrP->addr.him4.sin_addr.s_addr)) { |
|
799 |
break; |
|
800 |
} |
|
801 |
addrP = addrP->next; |
|
802 |
} |
|
803 |
||
804 |
/* |
|
805 |
* Address matched so create NetworkInterface for this interface |
|
806 |
* and address list. |
|
807 |
*/ |
|
808 |
if (addrP != NULL) { |
|
809 |
/* createNetworkInterface will free addrList */ |
|
810 |
netifObj = createNetworkInterface(env, curr, count, addrList); |
|
811 |
break; |
|
812 |
} |
|
813 |
||
814 |
/* on next interface */ |
|
815 |
curr = curr->next; |
|
816 |
} |
|
817 |
||
818 |
/* release the interface list */ |
|
819 |
free_netif(ifList); |
|
820 |
||
821 |
return netifObj; |
|
822 |
} |
|
823 |
||
824 |
/* |
|
825 |
* Class: java_net_NetworkInterface |
|
826 |
* Method: getAll |
|
827 |
* Signature: ()[Ljava/net/NetworkInterface; |
|
828 |
*/ |
|
829 |
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll |
|
830 |
(JNIEnv *env, jclass cls) |
|
831 |
{ |
|
832 |
int count; |
|
833 |
netif *ifList, *curr; |
|
834 |
jobjectArray netIFArr; |
|
835 |
jint arr_index; |
|
836 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
837 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
838 |
if (ipv6_available()) { |
2 | 839 |
return Java_java_net_NetworkInterface_getAll_XP (env, cls); |
840 |
} |
|
841 |
||
842 |
/* |
|
843 |
* Get list of interfaces |
|
844 |
*/ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
845 |
count = enumInterfaces(env, &ifList); |
2 | 846 |
if (count < 0) { |
847 |
return NULL; |
|
848 |
} |
|
849 |
||
850 |
/* allocate a NetworkInterface array */ |
|
851 |
netIFArr = (*env)->NewObjectArray(env, count, cls, NULL); |
|
852 |
if (netIFArr == NULL) { |
|
853 |
return NULL; |
|
854 |
} |
|
855 |
||
856 |
/* |
|
857 |
* Iterate through the interfaces, create a NetworkInterface instance |
|
858 |
* for each array element and populate the object. |
|
859 |
*/ |
|
860 |
curr = ifList; |
|
861 |
arr_index = 0; |
|
862 |
while (curr != NULL) { |
|
863 |
jobject netifObj; |
|
864 |
||
865 |
netifObj = createNetworkInterface(env, curr, -1, NULL); |
|
866 |
if (netifObj == NULL) { |
|
867 |
return NULL; |
|
868 |
} |
|
869 |
||
870 |
/* put the NetworkInterface into the array */ |
|
871 |
(*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj); |
|
872 |
||
873 |
curr = curr->next; |
|
874 |
} |
|
875 |
||
876 |
/* release the interface list */ |
|
877 |
free_netif(ifList); |
|
878 |
||
879 |
return netIFArr; |
|
880 |
} |
|
881 |
||
882 |
/* |
|
883 |
* Class: java_net_NetworkInterface |
|
884 |
* Method: isUp0 |
|
885 |
* Signature: (Ljava/lang/String;)Z |
|
886 |
*/ |
|
887 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0 |
|
888 |
(JNIEnv *env, jclass cls, jstring name, jint index) { |
|
889 |
jboolean ret = JNI_FALSE; |
|
890 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
891 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
892 |
if (ipv6_available()) { |
2 | 893 |
return Java_java_net_NetworkInterface_isUp0_XP(env, cls, name, index); |
894 |
} else { |
|
895 |
MIB_IFROW *ifRowP; |
|
896 |
ifRowP = getIF(index); |
|
897 |
if (ifRowP != NULL) { |
|
19866
f5e8a8275078
6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
17193
diff
changeset
|
898 |
ret = ifRowP->dwAdminStatus == MIB_IF_ADMIN_STATUS_UP && |
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
899 |
(ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL || |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
900 |
ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED); |
2 | 901 |
free(ifRowP); |
902 |
} |
|
903 |
} |
|
904 |
return ret; |
|
905 |
} |
|
906 |
||
907 |
/* |
|
908 |
* Class: java_net_NetworkInterface |
|
909 |
* Method: isP2P0 |
|
910 |
* Signature: (Ljava/lang/String;I)Z |
|
911 |
*/ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
912 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0 |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
913 |
(JNIEnv *env, jclass cls, jstring name, jint index) { |
2 | 914 |
MIB_IFROW *ifRowP; |
915 |
jboolean ret = JNI_FALSE; |
|
916 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
917 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
918 |
if (ipv6_available()) { |
2 | 919 |
return Java_java_net_NetworkInterface_isP2P0_XP(env, cls, name, index); |
920 |
} else { |
|
921 |
ifRowP = getIF(index); |
|
922 |
if (ifRowP != NULL) { |
|
923 |
switch(ifRowP->dwType) { |
|
924 |
case MIB_IF_TYPE_PPP: |
|
925 |
case MIB_IF_TYPE_SLIP: |
|
926 |
ret = JNI_TRUE; |
|
927 |
break; |
|
928 |
} |
|
929 |
free(ifRowP); |
|
930 |
} |
|
931 |
} |
|
932 |
return ret; |
|
933 |
} |
|
934 |
||
935 |
/* |
|
936 |
* Class: java_net_NetworkInterface |
|
937 |
* Method: isLoopback0 |
|
938 |
* Signature: (Ljava/lang/String;I)Z |
|
939 |
*/ |
|
940 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0 |
|
941 |
(JNIEnv *env, jclass cls, jstring name, jint index) { |
|
942 |
MIB_IFROW *ifRowP; |
|
943 |
jboolean ret = JNI_FALSE; |
|
944 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
945 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
946 |
if (ipv6_available()) { |
2 | 947 |
return Java_java_net_NetworkInterface_isLoopback0_XP(env, cls, name, index); |
948 |
} else { |
|
949 |
ifRowP = getIF(index); |
|
950 |
if (ifRowP != NULL) { |
|
951 |
if (ifRowP->dwType == MIB_IF_TYPE_LOOPBACK) |
|
952 |
ret = JNI_TRUE; |
|
953 |
free(ifRowP); |
|
954 |
} |
|
955 |
return ret; |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
/* |
|
960 |
* Class: java_net_NetworkInterface |
|
961 |
* Method: supportsMulticast0 |
|
962 |
* Signature: (Ljava/lang/String;I)Z |
|
963 |
*/ |
|
964 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0 |
|
965 |
(JNIEnv *env, jclass cls, jstring name, jint index) { |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
966 |
return Java_java_net_NetworkInterface_supportsMulticast0_XP(env, cls, |
2 | 967 |
name, index); |
968 |
} |
|
969 |
||
970 |
/* |
|
971 |
* Class: java_net_NetworkInterface |
|
972 |
* Method: getMacAddr0 |
|
973 |
* Signature: ([bLjava/lang/String;I)[b |
|
974 |
*/ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
975 |
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0 |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
976 |
(JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) { |
2 | 977 |
jbyteArray ret = NULL; |
978 |
int len; |
|
979 |
MIB_IFROW *ifRowP; |
|
980 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
981 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
982 |
if (ipv6_available()) { |
2 | 983 |
return Java_java_net_NetworkInterface_getMacAddr0_XP(env, class, name, index); |
984 |
} else { |
|
985 |
ifRowP = getIF(index); |
|
986 |
if (ifRowP != NULL) { |
|
987 |
switch(ifRowP->dwType) { |
|
988 |
case MIB_IF_TYPE_ETHERNET: |
|
989 |
case MIB_IF_TYPE_TOKENRING: |
|
990 |
case MIB_IF_TYPE_FDDI: |
|
12542
31190502e9e3
7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents:
10417
diff
changeset
|
991 |
case IF_TYPE_IEEE80211: |
2 | 992 |
len = ifRowP->dwPhysAddrLen; |
26595
1f96f8175e05
8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents:
25859
diff
changeset
|
993 |
if (len > 0) { |
1f96f8175e05
8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents:
25859
diff
changeset
|
994 |
ret = (*env)->NewByteArray(env, len); |
1f96f8175e05
8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents:
25859
diff
changeset
|
995 |
if (!IS_NULL(ret)) { |
1f96f8175e05
8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents:
25859
diff
changeset
|
996 |
(*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) ifRowP->bPhysAddr); |
1f96f8175e05
8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents:
25859
diff
changeset
|
997 |
} |
2 | 998 |
} |
999 |
break; |
|
1000 |
} |
|
1001 |
free(ifRowP); |
|
1002 |
} |
|
1003 |
return ret; |
|
1004 |
} |
|
1005 |
} |
|
1006 |
||
1007 |
/* |
|
1008 |
* Class: java_net_NetworkInterface |
|
1009 |
* Method: getMTU0 |
|
1010 |
* Signature: ([bLjava/lang/String;I)I |
|
1011 |
*/ |
|
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
1012 |
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0 |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
1013 |
(JNIEnv *env, jclass class, jstring name, jint index) { |
2 | 1014 |
jint ret = -1; |
1015 |
MIB_IFROW *ifRowP; |
|
1016 |
||
9003
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
1017 |
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack |
e1b0f0099915
7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents:
5506
diff
changeset
|
1018 |
if (ipv6_available()) { |
2 | 1019 |
return Java_java_net_NetworkInterface_getMTU0_XP(env, class, name, index); |
1020 |
} else { |
|
1021 |
ifRowP = getIF(index); |
|
1022 |
if (ifRowP != NULL) { |
|
1023 |
ret = ifRowP->dwMtu; |
|
1024 |
free(ifRowP); |
|
1025 |
} |
|
1026 |
return ret; |
|
1027 |
} |
|
1028 |
} |