equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2013, 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 |
80 static int getAdapters (JNIEnv *env, IP_ADAPTER_ADDRESSES **adapters) { |
80 static int getAdapters (JNIEnv *env, IP_ADAPTER_ADDRESSES **adapters) { |
81 DWORD ret, flags; |
81 DWORD ret, flags; |
82 IP_ADAPTER_ADDRESSES *adapterInfo; |
82 IP_ADAPTER_ADDRESSES *adapterInfo; |
83 ULONG len; |
83 ULONG len; |
84 adapterInfo = (IP_ADAPTER_ADDRESSES *)malloc (bufsize); |
84 adapterInfo = (IP_ADAPTER_ADDRESSES *)malloc (bufsize); |
85 |
|
86 if (adapterInfo == NULL) { |
85 if (adapterInfo == NULL) { |
87 JNU_ThrowByName(env, "java/lang/OutOfMemoryError", "Native heap allocation failure"); |
86 JNU_ThrowByName(env, "java/lang/OutOfMemoryError", "Native heap allocation failure"); |
88 return -1; |
87 return -1; |
89 } |
88 } |
90 |
89 |
158 return NULL; |
157 return NULL; |
159 } |
158 } |
160 ptr = adapterInfo; |
159 ptr = adapterInfo; |
161 ret = NULL; |
160 ret = NULL; |
162 while (ptr != NULL) { |
161 while (ptr != NULL) { |
163 // IPv4 interface |
162 // in theory the IPv4 index and the IPv6 index can be the same |
164 if (ptr->Ipv6IfIndex == index) { |
163 // where an interface is enabled for v4 and v6 |
|
164 // IfIndex == 0 IPv4 not available on this interface |
|
165 // Ipv6IfIndex == 0 IPv6 not available on this interface |
|
166 if (((ptr->IfIndex != 0)&&(ptr->IfIndex == index)) || |
|
167 ((ptr->Ipv6IfIndex !=0) && (ptr->Ipv6IfIndex == index))) { |
165 ret = (IP_ADAPTER_ADDRESSES *) malloc(sizeof(IP_ADAPTER_ADDRESSES)); |
168 ret = (IP_ADAPTER_ADDRESSES *) malloc(sizeof(IP_ADAPTER_ADDRESSES)); |
166 if (ret == NULL) { |
169 if (ret == NULL) { |
167 free(adapterInfo); |
170 free(adapterInfo); |
168 JNU_ThrowByName(env, "java/lang/OutOfMemoryError", "Native heap allocation failure"); |
171 JNU_ThrowByName(env, "java/lang/OutOfMemoryError", "Native heap allocation failure"); |
169 return NULL; |
172 return NULL; |
170 } |
173 } |
171 |
174 |
172 //copy the memory and break out of the while loop. |
175 //copy the memory and break out of the while loop. |
173 memcpy(ret, ptr, sizeof(IP_ADAPTER_ADDRESSES)); |
176 memcpy(ret, ptr, sizeof(IP_ADAPTER_ADDRESSES)); |
174 break; |
177 break; |
|
178 |
175 } |
179 } |
176 ptr=ptr->Next; |
180 ptr=ptr->Next; |
177 } |
181 } |
178 free(adapterInfo); |
182 free(adapterInfo); |
179 return ret; |
183 return ret; |
190 ULONG len=ipinflen, count=0; |
194 ULONG len=ipinflen, count=0; |
191 netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr; |
195 netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr; |
192 int tun=0, net=0; |
196 int tun=0, net=0; |
193 |
197 |
194 *netifPP = NULL; |
198 *netifPP = NULL; |
195 |
|
196 /* |
199 /* |
197 * Get the IPv4 interfaces. This information is the same |
200 * Get the IPv4 interfaces. This information is the same |
198 * as what previous JDK versions would return. |
201 * as what previous JDK versions would return. |
199 */ |
202 */ |
200 |
203 |
262 if (nif->index == index) { |
265 if (nif->index == index) { |
263 /* found the interface entry |
266 /* found the interface entry |
264 * set the index to the IPv6 index and add the |
267 * set the index to the IPv6 index and add the |
265 * IPv6 addresses |
268 * IPv6 addresses |
266 */ |
269 */ |
267 nif->index = ptr->Ipv6IfIndex; |
270 nif->ipv6Index = ptr->Ipv6IfIndex; |
268 c = getAddrsFromAdapter(ptr, &nif->addrs); |
271 c = getAddrsFromAdapter(ptr, &nif->addrs); |
269 nif->naddrs += c; |
272 nif->naddrs += c; |
270 break; |
273 break; |
271 } |
274 } |
272 } |
275 } |
307 goto err; |
310 goto err; |
308 } |
311 } |
309 strcpy (nif->name, newname); |
312 strcpy (nif->name, newname); |
310 wcscpy ((PWCHAR)nif->displayName, ptr->FriendlyName); |
313 wcscpy ((PWCHAR)nif->displayName, ptr->FriendlyName); |
311 nif->dNameIsUnicode = TRUE; |
314 nif->dNameIsUnicode = TRUE; |
|
315 |
|
316 // the java.net.NetworkInterface abstraction only has index |
|
317 // so the Ipv6IfIndex needs to map onto index |
312 nif->index = ptr->Ipv6IfIndex; |
318 nif->index = ptr->Ipv6IfIndex; |
313 nif->ipv6Index = ptr->Ipv6IfIndex; |
319 nif->ipv6Index = ptr->Ipv6IfIndex; |
314 nif->hasIpv6Address = TRUE; |
320 nif->hasIpv6Address = TRUE; |
315 |
321 |
316 last->next = nif; |
322 last->next = nif; |
485 return NULL; |
491 return NULL; |
486 } |
492 } |
487 (*env)->SetObjectField(env, netifObj, ni_nameID, name); |
493 (*env)->SetObjectField(env, netifObj, ni_nameID, name); |
488 (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName); |
494 (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName); |
489 (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index); |
495 (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index); |
490 |
|
491 /* |
496 /* |
492 * Get the IP addresses for this interface if necessary |
497 * Get the IP addresses for this interface if necessary |
493 * Note that 0 is a valid number of addresses. |
498 * Note that 0 is a valid number of addresses. |
494 */ |
499 */ |
495 if (netaddrCount < 0) { |
500 if (netaddrCount < 0) { |