equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
31 * Windows implementation of the java.net.NetworkInterface native methods. |
31 * Windows implementation of the java.net.NetworkInterface native methods. |
32 * This module provides the implementations of getAll, getByName, getByIndex, |
32 * This module provides the implementations of getAll, getByName, getByIndex, |
33 * and getByAddress. |
33 * and getByAddress. |
34 */ |
34 */ |
35 |
35 |
|
36 extern int enumAddresses_win_ipaddrtable(JNIEnv *env, netif *netifP, netaddr **netaddrPP, MIB_IPADDRTABLE *tableP); |
36 extern int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP); |
37 extern int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP); |
|
38 extern int lookupIPAddrTable(JNIEnv *env, MIB_IPADDRTABLE **tablePP); |
37 int getAddrsFromAdapter(IP_ADAPTER_ADDRESSES *ptr, netaddr **netaddrPP); |
39 int getAddrsFromAdapter(IP_ADAPTER_ADDRESSES *ptr, netaddr **netaddrPP); |
38 |
40 |
39 #ifdef DEBUG |
41 #ifdef DEBUG |
40 void printnif (netif *nif) { |
42 void printnif (netif *nif) { |
41 #ifdef _WIN64 |
43 #ifdef _WIN64 |
237 /* |
239 /* |
238 */ |
240 */ |
239 int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) |
241 int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) |
240 { |
242 { |
241 DWORD ret; |
243 DWORD ret; |
|
244 MIB_IPADDRTABLE *tableP; |
242 IP_ADAPTER_ADDRESSES *ptr, *adapters=NULL; |
245 IP_ADAPTER_ADDRESSES *ptr, *adapters=NULL; |
243 ULONG len=ipinflen, count=0; |
246 ULONG len=ipinflen, count=0; |
244 netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr; |
247 netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr; |
245 int tun=0, net=0; |
248 int tun=0, net=0; |
246 |
249 |
269 last = nif; |
272 last = nif; |
270 } |
273 } |
271 |
274 |
272 // Retrieve IPv4 addresses with the IP Helper API |
275 // Retrieve IPv4 addresses with the IP Helper API |
273 curr = *netifPP; |
276 curr = *netifPP; |
|
277 ret = lookupIPAddrTable(env, &tableP); |
|
278 if (ret < 0) { |
|
279 return -1; |
|
280 } |
274 while (curr != NULL) { |
281 while (curr != NULL) { |
275 netaddr *netaddrP; |
282 netaddr *netaddrP; |
276 ret = enumAddresses_win(env, curr, &netaddrP); |
283 ret = enumAddresses_win_ipaddrtable(env, curr, &netaddrP, tableP); |
277 if (ret == -1) { |
284 if (ret == -1) { |
|
285 free(tableP); |
278 return -1; |
286 return -1; |
279 } else if (ret == -2) { |
287 } else if (ret == -2) { |
280 if ((*env)->ExceptionCheck(env)) { |
288 if ((*env)->ExceptionCheck(env)) { |
281 (*env)->ExceptionClear(env); |
289 (*env)->ExceptionClear(env); |
282 } |
290 } |
285 curr->addrs = netaddrP; |
293 curr->addrs = netaddrP; |
286 curr->naddrs += ret; |
294 curr->naddrs += ret; |
287 curr = curr->next; |
295 curr = curr->next; |
288 } |
296 } |
289 } |
297 } |
290 |
298 free(tableP); |
291 ret = getAdapters (env, &adapters); |
299 ret = getAdapters (env, &adapters); |
292 if (ret != ERROR_SUCCESS) { |
300 if (ret != ERROR_SUCCESS) { |
293 goto err; |
301 goto err; |
294 } |
302 } |
295 |
303 |