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