author | michaelm |
Mon, 08 May 2017 14:04:27 +0100 | |
changeset 44927 | d554736d963e |
parent 43100 | a7e3457672c7 |
child 45703 | fc1eb80b198b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
43100 | 2 |
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
25 |
#include <arpa/inet.h> |
2 | 26 |
#include <errno.h> |
27 |
#include <net/if.h> |
|
28 |
#include <net/if_arp.h> |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
29 |
#include <stdlib.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
30 |
#include <string.h> |
2 | 31 |
#include <sys/ioctl.h> |
32 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
33 |
#if defined(_AIX) |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
34 |
#include <netinet/in6_var.h> |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
35 |
#include <sys/ndd_var.h> |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
36 |
#include <sys/kinfo.h> |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
37 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
38 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
39 |
#if defined(__solaris__) |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
40 |
#include <stropts.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
41 |
#include <sys/dlpi.h> |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
42 |
#include <sys/sockio.h> |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
43 |
#endif |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
44 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
45 |
#if defined(_ALLBSD_SOURCE) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
46 |
#include <net/ethernet.h> |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
47 |
#include <net/if_dl.h> |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
48 |
#include <ifaddrs.h> |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
49 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
50 |
|
2 | 51 |
#include "net_util.h" |
52 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
53 |
#include "java_net_InetAddress.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
40741
diff
changeset
|
54 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
55 |
#if defined(__linux__) |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
56 |
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
57 |
#elif defined(__solaris__) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
58 |
#ifndef SIOCGLIFHWADDR |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
59 |
#define SIOCGLIFHWADDR _IOWR('i', 192, struct lifreq) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
60 |
#endif |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
61 |
#define DEV_PREFIX "/dev/" |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
62 |
#endif |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
63 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
64 |
#ifdef LIFNAMSIZ |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
65 |
#define IFNAMESIZE LIFNAMSIZ |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
66 |
#else |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
67 |
#define IFNAMESIZE IFNAMSIZ |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
68 |
#endif |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
69 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
70 |
#define CHECKED_MALLOC3(_pointer, _type, _size) \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
71 |
do { \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
72 |
_pointer = (_type)malloc(_size); \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
73 |
if (_pointer == NULL) { \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
74 |
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
75 |
return ifs; /* return untouched list */ \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
76 |
} \ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
77 |
} while(0) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
78 |
|
2 | 79 |
typedef struct _netaddr { |
80 |
struct sockaddr *addr; |
|
81 |
struct sockaddr *brdcast; |
|
82 |
short mask; |
|
83 |
int family; /* to make searches simple */ |
|
84 |
struct _netaddr *next; |
|
85 |
} netaddr; |
|
86 |
||
87 |
typedef struct _netif { |
|
88 |
char *name; |
|
89 |
int index; |
|
90 |
char virtual; |
|
91 |
netaddr *addr; |
|
92 |
struct _netif *childs; |
|
93 |
struct _netif *next; |
|
94 |
} netif; |
|
95 |
||
96 |
/************************************************************************ |
|
97 |
* NetworkInterface |
|
98 |
*/ |
|
99 |
||
100 |
#include "java_net_NetworkInterface.h" |
|
101 |
||
102 |
/************************************************************************ |
|
103 |
* NetworkInterface |
|
104 |
*/ |
|
105 |
jclass ni_class; |
|
106 |
jfieldID ni_nameID; |
|
107 |
jfieldID ni_indexID; |
|
108 |
jfieldID ni_descID; |
|
109 |
jfieldID ni_addrsID; |
|
110 |
jfieldID ni_bindsID; |
|
111 |
jfieldID ni_virutalID; |
|
112 |
jfieldID ni_childsID; |
|
113 |
jfieldID ni_parentID; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
114 |
jfieldID ni_defaultIndexID; |
2 | 115 |
jmethodID ni_ctrID; |
116 |
||
117 |
static jclass ni_ibcls; |
|
118 |
static jmethodID ni_ibctrID; |
|
119 |
static jfieldID ni_ibaddressID; |
|
120 |
static jfieldID ni_ib4broadcastID; |
|
121 |
static jfieldID ni_ib4maskID; |
|
122 |
||
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
123 |
/** Private methods declarations **/ |
2 | 124 |
static jobject createNetworkInterface(JNIEnv *env, netif *ifs); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
125 |
static int getFlags0(JNIEnv *env, jstring ifname); |
2 | 126 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
127 |
static netif *enumInterfaces(JNIEnv *env); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
128 |
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
129 |
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs); |
2 | 130 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
131 |
static netif *addif(JNIEnv *env, int sock, const char *if_name, netif *ifs, |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
132 |
struct sockaddr *ifr_addrP, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
133 |
struct sockaddr *ifr_broadaddrP, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
134 |
int family, short prefix); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
135 |
static void freeif(netif *ifs); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
136 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
137 |
static int openSocket(JNIEnv *env, int proto); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
138 |
static int openSocketWithFallback(JNIEnv *env, const char *ifname); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
139 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
140 |
static short translateIPv4AddressToPrefix(struct sockaddr_in *addr); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
141 |
static short translateIPv6AddressToPrefix(struct sockaddr_in6 *addr); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
142 |
|
6002
4df5b9bcf842
6967937: Scope id no longer being set after 6931566
chegar
parents:
5969
diff
changeset
|
143 |
static int getIndex(int sock, const char *ifname); |
13564
3571e232ab03
7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
chegar
parents:
13245
diff
changeset
|
144 |
static int getFlags(int sock, const char *ifname, int *flags); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
145 |
static int getMacAddress(JNIEnv *env, const char *ifname, |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
146 |
const struct in_addr *addr, unsigned char *buf); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
147 |
static int getMTU(JNIEnv *env, int sock, const char *ifname); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
148 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
149 |
#if defined(__solaris__) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
150 |
static int getMacFromDevice(JNIEnv *env, const char *ifname, |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
151 |
unsigned char *retbuf); |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
152 |
#endif |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
153 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
154 |
/******************* Java entry points *****************************/ |
2 | 155 |
|
156 |
/* |
|
157 |
* Class: java_net_NetworkInterface |
|
158 |
* Method: init |
|
159 |
* Signature: ()V |
|
160 |
*/ |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
161 |
JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
162 |
(JNIEnv *env, jclass cls) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
163 |
{ |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
164 |
ni_class = (*env)->FindClass(env, "java/net/NetworkInterface"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
165 |
CHECK_NULL(ni_class); |
2 | 166 |
ni_class = (*env)->NewGlobalRef(env, ni_class); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
167 |
CHECK_NULL(ni_class); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
168 |
ni_nameID = (*env)->GetFieldID(env, ni_class, "name", "Ljava/lang/String;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
169 |
CHECK_NULL(ni_nameID); |
2 | 170 |
ni_indexID = (*env)->GetFieldID(env, ni_class, "index", "I"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
171 |
CHECK_NULL(ni_indexID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
172 |
ni_addrsID = (*env)->GetFieldID(env, ni_class, "addrs", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
173 |
"[Ljava/net/InetAddress;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
174 |
CHECK_NULL(ni_addrsID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
175 |
ni_bindsID = (*env)->GetFieldID(env, ni_class, "bindings", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
176 |
"[Ljava/net/InterfaceAddress;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
177 |
CHECK_NULL(ni_bindsID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
178 |
ni_descID = (*env)->GetFieldID(env, ni_class, "displayName", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
179 |
"Ljava/lang/String;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
180 |
CHECK_NULL(ni_descID); |
2 | 181 |
ni_virutalID = (*env)->GetFieldID(env, ni_class, "virtual", "Z"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
182 |
CHECK_NULL(ni_virutalID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
183 |
ni_childsID = (*env)->GetFieldID(env, ni_class, "childs", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
184 |
"[Ljava/net/NetworkInterface;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
185 |
CHECK_NULL(ni_childsID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
186 |
ni_parentID = (*env)->GetFieldID(env, ni_class, "parent", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
187 |
"Ljava/net/NetworkInterface;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
188 |
CHECK_NULL(ni_parentID); |
2 | 189 |
ni_ctrID = (*env)->GetMethodID(env, ni_class, "<init>", "()V"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
190 |
CHECK_NULL(ni_ctrID); |
2 | 191 |
ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
192 |
CHECK_NULL(ni_ibcls); |
2 | 193 |
ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
194 |
CHECK_NULL(ni_ibcls); |
2 | 195 |
ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
196 |
CHECK_NULL(ni_ibctrID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
197 |
ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
198 |
"Ljava/net/InetAddress;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
199 |
CHECK_NULL(ni_ibaddressID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
200 |
ni_ib4broadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
201 |
"Ljava/net/Inet4Address;"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
202 |
CHECK_NULL(ni_ib4broadcastID); |
2 | 203 |
ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S"); |
21409
246ccfb4a0f0
8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents:
20848
diff
changeset
|
204 |
CHECK_NULL(ni_ib4maskID); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
205 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
206 |
"I"); |
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22605
diff
changeset
|
207 |
CHECK_NULL(ni_defaultIndexID); |
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22605
diff
changeset
|
208 |
initInetAddressIDs(env); |
2 | 209 |
} |
210 |
||
211 |
/* |
|
212 |
* Class: java_net_NetworkInterface |
|
213 |
* Method: getByName0 |
|
214 |
* Signature: (Ljava/lang/String;)Ljava/net/NetworkInterface; |
|
215 |
*/ |
|
216 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
217 |
(JNIEnv *env, jclass cls, jstring name) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
218 |
{ |
2 | 219 |
netif *ifs, *curr; |
220 |
jboolean isCopy; |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
221 |
const char* name_utf; |
42945
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
222 |
char *colonP; |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
223 |
char searchName[IFNAMESIZE]; |
2 | 224 |
jobject obj = NULL; |
225 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
226 |
if (name != NULL) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
227 |
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
228 |
} else { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
229 |
JNU_ThrowNullPointerException(env, "network interface name is NULL"); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
230 |
return NULL; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
231 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
232 |
|
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
233 |
if (name_utf == NULL) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
234 |
if (!(*env)->ExceptionCheck(env)) |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
235 |
JNU_ThrowOutOfMemoryError(env, NULL); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
236 |
return NULL; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
237 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
238 |
|
2 | 239 |
ifs = enumInterfaces(env); |
240 |
if (ifs == NULL) { |
|
241 |
return NULL; |
|
242 |
} |
|
243 |
||
42945
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
244 |
// search the list of interfaces based on name, |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
245 |
// if it is virtual sub interface search with parent first. |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
246 |
strncpy(searchName, name_utf, IFNAMESIZE); |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
247 |
searchName[IFNAMESIZE - 1] = '\0'; |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
248 |
colonP = strchr(searchName, ':'); |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
249 |
if (colonP != NULL) { |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
250 |
*colonP = '\0'; |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
251 |
} |
2 | 252 |
curr = ifs; |
253 |
while (curr != NULL) { |
|
42945
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
254 |
if (strcmp(searchName, curr->name) == 0) { |
2 | 255 |
break; |
256 |
} |
|
257 |
curr = curr->next; |
|
258 |
} |
|
259 |
||
42945
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
260 |
// search the child list |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
261 |
if (colonP != NULL && curr != NULL) { |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
262 |
curr = curr->childs; |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
263 |
while (curr != NULL) { |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
264 |
if (strcmp(name_utf, curr->name) == 0) { |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
265 |
break; |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
266 |
} |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
267 |
curr = curr->next; |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
268 |
} |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
269 |
} |
1a9931e1c0f5
8168840: InetAddress.getByName() throws java.net.UnknownHostException no such interface when used with virtual interfaces on Solaris
vtewari
parents:
41834
diff
changeset
|
270 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
271 |
// if found create a NetworkInterface |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
272 |
if (curr != NULL) { |
2 | 273 |
obj = createNetworkInterface(env, curr); |
274 |
} |
|
275 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
276 |
// release the UTF string and interface list |
2 | 277 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
278 |
freeif(ifs); |
|
279 |
||
280 |
return obj; |
|
281 |
} |
|
282 |
||
283 |
/* |
|
284 |
* Class: java_net_NetworkInterface |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
910
diff
changeset
|
285 |
* Method: getByIndex0 |
2 | 286 |
* Signature: (Ljava/lang/String;)Ljava/net/NetworkInterface; |
287 |
*/ |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
910
diff
changeset
|
288 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0 |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
289 |
(JNIEnv *env, jclass cls, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
290 |
{ |
2 | 291 |
netif *ifs, *curr; |
292 |
jobject obj = NULL; |
|
293 |
||
294 |
if (index <= 0) { |
|
295 |
return NULL; |
|
296 |
} |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
297 |
|
2 | 298 |
ifs = enumInterfaces(env); |
299 |
if (ifs == NULL) { |
|
300 |
return NULL; |
|
301 |
} |
|
302 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
303 |
// search the list of interfaces based on index |
2 | 304 |
curr = ifs; |
305 |
while (curr != NULL) { |
|
306 |
if (index == curr->index) { |
|
307 |
break; |
|
308 |
} |
|
309 |
curr = curr->next; |
|
310 |
} |
|
311 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
312 |
// if found create a NetworkInterface |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
313 |
if (curr != NULL) { |
2 | 314 |
obj = createNetworkInterface(env, curr); |
315 |
} |
|
316 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
317 |
// release the interface list |
2 | 318 |
freeif(ifs); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
319 |
|
2 | 320 |
return obj; |
321 |
} |
|
322 |
||
323 |
/* |
|
324 |
* Class: java_net_NetworkInterface |
|
325 |
* Method: getByInetAddress0 |
|
326 |
* Signature: (Ljava/net/InetAddress;)Ljava/net/NetworkInterface; |
|
327 |
*/ |
|
328 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
329 |
(JNIEnv *env, jclass cls, jobject iaObj) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
330 |
{ |
2 | 331 |
netif *ifs, *curr; |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
332 |
int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ? |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
333 |
AF_INET : AF_INET6; |
2 | 334 |
jobject obj = NULL; |
335 |
jboolean match = JNI_FALSE; |
|
336 |
||
337 |
ifs = enumInterfaces(env); |
|
338 |
if (ifs == NULL) { |
|
339 |
return NULL; |
|
340 |
} |
|
341 |
||
342 |
curr = ifs; |
|
343 |
while (curr != NULL) { |
|
344 |
netaddr *addrP = curr->addr; |
|
345 |
||
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
346 |
// iterate through each address on the interface |
2 | 347 |
while (addrP != NULL) { |
348 |
||
349 |
if (family == addrP->family) { |
|
350 |
if (family == AF_INET) { |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
351 |
int address1 = htonl( |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
352 |
((struct sockaddr_in *)addrP->addr)->sin_addr.s_addr); |
16870 | 353 |
int address2 = getInetAddress_addr(env, iaObj); |
2 | 354 |
|
355 |
if (address1 == address2) { |
|
356 |
match = JNI_TRUE; |
|
357 |
break; |
|
358 |
} |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
359 |
} else if (family == AF_INET6) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
360 |
jbyte *bytes = (jbyte *)&( |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
361 |
((struct sockaddr_in6*)addrP->addr)->sin6_addr); |
2 | 362 |
jbyte caddr[16]; |
363 |
int i; |
|
44927 | 364 |
unsigned int scopeid; |
20821 | 365 |
getInet6Address_ipaddress(env, iaObj, (char *)caddr); |
44927 | 366 |
scopeid = (unsigned int)getInet6Address_scopeid(env, iaObj); |
367 |
if (scopeid != 0 && scopeid != ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id) |
|
368 |
break; |
|
2 | 369 |
i = 0; |
370 |
while (i < 16) { |
|
371 |
if (caddr[i] != bytes[i]) { |
|
372 |
break; |
|
373 |
} |
|
374 |
i++; |
|
375 |
} |
|
376 |
if (i >= 16) { |
|
377 |
match = JNI_TRUE; |
|
378 |
break; |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
if (match) { |
|
384 |
break; |
|
385 |
} |
|
386 |
addrP = addrP->next; |
|
387 |
} |
|
388 |
||
389 |
if (match) { |
|
390 |
break; |
|
391 |
} |
|
392 |
curr = curr->next; |
|
393 |
} |
|
394 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
395 |
// if found create a NetworkInterface |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
396 |
if (match) { |
2 | 397 |
obj = createNetworkInterface(env, curr); |
398 |
} |
|
399 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
400 |
// release the interface list |
2 | 401 |
freeif(ifs); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
402 |
|
2 | 403 |
return obj; |
404 |
} |
|
405 |
||
406 |
/* |
|
407 |
* Class: java_net_NetworkInterface |
|
408 |
* Method: getAll |
|
409 |
* Signature: ()[Ljava/net/NetworkInterface; |
|
410 |
*/ |
|
411 |
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
412 |
(JNIEnv *env, jclass cls) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
413 |
{ |
2 | 414 |
netif *ifs, *curr; |
415 |
jobjectArray netIFArr; |
|
416 |
jint arr_index, ifCount; |
|
417 |
||
418 |
ifs = enumInterfaces(env); |
|
419 |
if (ifs == NULL) { |
|
420 |
return NULL; |
|
421 |
} |
|
422 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
423 |
// count the interfaces |
2 | 424 |
ifCount = 0; |
425 |
curr = ifs; |
|
426 |
while (curr != NULL) { |
|
427 |
ifCount++; |
|
428 |
curr = curr->next; |
|
429 |
} |
|
430 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
431 |
// allocate a NetworkInterface array |
2 | 432 |
netIFArr = (*env)->NewObjectArray(env, ifCount, cls, NULL); |
433 |
if (netIFArr == NULL) { |
|
434 |
freeif(ifs); |
|
435 |
return NULL; |
|
436 |
} |
|
437 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
438 |
// iterate through the interfaces, create a NetworkInterface instance |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
439 |
// for each array element and populate the object |
2 | 440 |
curr = ifs; |
441 |
arr_index = 0; |
|
442 |
while (curr != NULL) { |
|
443 |
jobject netifObj; |
|
444 |
||
445 |
netifObj = createNetworkInterface(env, curr); |
|
446 |
if (netifObj == NULL) { |
|
447 |
freeif(ifs); |
|
448 |
return NULL; |
|
449 |
} |
|
450 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
451 |
// put the NetworkInterface into the array |
2 | 452 |
(*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj); |
453 |
||
454 |
curr = curr->next; |
|
455 |
} |
|
456 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
457 |
// release the interface list |
2 | 458 |
freeif(ifs); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
459 |
|
2 | 460 |
return netIFArr; |
461 |
} |
|
462 |
||
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
463 |
/* |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
464 |
* Class: java_net_NetworkInterface |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
465 |
* Method: isUp0 |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
466 |
* Signature: (Ljava/lang/String;I)Z |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
467 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
468 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0 |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
469 |
(JNIEnv *env, jclass cls, jstring name, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
470 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
471 |
int ret = getFlags0(env, name); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
472 |
return ((ret & IFF_UP) && (ret & IFF_RUNNING)) ? JNI_TRUE : JNI_FALSE; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
473 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
474 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
475 |
/* |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
476 |
* Class: java_net_NetworkInterface |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
477 |
* Method: isP2P0 |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
478 |
* Signature: (Ljava/lang/String;I)Z |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
479 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
480 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0 |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
481 |
(JNIEnv *env, jclass cls, jstring name, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
482 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
483 |
int ret = getFlags0(env, name); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
484 |
return (ret & IFF_POINTOPOINT) ? JNI_TRUE : JNI_FALSE; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
485 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
486 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
487 |
/* |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
488 |
* Class: java_net_NetworkInterface |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
489 |
* Method: isLoopback0 |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
490 |
* Signature: (Ljava/lang/String;I)Z |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
491 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
492 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0 |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
493 |
(JNIEnv *env, jclass cls, jstring name, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
494 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
495 |
int ret = getFlags0(env, name); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
496 |
return (ret & IFF_LOOPBACK) ? JNI_TRUE : JNI_FALSE; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
497 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
498 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
499 |
/* |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
500 |
* Class: java_net_NetworkInterface |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
501 |
* Method: supportsMulticast0 |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
502 |
* Signature: (Ljava/lang/String;I)Z |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
503 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
504 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0 |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
505 |
(JNIEnv *env, jclass cls, jstring name, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
506 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
507 |
int ret = getFlags0(env, name); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
508 |
return (ret & IFF_MULTICAST) ? JNI_TRUE : JNI_FALSE; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
509 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
510 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
511 |
/* |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
512 |
* Class: java_net_NetworkInterface |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
513 |
* Method: getMacAddr0 |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
514 |
* Signature: ([bLjava/lang/String;I)[b |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
515 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
516 |
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0 |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
517 |
(JNIEnv *env, jclass cls, jbyteArray addrArray, jstring name, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
518 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
519 |
jint addr; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
520 |
jbyte caddr[4]; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
521 |
struct in_addr iaddr; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
522 |
jbyteArray ret = NULL; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
523 |
unsigned char mac[16]; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
524 |
int len; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
525 |
jboolean isCopy; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
526 |
const char *name_utf; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
527 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
528 |
if (name != NULL) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
529 |
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
530 |
} else { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
531 |
JNU_ThrowNullPointerException(env, "network interface name is NULL"); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
532 |
return NULL; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
533 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
534 |
|
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
535 |
if (name_utf == NULL) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
536 |
if (!(*env)->ExceptionCheck(env)) |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
537 |
JNU_ThrowOutOfMemoryError(env, NULL); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
538 |
return NULL; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
539 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
540 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
541 |
if (!IS_NULL(addrArray)) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
542 |
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
543 |
addr = ((caddr[0]<<24) & 0xff000000); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
544 |
addr |= ((caddr[1] <<16) & 0xff0000); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
545 |
addr |= ((caddr[2] <<8) & 0xff00); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
546 |
addr |= (caddr[3] & 0xff); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
547 |
iaddr.s_addr = htonl(addr); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
548 |
len = getMacAddress(env, name_utf, &iaddr, mac); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
549 |
} else { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
550 |
len = getMacAddress(env, name_utf, NULL, mac); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
551 |
} |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
552 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
553 |
if (len > 0) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
554 |
ret = (*env)->NewByteArray(env, len); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
555 |
if (!IS_NULL(ret)) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
556 |
(*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *)(mac)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
557 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
558 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
559 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
560 |
// release the UTF string and interface list |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
561 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
562 |
|
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
563 |
return ret; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
564 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
565 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
566 |
/* |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
567 |
* Class: java_net_NetworkInterface |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
568 |
* Method: getMTU0 |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
569 |
* Signature: ([bLjava/lang/String;I)I |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
570 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
571 |
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0 |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
572 |
(JNIEnv *env, jclass cls, jstring name, jint index) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
573 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
574 |
jboolean isCopy; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
575 |
int sock, ret = -1; |
28549 | 576 |
const char* name_utf = NULL; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
577 |
|
28549 | 578 |
if (name != NULL) { |
579 |
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy); |
|
580 |
} else { |
|
581 |
JNU_ThrowNullPointerException(env, "network interface name is NULL"); |
|
582 |
return ret; |
|
583 |
} |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
584 |
|
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
585 |
if (name_utf == NULL) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
586 |
if (!(*env)->ExceptionCheck(env)) |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
587 |
JNU_ThrowOutOfMemoryError(env, NULL); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
588 |
return ret; |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
589 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
590 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
591 |
if ((sock = openSocketWithFallback(env, name_utf)) < 0) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
592 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
593 |
return JNI_FALSE; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
594 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
595 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
596 |
ret = getMTU(env, sock, name_utf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
597 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
598 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
599 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
600 |
close(sock); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
601 |
return ret; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
602 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
603 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
604 |
/*** Private methods definitions ****/ |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
605 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
606 |
static int getFlags0(JNIEnv *env, jstring name) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
607 |
jboolean isCopy; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
608 |
int ret, sock, flags = 0; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
609 |
const char *name_utf; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
610 |
|
28549 | 611 |
if (name != NULL) { |
612 |
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy); |
|
613 |
} else { |
|
614 |
JNU_ThrowNullPointerException(env, "network interface name is NULL"); |
|
615 |
return -1; |
|
616 |
} |
|
617 |
||
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
618 |
if (name_utf == NULL) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
619 |
if (!(*env)->ExceptionCheck(env)) |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
620 |
JNU_ThrowOutOfMemoryError(env, NULL); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
621 |
return -1; |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
622 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
623 |
if ((sock = openSocketWithFallback(env, name_utf)) < 0) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
624 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
19411
b8942467963c
8022584: Memory leak in some NetworkInterface methods
igerasim
parents:
17921
diff
changeset
|
625 |
return -1; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
626 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
627 |
|
13564
3571e232ab03
7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
chegar
parents:
13245
diff
changeset
|
628 |
ret = getFlags(sock, name_utf, &flags); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
629 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
630 |
close(sock); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
631 |
(*env)->ReleaseStringUTFChars(env, name, name_utf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
632 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
633 |
if (ret < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
634 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
635 |
(env, JNU_JAVANETPKG "SocketException", "getFlags() failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
636 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
637 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
638 |
|
13564
3571e232ab03
7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
chegar
parents:
13245
diff
changeset
|
639 |
return flags; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
640 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
641 |
|
2 | 642 |
/* |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
643 |
* Creates a NetworkInterface object, populates the name, the index, and |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
644 |
* populates the InetAddress array based on the IP addresses for this |
2 | 645 |
* interface. |
646 |
*/ |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
647 |
static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { |
2 | 648 |
jobject netifObj; |
649 |
jobject name; |
|
650 |
jobjectArray addrArr; |
|
651 |
jobjectArray bindArr; |
|
652 |
jobjectArray childArr; |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
653 |
netaddr *addrs; |
2 | 654 |
jint addr_index, addr_count, bind_index; |
655 |
jint child_count, child_index; |
|
656 |
netaddr *addrP; |
|
657 |
netif *childP; |
|
658 |
jobject tmp; |
|
659 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
660 |
// create a NetworkInterface object and populate it |
2 | 661 |
netifObj = (*env)->NewObject(env, ni_class, ni_ctrID); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
662 |
CHECK_NULL_RETURN(netifObj, NULL); |
2 | 663 |
name = (*env)->NewStringUTF(env, ifs->name); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
664 |
CHECK_NULL_RETURN(name, NULL); |
2 | 665 |
(*env)->SetObjectField(env, netifObj, ni_nameID, name); |
666 |
(*env)->SetObjectField(env, netifObj, ni_descID, name); |
|
667 |
(*env)->SetIntField(env, netifObj, ni_indexID, ifs->index); |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
668 |
(*env)->SetBooleanField(env, netifObj, ni_virutalID, |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
669 |
ifs->virtual ? JNI_TRUE : JNI_FALSE); |
2 | 670 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
671 |
// count the number of addresses on this interface |
2 | 672 |
addr_count = 0; |
673 |
addrP = ifs->addr; |
|
674 |
while (addrP != NULL) { |
|
675 |
addr_count++; |
|
676 |
addrP = addrP->next; |
|
677 |
} |
|
678 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
679 |
// create the array of InetAddresses |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
37898
diff
changeset
|
680 |
addrArr = (*env)->NewObjectArray(env, addr_count, ia_class, NULL); |
2 | 681 |
if (addrArr == NULL) { |
682 |
return NULL; |
|
683 |
} |
|
684 |
||
685 |
bindArr = (*env)->NewObjectArray(env, addr_count, ni_ibcls, NULL); |
|
686 |
if (bindArr == NULL) { |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
687 |
return NULL; |
2 | 688 |
} |
689 |
addrP = ifs->addr; |
|
690 |
addr_index = 0; |
|
691 |
bind_index = 0; |
|
692 |
while (addrP != NULL) { |
|
693 |
jobject iaObj = NULL; |
|
694 |
jobject ibObj = NULL; |
|
695 |
||
696 |
if (addrP->family == AF_INET) { |
|
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22605
diff
changeset
|
697 |
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); |
2 | 698 |
if (iaObj) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
699 |
setInetAddress_addr(env, iaObj, htonl( |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
700 |
((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr)); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
701 |
} else { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
702 |
return NULL; |
2 | 703 |
} |
704 |
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); |
|
705 |
if (ibObj) { |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
706 |
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
707 |
if (addrP->brdcast) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
708 |
jobject ia2Obj = NULL; |
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22605
diff
changeset
|
709 |
ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
710 |
if (ia2Obj) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
711 |
setInetAddress_addr(env, ia2Obj, htonl( |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
712 |
((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
713 |
(*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
714 |
} else { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
715 |
return NULL; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
716 |
} |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
717 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
718 |
(*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
719 |
(*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
720 |
} else { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
721 |
return NULL; |
2 | 722 |
} |
723 |
} |
|
724 |
if (addrP->family == AF_INET6) { |
|
725 |
int scope=0; |
|
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22605
diff
changeset
|
726 |
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); |
2 | 727 |
if (iaObj) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
728 |
jboolean ret = setInet6Address_ipaddress(env, iaObj, |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
729 |
(char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr)); |
20821 | 730 |
if (ret == JNI_FALSE) { |
2 | 731 |
return NULL; |
732 |
} |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
733 |
|
2 | 734 |
scope = ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
735 |
|
2 | 736 |
if (scope != 0) { /* zero is default value, no need to set */ |
20821 | 737 |
setInet6Address_scopeid(env, iaObj, scope); |
738 |
setInet6Address_scopeifname(env, iaObj, netifObj); |
|
2 | 739 |
} |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
740 |
} else { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
741 |
return NULL; |
2 | 742 |
} |
743 |
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); |
|
744 |
if (ibObj) { |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
745 |
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
746 |
(*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
747 |
(*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj); |
23563
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
748 |
} else { |
71ed058849d4
8025293: JNI exception pending checks in java.net
msheppar
parents:
23015
diff
changeset
|
749 |
return NULL; |
2 | 750 |
} |
751 |
} |
|
752 |
||
753 |
(*env)->SetObjectArrayElement(env, addrArr, addr_index++, iaObj); |
|
754 |
addrP = addrP->next; |
|
755 |
} |
|
756 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
757 |
// see if there is any virtual interface attached to this one. |
2 | 758 |
child_count = 0; |
759 |
childP = ifs->childs; |
|
760 |
while (childP) { |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
761 |
child_count++; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
762 |
childP = childP->next; |
2 | 763 |
} |
764 |
||
765 |
childArr = (*env)->NewObjectArray(env, child_count, ni_class, NULL); |
|
766 |
if (childArr == NULL) { |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
767 |
return NULL; |
2 | 768 |
} |
769 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
770 |
// create the NetworkInterface instances for the sub-interfaces as well |
2 | 771 |
child_index = 0; |
772 |
childP = ifs->childs; |
|
773 |
while(childP) { |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
774 |
tmp = createNetworkInterface(env, childP); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
775 |
if (tmp == NULL) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
776 |
return NULL; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
777 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
778 |
(*env)->SetObjectField(env, tmp, ni_parentID, netifObj); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
779 |
(*env)->SetObjectArrayElement(env, childArr, child_index++, tmp); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
780 |
childP = childP->next; |
2 | 781 |
} |
782 |
(*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr); |
|
783 |
(*env)->SetObjectField(env, netifObj, ni_bindsID, bindArr); |
|
784 |
(*env)->SetObjectField(env, netifObj, ni_childsID, childArr); |
|
785 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
786 |
// return the NetworkInterface |
2 | 787 |
return netifObj; |
788 |
} |
|
789 |
||
790 |
/* |
|
791 |
* Enumerates all interfaces |
|
792 |
*/ |
|
793 |
static netif *enumInterfaces(JNIEnv *env) { |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
794 |
netif *ifs = NULL; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
795 |
int sock; |
2 | 796 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
797 |
sock = openSocket(env, AF_INET); |
43100 | 798 |
if (sock < 0) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
799 |
return NULL; |
2 | 800 |
} |
801 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
802 |
// enumerate IPv4 addresses |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
803 |
ifs = enumIPv4Interfaces(env, sock, NULL); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
804 |
close(sock); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
805 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
806 |
// return partial list if an exception occurs in the middle of process ??? |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
807 |
if (ifs == NULL && (*env)->ExceptionOccurred(env)) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
808 |
return NULL; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
809 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
810 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
811 |
// If IPv6 is available then enumerate IPv6 addresses. |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
812 |
// User can disable ipv6 explicitly by -Djava.net.preferIPv4Stack=true, |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
813 |
// so we have to call ipv6_available() |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
814 |
if (ipv6_available()) { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
815 |
sock = openSocket(env, AF_INET6); |
43100 | 816 |
if (sock < 0) { |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
817 |
freeif(ifs); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
818 |
return NULL; |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
819 |
} |
2 | 820 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
821 |
ifs = enumIPv6Interfaces(env, sock, ifs); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
822 |
close(sock); |
6108
d5bfa0bc6123
6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents:
6002
diff
changeset
|
823 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
824 |
if ((*env)->ExceptionOccurred(env)) { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
825 |
freeif(ifs); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
826 |
return NULL; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
827 |
} |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
828 |
} |
2 | 829 |
|
830 |
return ifs; |
|
831 |
} |
|
832 |
||
833 |
/* |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
834 |
* Frees an interface list (including any attached addresses). |
2 | 835 |
*/ |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
836 |
static void freeif(netif *ifs) { |
2 | 837 |
netif *currif = ifs; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
838 |
netif *child = NULL; |
2 | 839 |
|
840 |
while (currif != NULL) { |
|
841 |
netaddr *addrP = currif->addr; |
|
842 |
while (addrP != NULL) { |
|
843 |
netaddr *next = addrP->next; |
|
844 |
free(addrP); |
|
845 |
addrP = next; |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
846 |
} |
2 | 847 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
848 |
// don't forget to free the sub-interfaces |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
849 |
if (currif->childs != NULL) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
850 |
freeif(currif->childs); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
851 |
} |
2 | 852 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
853 |
ifs = currif->next; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
854 |
free(currif); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
855 |
currif = ifs; |
2 | 856 |
} |
857 |
} |
|
858 |
||
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
859 |
static netif *addif(JNIEnv *env, int sock, const char *if_name, netif *ifs, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
860 |
struct sockaddr *ifr_addrP, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
861 |
struct sockaddr *ifr_broadaddrP, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
862 |
int family, short prefix) |
17423
1c681c88107c
8013140: Heap corruption with NetworkInterface.getByInetAddress() and long i/f name
khazra
parents:
16870
diff
changeset
|
863 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
864 |
netif *currif = ifs, *parent; |
2 | 865 |
netaddr *addrP; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
866 |
char name[IFNAMESIZE], vname[IFNAMESIZE]; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
867 |
char *name_colonP; |
2 | 868 |
int isVirtual = 0; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
869 |
int addr_size; |
2 | 870 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
871 |
// If the interface name is a logical interface then we remove the unit |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
872 |
// number so that we have the physical interface (eg: hme0:1 -> hme0). |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
873 |
// NetworkInterface currently doesn't have any concept of physical vs. |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
874 |
// logical interfaces. |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
875 |
strncpy(name, if_name, IFNAMESIZE); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
876 |
name[IFNAMESIZE - 1] = '\0'; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
877 |
*vname = 0; |
2 | 878 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
879 |
// Create and populate the netaddr node. If allocation fails |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
880 |
// return an un-updated list. |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
881 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
882 |
// Allocate for addr and brdcast at once |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
883 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
884 |
addr_size = (family == AF_INET) ? sizeof(struct sockaddr_in) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
885 |
: sizeof(struct sockaddr_in6); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
886 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
887 |
CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr) + 2 * addr_size); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
888 |
addrP->addr = (struct sockaddr *)((char *)addrP + sizeof(netaddr)); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
889 |
memcpy(addrP->addr, ifr_addrP, addr_size); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
890 |
|
2 | 891 |
addrP->family = family; |
892 |
addrP->mask = prefix; |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
893 |
addrP->next = 0; |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
894 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
895 |
// for IPv4 add broadcast address |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
896 |
if (family == AF_INET && ifr_broadaddrP != NULL) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
897 |
addrP->brdcast = (struct sockaddr *) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
898 |
((char *)addrP + sizeof(netaddr) + addr_size); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
899 |
memcpy(addrP->brdcast, ifr_broadaddrP, addr_size); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
900 |
} else { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
901 |
addrP->brdcast = NULL; |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
902 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
903 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
904 |
// Deal with virtual interface with colon notation e.g. eth0:1 |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
905 |
name_colonP = strchr(name, ':'); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
906 |
if (name_colonP != NULL) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
907 |
int flags = 0; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
908 |
// This is a virtual interface. If we are able to access the parent |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
909 |
// we need to create a new entry if it doesn't exist yet *and* update |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
910 |
// the 'parent' interface with the new records. |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
911 |
*name_colonP = 0; |
13564
3571e232ab03
7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
chegar
parents:
13245
diff
changeset
|
912 |
if (getFlags(sock, name, &flags) < 0 || flags < 0) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
913 |
// failed to access parent interface do not create parent. |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
914 |
// We are a virtual interface with no parent. |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
915 |
isVirtual = 1; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
916 |
*name_colonP = ':'; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
917 |
} else { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
918 |
// Got access to parent, so create it if necessary. |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
919 |
// Save original name to vname and truncate name by ':' |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
920 |
memcpy(vname, name, sizeof(vname)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
921 |
vname[name_colonP - name] = ':'; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
922 |
} |
2 | 923 |
} |
924 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
925 |
// Check if this is a "new" interface. Use the interface name for |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
926 |
// matching because index isn't supported on Solaris 2.6 & 7. |
2 | 927 |
while (currif != NULL) { |
928 |
if (strcmp(name, currif->name) == 0) { |
|
929 |
break; |
|
930 |
} |
|
931 |
currif = currif->next; |
|
932 |
} |
|
933 |
||
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
934 |
// If "new" then create a netif structure and insert it into the list. |
2 | 935 |
if (currif == NULL) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
936 |
CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
937 |
currif->name = (char *)currif + sizeof(netif); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
938 |
strncpy(currif->name, name, IFNAMESIZE); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
939 |
currif->name[IFNAMESIZE - 1] = '\0'; |
6002
4df5b9bcf842
6967937: Scope id no longer being set after 6931566
chegar
parents:
5969
diff
changeset
|
940 |
currif->index = getIndex(sock, name); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
941 |
currif->addr = NULL; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
942 |
currif->childs = NULL; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
943 |
currif->virtual = isVirtual; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
944 |
currif->next = ifs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
945 |
ifs = currif; |
2 | 946 |
} |
947 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
948 |
// Finally insert the address on the interface |
2 | 949 |
addrP->next = currif->addr; |
950 |
currif->addr = addrP; |
|
951 |
||
952 |
parent = currif; |
|
953 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
954 |
// Deal with the virtual interface now. |
2 | 955 |
if (vname[0]) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
956 |
netaddr *tmpaddr; |
2 | 957 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
958 |
currif = parent->childs; |
2 | 959 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
960 |
while (currif != NULL) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
961 |
if (strcmp(vname, currif->name) == 0) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
962 |
break; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
963 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
964 |
currif = currif->next; |
2 | 965 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
966 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
967 |
if (currif == NULL) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
968 |
CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
969 |
currif->name = (char *)currif + sizeof(netif); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
970 |
strncpy(currif->name, vname, IFNAMESIZE); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
971 |
currif->name[IFNAMESIZE - 1] = '\0'; |
6002
4df5b9bcf842
6967937: Scope id no longer being set after 6931566
chegar
parents:
5969
diff
changeset
|
972 |
currif->index = getIndex(sock, vname); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
973 |
currif->addr = NULL; // Need to duplicate the addr entry? |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
974 |
currif->virtual = 1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
975 |
currif->childs = NULL; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
976 |
currif->next = parent->childs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
977 |
parent->childs = currif; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
978 |
} |
2 | 979 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
980 |
CHECKED_MALLOC3(tmpaddr, netaddr *, sizeof(netaddr) + 2 * addr_size); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
981 |
memcpy(tmpaddr, addrP, sizeof(netaddr)); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
982 |
if (addrP->addr != NULL) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
983 |
tmpaddr->addr = (struct sockaddr *) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
984 |
((char*)tmpaddr + sizeof(netaddr)); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
985 |
memcpy(tmpaddr->addr, addrP->addr, addr_size); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
986 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
987 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
988 |
if (addrP->brdcast != NULL) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
989 |
tmpaddr->brdcast = (struct sockaddr *) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
990 |
((char *)tmpaddr + sizeof(netaddr) + addr_size); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
991 |
memcpy(tmpaddr->brdcast, addrP->brdcast, addr_size); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
992 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
993 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
994 |
tmpaddr->next = currif->addr; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
995 |
currif->addr = tmpaddr; |
2 | 996 |
} |
997 |
||
998 |
return ifs; |
|
999 |
} |
|
1000 |
||
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1001 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1002 |
* Determines the prefix value for an AF_INET subnet address. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1003 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1004 |
static short translateIPv4AddressToPrefix(struct sockaddr_in *addr) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1005 |
short prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1006 |
unsigned int mask = ntohl(addr->sin_addr.s_addr); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1007 |
while (mask) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1008 |
mask <<= 1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1009 |
prefix++; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1010 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1011 |
return prefix; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1012 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1013 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1014 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1015 |
* Determines the prefix value for an AF_INET6 subnet address. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1016 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1017 |
static short translateIPv6AddressToPrefix(struct sockaddr_in6 *addr) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1018 |
short prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1019 |
u_char *addrBytes = (u_char *)&(addr->sin6_addr); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1020 |
unsigned int byte, bit; |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1021 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1022 |
for (byte = 0; byte < sizeof(struct in6_addr); byte++, prefix += 8) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1023 |
if (addrBytes[byte] != 0xff) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1024 |
break; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1025 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1026 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1027 |
if (byte != sizeof(struct in6_addr)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1028 |
for (bit = 7; bit != 0; bit--, prefix++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1029 |
if (!(addrBytes[byte] & (1 << bit))) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1030 |
break; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1031 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1032 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1033 |
for (; bit != 0; bit--) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1034 |
if (addrBytes[byte] & (1 << bit)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1035 |
prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1036 |
break; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1037 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1038 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1039 |
if (prefix > 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1040 |
byte++; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1041 |
for (; byte < sizeof(struct in6_addr); byte++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1042 |
if (addrBytes[byte]) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1043 |
prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1044 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1045 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1046 |
} |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1047 |
} |
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1048 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1049 |
return prefix; |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1050 |
} |
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1051 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1052 |
/* |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1053 |
* Opens a socket for further ioct calls. proto is one of AF_INET or AF_INET6. |
2 | 1054 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1055 |
static int openSocket(JNIEnv *env, int proto) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1056 |
int sock; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1057 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
22956
diff
changeset
|
1058 |
if ((sock = socket(proto, SOCK_DGRAM, 0)) < 0) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1059 |
// If EPROTONOSUPPORT is returned it means we don't have |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1060 |
// support for this proto so don't throw an exception. |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1061 |
if (errno != EPROTONOSUPPORT) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1062 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1063 |
(env, JNU_JAVANETPKG "SocketException", "Socket creation failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1064 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1065 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1066 |
} |
2 | 1067 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1068 |
return sock; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1069 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1070 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1071 |
/** Linux **/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1072 |
#if defined(__linux__) |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1073 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1074 |
/* |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1075 |
* Opens a socket for further ioctl calls. Tries AF_INET socket first and |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1076 |
* if it fails return AF_INET6 socket. |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1077 |
*/ |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1078 |
static int openSocketWithFallback(JNIEnv *env, const char *ifname) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1079 |
int sock; |
2 | 1080 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1081 |
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1082 |
if (errno == EPROTONOSUPPORT) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1083 |
if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1084 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1085 |
(env, JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed"); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1086 |
return -1; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1087 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1088 |
} else { // errno is not NOSUPPORT |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1089 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1090 |
(env, JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed"); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1091 |
return -1; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1092 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1093 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1094 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1095 |
// Linux starting from 2.6.? kernel allows ioctl call with either IPv4 or |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1096 |
// IPv6 socket regardless of type of address of an interface. |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1097 |
return sock; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1098 |
} |
2 | 1099 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1100 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1101 |
* Enumerates and returns all IPv4 interfaces on Linux. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1102 |
*/ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1103 |
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1104 |
struct ifconf ifc; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1105 |
struct ifreq *ifreqP; |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1106 |
char *buf = NULL; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1107 |
unsigned i; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1108 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1109 |
// do a dummy SIOCGIFCONF to determine the buffer size |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1110 |
// SIOCGIFCOUNT doesn't work |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1111 |
ifc.ifc_buf = NULL; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1112 |
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1113 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1114 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFCONF) failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1115 |
return ifs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1116 |
} |
709
4d98e12330e6
6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents:
2
diff
changeset
|
1117 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1118 |
// call SIOCGIFCONF to enumerate the interfaces |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1119 |
CHECKED_MALLOC3(buf, char *, ifc.ifc_len); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1120 |
ifc.ifc_buf = buf; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1121 |
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1122 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1123 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFCONF) failed"); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1124 |
free(buf); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1125 |
return ifs; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1126 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1127 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1128 |
// iterate through each interface |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1129 |
ifreqP = ifc.ifc_req; |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1130 |
for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++, ifreqP++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1131 |
struct sockaddr addr, broadaddr, *broadaddrP = NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1132 |
short prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1133 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1134 |
// ignore non IPv4 addresses |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1135 |
if (ifreqP->ifr_addr.sa_family != AF_INET) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1136 |
continue; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1137 |
} |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1138 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1139 |
// save socket address |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1140 |
memcpy(&addr, &(ifreqP->ifr_addr), sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1141 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1142 |
// determine broadcast address, if applicable |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1143 |
if ((ioctl(sock, SIOCGIFFLAGS, ifreqP) == 0) && |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1144 |
ifreqP->ifr_flags & IFF_BROADCAST) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1145 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1146 |
// restore socket address to ifreqP |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1147 |
memcpy(&(ifreqP->ifr_addr), &addr, sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1148 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1149 |
if (ioctl(sock, SIOCGIFBRDADDR, ifreqP) == 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1150 |
memcpy(&broadaddr, &(ifreqP->ifr_broadaddr), |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1151 |
sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1152 |
broadaddrP = &broadaddr; |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1153 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1154 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1155 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1156 |
// restore socket address to ifreqP |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1157 |
memcpy(&(ifreqP->ifr_addr), &addr, sizeof(struct sockaddr)); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1158 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1159 |
// determine netmask |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1160 |
if (ioctl(sock, SIOCGIFNETMASK, ifreqP) == 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1161 |
prefix = translateIPv4AddressToPrefix( |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1162 |
(struct sockaddr_in *)&(ifreqP->ifr_netmask)); |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1163 |
} |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1164 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1165 |
// add interface to the list |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1166 |
ifs = addif(env, sock, ifreqP->ifr_name, ifs, |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1167 |
&addr, broadaddrP, AF_INET, prefix); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1168 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1169 |
// in case of exception, free interface list and buffer and return NULL |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1170 |
if ((*env)->ExceptionOccurred(env)) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1171 |
free(buf); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1172 |
freeif(ifs); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1173 |
return NULL; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1174 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1175 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1176 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1177 |
// free buffer |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1178 |
free(buf); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1179 |
return ifs; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1180 |
} |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1181 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1182 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1183 |
* Enumerates and returns all IPv6 interfaces on Linux. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1184 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1185 |
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1186 |
FILE *f; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1187 |
char devname[21], addr6p[8][5]; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1188 |
int prefix, scope, dad_status, if_idx; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1189 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1190 |
if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1191 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1192 |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1193 |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1194 |
&if_idx, &prefix, &scope, &dad_status, devname) != EOF) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1195 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1196 |
char addr6[40]; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1197 |
struct sockaddr_in6 addr; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1198 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1199 |
sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1200 |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1201 |
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1202 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1203 |
memset(&addr, 0, sizeof(struct sockaddr_in6)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1204 |
inet_pton(AF_INET6, addr6, (void*)addr.sin6_addr.s6_addr); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1205 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1206 |
// set scope ID to interface index |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1207 |
addr.sin6_scope_id = if_idx; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1208 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1209 |
// add interface to the list |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1210 |
ifs = addif(env, sock, devname, ifs, (struct sockaddr *)&addr, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1211 |
NULL, AF_INET6, (short)prefix); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1212 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1213 |
// if an exception occurred then return the list as is |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1214 |
if ((*env)->ExceptionOccurred(env)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1215 |
break; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1216 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1217 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1218 |
fclose(f); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1219 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1220 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1221 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1222 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1223 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1224 |
* Try to get the interface index. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1225 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1226 |
static int getIndex(int sock, const char *name) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1227 |
struct ifreq if2; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1228 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1229 |
strncpy(if2.ifr_name, name, sizeof(if2.ifr_name) - 1); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1230 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1231 |
if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) < 0) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1232 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1233 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1234 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1235 |
return if2.ifr_ifindex; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1236 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1237 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1238 |
/* |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1239 |
* Gets the Hardware address (usually MAC address) for the named interface. |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1240 |
* On return puts the data in buf, and returns the length, in byte, of the |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1241 |
* MAC address. Returns -1 if there is no hardware address on that interface. |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1242 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1243 |
static int getMacAddress |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1244 |
(JNIEnv *env, const char *ifname, const struct in_addr *addr, |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1245 |
unsigned char *buf) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1246 |
{ |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1247 |
static struct ifreq ifr; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1248 |
int i, sock; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1249 |
|
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1250 |
if ((sock = openSocketWithFallback(env, ifname)) < 0) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1251 |
return -1; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1252 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1253 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1254 |
memset((char *)&ifr, 0, sizeof(ifr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1255 |
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1256 |
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1257 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1258 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFHWADDR) failed"); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1259 |
close(sock); |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1260 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1261 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1262 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1263 |
close(sock); |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1264 |
memcpy(buf, &ifr.ifr_hwaddr.sa_data, IFHWADDRLEN); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1265 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1266 |
// all bytes to 0 means no hardware address |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1267 |
for (i = 0; i < IFHWADDRLEN; i++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1268 |
if (buf[i] != 0) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1269 |
return IFHWADDRLEN; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1270 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1271 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1272 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1273 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1274 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1275 |
static int getMTU(JNIEnv *env, int sock, const char *ifname) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1276 |
struct ifreq if2; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1277 |
memset((char *)&if2, 0, sizeof(if2)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1278 |
strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1279 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1280 |
if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1281 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1282 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFMTU) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1283 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1284 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1285 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1286 |
return if2.ifr_mtu; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1287 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1288 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1289 |
static int getFlags(int sock, const char *ifname, int *flags) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1290 |
struct ifreq if2; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1291 |
memset((char *)&if2, 0, sizeof(if2)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1292 |
strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1293 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1294 |
if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1295 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1296 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1297 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1298 |
if (sizeof(if2.ifr_flags) == sizeof(short)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1299 |
*flags = (if2.ifr_flags & 0xffff); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1300 |
} else { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1301 |
*flags = if2.ifr_flags; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1302 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1303 |
return 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1304 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1305 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1306 |
#endif /* __linux__ */ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1307 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1308 |
/** AIX **/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1309 |
#if defined(_AIX) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1310 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1311 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1312 |
* Opens a socket for further ioctl calls. Tries AF_INET socket first and |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1313 |
* if it fails return AF_INET6 socket. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1314 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1315 |
static int openSocketWithFallback(JNIEnv *env, const char *ifname) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1316 |
int sock; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1317 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1318 |
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1319 |
if (errno == EPROTONOSUPPORT) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1320 |
if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1321 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1322 |
(env, JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1323 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1324 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1325 |
} else { // errno is not NOSUPPORT |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1326 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1327 |
(env, JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1328 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1329 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1330 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1331 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1332 |
return sock; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1333 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1334 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1335 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1336 |
* Enumerates and returns all IPv4 interfaces on AIX. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1337 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1338 |
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1339 |
struct ifconf ifc; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1340 |
struct ifreq *ifreqP; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1341 |
char *buf = NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1342 |
unsigned i; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1343 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1344 |
// call SIOCGSIZIFCONF to get the size of SIOCGIFCONF buffer |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1345 |
if (ioctl(sock, SIOCGSIZIFCONF, &(ifc.ifc_len)) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1346 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1347 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGSIZIFCONF) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1348 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1349 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1350 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1351 |
// call CSIOCGIFCONF instead of SIOCGIFCONF where interface |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1352 |
// records will always have sizeof(struct ifreq) length. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1353 |
// Be aware that only IPv4 data is complete this way. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1354 |
CHECKED_MALLOC3(buf, char *, ifc.ifc_len); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1355 |
ifc.ifc_buf = buf; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1356 |
if (ioctl(sock, CSIOCGIFCONF, (char *)&ifc) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1357 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1358 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(CSIOCGIFCONF) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1359 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1360 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1361 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1362 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1363 |
// iterate through each interface |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1364 |
ifreqP = ifc.ifc_req; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1365 |
for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++, ifreqP++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1366 |
struct sockaddr addr, broadaddr, *broadaddrP = NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1367 |
short prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1368 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1369 |
// ignore non IPv4 addresses |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1370 |
if (ifreqP->ifr_addr.sa_family != AF_INET) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1371 |
continue; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1372 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1373 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1374 |
// save socket address |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1375 |
memcpy(&addr, &(ifreqP->ifr_addr), sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1376 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1377 |
// determine broadcast address, if applicable |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1378 |
if ((ioctl(sock, SIOCGIFFLAGS, ifreqP) == 0) && |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1379 |
ifreqP->ifr_flags & IFF_BROADCAST) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1380 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1381 |
// restore socket address to ifreqP |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1382 |
memcpy(&(ifreqP->ifr_addr), &addr, sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1383 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1384 |
if (ioctl(sock, SIOCGIFBRDADDR, ifreqP) == 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1385 |
memcpy(&broadaddr, &(ifreqP->ifr_broadaddr), |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1386 |
sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1387 |
broadaddrP = &broadaddr; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1388 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1389 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1390 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1391 |
// restore socket address to ifreqP |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1392 |
memcpy(&(ifreqP->ifr_addr), &addr, sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1393 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1394 |
// determine netmask |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1395 |
if (ioctl(sock, SIOCGIFNETMASK, ifreqP) == 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1396 |
prefix = translateIPv4AddressToPrefix( |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1397 |
(struct sockaddr_in *)&(ifreqP->ifr_addr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1398 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1399 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1400 |
// add interface to the list |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1401 |
ifs = addif(env, sock, ifreqP->ifr_name, ifs, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1402 |
&addr, broadaddrP, AF_INET, prefix); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1403 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1404 |
// in case of exception, free interface list and buffer and return NULL |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1405 |
if ((*env)->ExceptionOccurred(env)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1406 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1407 |
freeif(ifs); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1408 |
return NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1409 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1410 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1411 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1412 |
// free buffer |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1413 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1414 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1415 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1416 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1417 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1418 |
* Enumerates and returns all IPv6 interfaces on AIX. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1419 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1420 |
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1421 |
struct ifconf ifc; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1422 |
struct ifreq *ifreqP; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1423 |
char *buf, *cp, *cplimit; |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1424 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1425 |
// call SIOCGSIZIFCONF to get size for SIOCGIFCONF buffer |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1426 |
if (ioctl(sock, SIOCGSIZIFCONF, &(ifc.ifc_len)) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1427 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1428 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGSIZIFCONF) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1429 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1430 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1431 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1432 |
// call SIOCGIFCONF to enumerate the interfaces |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1433 |
CHECKED_MALLOC3(buf, char *, ifc.ifc_len); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1434 |
ifc.ifc_buf = buf; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1435 |
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1436 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1437 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFCONF) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1438 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1439 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1440 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1441 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1442 |
// iterate through each interface |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1443 |
ifreqP = ifc.ifc_req; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1444 |
cp = (char *)ifc.ifc_req; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1445 |
cplimit = cp + ifc.ifc_len; |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1446 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1447 |
for (; cp < cplimit; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1448 |
cp += (sizeof(ifreqP->ifr_name) + |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1449 |
MAX((ifreqP->ifr_addr).sa_len, sizeof(ifreqP->ifr_addr)))) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1450 |
{ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1451 |
ifreqP = (struct ifreq *)cp; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1452 |
short prefix = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1453 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1454 |
// ignore non IPv6 addresses |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1455 |
if (ifreqP->ifr_addr.sa_family != AF_INET6) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1456 |
continue; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1457 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1458 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1459 |
// determine netmask |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1460 |
struct in6_ifreq if6; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1461 |
memset((char *)&if6, 0, sizeof(if6)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1462 |
strncpy(if6.ifr_name, ifreqP->ifr_name, sizeof(if6.ifr_name) - 1); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1463 |
memcpy(&(if6.ifr_Addr), &(ifreqP->ifr_addr), |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1464 |
sizeof(struct sockaddr_in6)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1465 |
if (ioctl(sock, SIOCGIFNETMASK6, (char *)&if6) >= 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1466 |
prefix = translateIPv6AddressToPrefix(&(if6.ifr_Addr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1467 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1468 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1469 |
// set scope ID to interface index |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1470 |
((struct sockaddr_in6 *)&(ifreqP->ifr_addr))->sin6_scope_id = |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1471 |
getIndex(sock, ifreqP->ifr_name); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1472 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1473 |
// add interface to the list |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1474 |
ifs = addif(env, sock, ifreqP->ifr_name, ifs, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1475 |
(struct sockaddr *)&(ifreqP->ifr_addr), |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1476 |
NULL, AF_INET6, prefix); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1477 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1478 |
// if an exception occurred then free the list |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1479 |
if ((*env)->ExceptionOccurred(env)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1480 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1481 |
freeif(ifs); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1482 |
return NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1483 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1484 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1485 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1486 |
// free buffer |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1487 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1488 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1489 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1490 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1491 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1492 |
* Try to get the interface index. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1493 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1494 |
static int getIndex(int sock, const char *name) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1495 |
int index = if_nametoindex(name); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1496 |
return (index == 0) ? -1 : index; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1497 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1498 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1499 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1500 |
* Gets the Hardware address (usually MAC address) for the named interface. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1501 |
* On return puts the data in buf, and returns the length, in byte, of the |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1502 |
* MAC address. Returns -1 if there is no hardware address on that interface. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1503 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1504 |
static int getMacAddress |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1505 |
(JNIEnv *env, const char *ifname, const struct in_addr *addr, |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1506 |
unsigned char *buf) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1507 |
{ |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1508 |
int size; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1509 |
struct kinfo_ndd *nddp; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1510 |
void *end; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1511 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1512 |
size = getkerninfo(KINFO_NDD, 0, 0, 0); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1513 |
if (size == 0) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1514 |
return -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1515 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1516 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1517 |
if (size < 0) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1518 |
perror("getkerninfo 1"); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1519 |
return -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1520 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1521 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1522 |
nddp = (struct kinfo_ndd *)malloc(size); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1523 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1524 |
if (!nddp) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1525 |
JNU_ThrowOutOfMemoryError(env, |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1526 |
"Network interface getMacAddress native buffer allocation failed"); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1527 |
return -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1528 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1529 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1530 |
if (getkerninfo(KINFO_NDD, nddp, &size, 0) < 0) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1531 |
perror("getkerninfo 2"); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1532 |
return -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1533 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1534 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1535 |
end = (void *)nddp + size; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1536 |
while ((void *)nddp < end) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1537 |
if (!strcmp(nddp->ndd_alias, ifname) || |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1538 |
!strcmp(nddp->ndd_name, ifname)) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1539 |
bcopy(nddp->ndd_addr, buf, 6); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1540 |
return 6; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1541 |
} else { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1542 |
nddp++; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1543 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1544 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1545 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21409
diff
changeset
|
1546 |
return -1; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1547 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1548 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1549 |
static int getMTU(JNIEnv *env, int sock, const char *ifname) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1550 |
struct ifreq if2; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1551 |
memset((char *)&if2, 0, sizeof(if2)); |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1552 |
strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1553 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1554 |
if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1555 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1556 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFMTU) failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1557 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1558 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1559 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1560 |
return if2.ifr_mtu; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1561 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1562 |
|
13564
3571e232ab03
7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
chegar
parents:
13245
diff
changeset
|
1563 |
static int getFlags(int sock, const char *ifname, int *flags) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1564 |
struct ifreq if2; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1565 |
memset((char *)&if2, 0, sizeof(if2)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1566 |
strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1); |
2 | 1567 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1568 |
if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1569 |
return -1; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1570 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1571 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1572 |
if (sizeof(if2.ifr_flags) == sizeof(short)) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1573 |
*flags = (if2.ifr_flags & 0xffff); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1574 |
} else { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1575 |
*flags = if2.ifr_flags; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1576 |
} |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1577 |
return 0; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1578 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1579 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1580 |
#endif /* _AIX */ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1581 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1582 |
/** Solaris **/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1583 |
#if defined(__solaris__) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1584 |
|
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1585 |
/* |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1586 |
* Opens a socket for further ioctl calls. Tries AF_INET socket first and |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1587 |
* if it fails return AF_INET6 socket. |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1588 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1589 |
static int openSocketWithFallback(JNIEnv *env, const char *ifname) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1590 |
int sock, alreadyV6 = 0; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1591 |
struct lifreq if2; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1592 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1593 |
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1594 |
if (errno == EPROTONOSUPPORT) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1595 |
if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1596 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1597 |
(env, JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed"); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1598 |
return -1; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1599 |
} |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1600 |
alreadyV6 = 1; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1601 |
} else { // errno is not NOSUPPORT |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1602 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1603 |
(env, JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed"); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1604 |
return -1; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1605 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1606 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1607 |
|
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1608 |
// Solaris requires that we have an IPv6 socket to query an interface |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1609 |
// without an IPv4 address - check it here. POSIX 1 require the kernel to |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1610 |
// return ENOTTY if the call is inappropriate for a device e.g. the NETMASK |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1611 |
// for a device having IPv6 only address but not all devices follow the |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1612 |
// standard so fall back on any error. It's not an ecologically friendly |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1613 |
// gesture but more reliable. |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1614 |
if (!alreadyV6) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1615 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1616 |
strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1617 |
if (ioctl(sock, SIOCGLIFNETMASK, (char *)&if2) < 0) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1618 |
close(sock); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1619 |
if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1620 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1621 |
(env, JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed"); |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1622 |
return -1; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1623 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1624 |
} |
2 | 1625 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1626 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1627 |
return sock; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1628 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1629 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1630 |
/* |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1631 |
* Enumerates and returns all IPv4 interfaces on Solaris. |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1632 |
*/ |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1633 |
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) { |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1634 |
struct lifconf ifc; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1635 |
struct lifreq *ifreqP; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1636 |
struct lifnum numifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1637 |
char *buf = NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1638 |
unsigned i; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1639 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1640 |
// call SIOCGLIFNUM to get the interface count |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1641 |
numifs.lifn_family = AF_INET; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1642 |
numifs.lifn_flags = 0; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1643 |
if (ioctl(sock, SIOCGLIFNUM, (char *)&numifs) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1644 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1645 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGLIFNUM) failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1646 |
return ifs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1647 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1648 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1649 |
// call SIOCGLIFCONF to enumerate the interfaces |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1650 |
ifc.lifc_len = numifs.lifn_count * sizeof(struct lifreq); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1651 |
CHECKED_MALLOC3(buf, char *, ifc.lifc_len); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1652 |
ifc.lifc_buf = buf; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1653 |
ifc.lifc_family = AF_INET; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1654 |
ifc.lifc_flags = 0; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1655 |
if (ioctl(sock, SIOCGLIFCONF, (char *)&ifc) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1656 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1657 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGLIFCONF) failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1658 |
free(buf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1659 |
return ifs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1660 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1661 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1662 |
// iterate through each interface |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1663 |
ifreqP = ifc.lifc_req; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1664 |
for (i = 0; i < numifs.lifn_count; i++, ifreqP++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1665 |
struct sockaddr addr, *broadaddrP = NULL; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1666 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1667 |
// ignore non IPv4 addresses |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1668 |
if (ifreqP->lifr_addr.ss_family != AF_INET) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1669 |
continue; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1670 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1671 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1672 |
// save socket address |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1673 |
memcpy(&addr, &(ifreqP->lifr_addr), sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1674 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1675 |
// determine broadcast address, if applicable |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1676 |
if ((ioctl(sock, SIOCGLIFFLAGS, ifreqP) == 0) && |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1677 |
ifreqP->lifr_flags & IFF_BROADCAST) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1678 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1679 |
// restore socket address to ifreqP |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1680 |
memcpy(&(ifreqP->lifr_addr), &addr, sizeof(struct sockaddr)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1681 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1682 |
// query broadcast address and set pointer to it |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1683 |
if (ioctl(sock, SIOCGLIFBRDADDR, ifreqP) == 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1684 |
broadaddrP = (struct sockaddr *)&(ifreqP->lifr_broadaddr); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1685 |
} |
6002
4df5b9bcf842
6967937: Scope id no longer being set after 6931566
chegar
parents:
5969
diff
changeset
|
1686 |
} |
4df5b9bcf842
6967937: Scope id no longer being set after 6931566
chegar
parents:
5969
diff
changeset
|
1687 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1688 |
// add to the list |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1689 |
ifs = addif(env, sock, ifreqP->lifr_name, ifs, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1690 |
&addr, broadaddrP, AF_INET, (short)ifreqP->lifr_addrlen); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1691 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1692 |
// if an exception occurred we return immediately |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1693 |
if ((*env)->ExceptionOccurred(env)) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1694 |
free(buf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1695 |
return ifs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1696 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1697 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1698 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1699 |
// free buffer |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1700 |
free(buf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1701 |
return ifs; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1702 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1703 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1704 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1705 |
* Enumerates and returns all IPv6 interfaces on Solaris. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1706 |
*/ |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1707 |
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1708 |
struct lifconf ifc; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1709 |
struct lifreq *ifreqP; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1710 |
struct lifnum numifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1711 |
char *buf = NULL; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1712 |
unsigned i; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1713 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1714 |
// call SIOCGLIFNUM to get the interface count |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1715 |
numifs.lifn_family = AF_INET6; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1716 |
numifs.lifn_flags = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1717 |
if (ioctl(sock, SIOCGLIFNUM, (char *)&numifs) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1718 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1719 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGLIFNUM) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1720 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1721 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1722 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1723 |
// call SIOCGLIFCONF to enumerate the interfaces |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1724 |
ifc.lifc_len = numifs.lifn_count * sizeof(struct lifreq); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1725 |
CHECKED_MALLOC3(buf, char *, ifc.lifc_len); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1726 |
ifc.lifc_buf = buf; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1727 |
ifc.lifc_family = AF_INET6; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1728 |
ifc.lifc_flags = 0; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1729 |
if (ioctl(sock, SIOCGLIFCONF, (char *)&ifc) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1730 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1731 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGLIFCONF) failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1732 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1733 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1734 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1735 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1736 |
// iterate through each interface |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1737 |
ifreqP = ifc.lifc_req; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1738 |
for (i = 0; i < numifs.lifn_count; i++, ifreqP++) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1739 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1740 |
// ignore non IPv6 addresses |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1741 |
if (ifreqP->lifr_addr.ss_family != AF_INET6) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1742 |
continue; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1743 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1744 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1745 |
// set scope ID to interface index |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1746 |
((struct sockaddr_in6 *)&(ifreqP->lifr_addr))->sin6_scope_id = |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1747 |
getIndex(sock, ifreqP->lifr_name); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1748 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1749 |
// add to the list |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1750 |
ifs = addif(env, sock, ifreqP->lifr_name, ifs, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1751 |
(struct sockaddr *)&(ifreqP->lifr_addr), |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1752 |
NULL, AF_INET6, (short)ifreqP->lifr_addrlen); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1753 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1754 |
// if an exception occurred we return immediately |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1755 |
if ((*env)->ExceptionOccurred(env)) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1756 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1757 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1758 |
} |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1759 |
} |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1760 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1761 |
// free buffer |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1762 |
free(buf); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1763 |
return ifs; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1764 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1765 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1766 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1767 |
* Try to get the interface index. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1768 |
* (Not supported on Solaris 2.6 or 7) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1769 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1770 |
static int getIndex(int sock, const char *name) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1771 |
struct lifreq if2; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1772 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1773 |
strncpy(if2.lifr_name, name, sizeof(if2.lifr_name) - 1); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1774 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1775 |
if (ioctl(sock, SIOCGLIFINDEX, (char *)&if2) < 0) { |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1776 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1777 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1778 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1779 |
return if2.lifr_index; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1780 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1781 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1782 |
/* |
2 | 1783 |
* Solaris specific DLPI code to get hardware address from a device. |
1784 |
* Unfortunately, at least up to Solaris X, you have to have special |
|
1785 |
* privileges (i.e. be root). |
|
1786 |
*/ |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1787 |
static int getMacFromDevice |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1788 |
(JNIEnv *env, const char *ifname, unsigned char *retbuf) |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1789 |
{ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1790 |
char style1dev[MAXPATHLEN]; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1791 |
int fd; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1792 |
dl_phys_addr_req_t dlpareq; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1793 |
dl_phys_addr_ack_t *dlpaack; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1794 |
struct strbuf msg; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1795 |
char buf[128]; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1796 |
int flags = 0; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1797 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1798 |
// Device is in /dev. e.g.: /dev/bge0 |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1799 |
strcpy(style1dev, DEV_PREFIX); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1800 |
strcat(style1dev, ifname); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1801 |
if ((fd = open(style1dev, O_RDWR)) < 0) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1802 |
// Can't open it. We probably are missing the privilege. |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1803 |
// We'll have to try something else |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1804 |
return 0; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1805 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1806 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1807 |
dlpareq.dl_primitive = DL_PHYS_ADDR_REQ; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1808 |
dlpareq.dl_addr_type = DL_CURR_PHYS_ADDR; |
2 | 1809 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1810 |
msg.buf = (char *)&dlpareq; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1811 |
msg.len = DL_PHYS_ADDR_REQ_SIZE; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1812 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1813 |
if (putmsg(fd, &msg, NULL, 0) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1814 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1815 |
(env, JNU_JAVANETPKG "SocketException", "putmsg() failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1816 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1817 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1818 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1819 |
dlpaack = (dl_phys_addr_ack_t *)buf; |
2 | 1820 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1821 |
msg.buf = (char *)buf; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1822 |
msg.len = 0; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1823 |
msg.maxlen = sizeof (buf); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1824 |
if (getmsg(fd, &msg, NULL, &flags) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1825 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1826 |
(env, JNU_JAVANETPKG "SocketException", "getmsg() failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1827 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1828 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1829 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1830 |
if (msg.len < DL_PHYS_ADDR_ACK_SIZE || dlpaack->dl_primitive != DL_PHYS_ADDR_ACK) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1831 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1832 |
"Couldn't obtain phys addr\n"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1833 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1834 |
} |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1835 |
|
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1836 |
memcpy(retbuf, &buf[dlpaack->dl_addr_offset], dlpaack->dl_addr_length); |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1837 |
return dlpaack->dl_addr_length; |
2 | 1838 |
} |
1839 |
||
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1840 |
/* |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1841 |
* Gets the Hardware address (usually MAC address) for the named interface. |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1842 |
* On return puts the data in buf, and returns the length, in byte, of the |
2 | 1843 |
* MAC address. Returns -1 if there is no hardware address on that interface. |
1844 |
*/ |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1845 |
static int getMacAddress |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1846 |
(JNIEnv *env, const char *ifname, const struct in_addr *addr, |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1847 |
unsigned char *buf) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1848 |
{ |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1849 |
struct lifreq if2; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1850 |
int len, i, sock; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1851 |
|
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1852 |
if ((sock = openSocketWithFallback(env, ifname)) < 0) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1853 |
return -1; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1854 |
} |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1855 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1856 |
// First, try the new (S11) SIOCGLIFHWADDR ioctl(). If that fails |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1857 |
// try the old way. |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1858 |
memset((char *)&if2, 0, sizeof(if2)); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1859 |
strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1); |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1860 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1861 |
if (ioctl(sock, SIOCGLIFHWADDR, &if2) != -1) { |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1862 |
struct sockaddr_dl *sp; |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1863 |
sp = (struct sockaddr_dl *)&if2.lifr_addr; |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1864 |
memcpy(buf, &sp->sdl_data[0], sp->sdl_alen); |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1865 |
close(sock); |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1866 |
return sp->sdl_alen; |
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1867 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1868 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1869 |
// On Solaris we have to use DLPI, but it will only work if we have |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1870 |
// privileged access (i.e. root). If that fails, we try a lookup |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1871 |
// in the ARP table, which requires an IPv4 address. |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1872 |
if (((len = getMacFromDevice(env, ifname, buf)) == 0) && (addr != NULL)) { |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1873 |
struct arpreq arpreq; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1874 |
struct sockaddr_in *sin; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1875 |
struct sockaddr_in ipAddr; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1876 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1877 |
len = 6; //??? |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1878 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1879 |
sin = (struct sockaddr_in *)&arpreq.arp_pa; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1880 |
memset((char *)&arpreq, 0, sizeof(struct arpreq)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1881 |
ipAddr.sin_port = 0; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1882 |
ipAddr.sin_family = AF_INET; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1883 |
memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1884 |
memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in)); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1885 |
arpreq.arp_flags= ATF_PUBL; |
2 | 1886 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1887 |
if (ioctl(sock, SIOCGARP, &arpreq) < 0) { |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1888 |
close(sock); |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1889 |
return -1; |
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1890 |
} |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1891 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1892 |
memcpy(buf, &arpreq.arp_ha.sa_data[0], len); |
10605
8c19a790b7c1
7079012: test/java/net/NetworkInterface/NetParamsTest.java fails with SocketException getting mac address
michaelm
parents:
9035
diff
changeset
|
1893 |
} |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1894 |
close(sock); |
2 | 1895 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1896 |
// all bytes to 0 means no hardware address |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1897 |
for (i = 0; i < len; i++) { |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1898 |
if (buf[i] != 0) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1899 |
return len; |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1900 |
} |
2 | 1901 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1902 |
return -1; |
2 | 1903 |
} |
1904 |
||
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1905 |
static int getMTU(JNIEnv *env, int sock, const char *ifname) { |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1906 |
struct lifreq if2; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1907 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1908 |
strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1); |
2 | 1909 |
|
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1910 |
if (ioctl(sock, SIOCGLIFMTU, (char *)&if2) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1911 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1912 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGLIFMTU) failed"); |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1913 |
return -1; |
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1914 |
} |
2 | 1915 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1916 |
return if2.lifr_mtu; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1917 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1918 |
|
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1919 |
static int getFlags(int sock, const char *ifname, int *flags) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1920 |
struct lifreq if2; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1921 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1922 |
strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1923 |
|
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1924 |
if (ioctl(sock, SIOCGLIFFLAGS, (char *)&if2) < 0) { |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
37898
diff
changeset
|
1925 |
return -1; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1926 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1927 |
|
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1928 |
*flags = if2.lifr_flags; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1929 |
return 0; |
2 | 1930 |
} |
1931 |
||
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1932 |
#endif /* __solaris__ */ |
5969
76a4031d39bd
6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents:
5506
diff
changeset
|
1933 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1934 |
/** BSD **/ |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1935 |
#if defined(_ALLBSD_SOURCE) |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1936 |
|
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1937 |
/* |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1938 |
* Opens a socket for further ioctl calls. Tries AF_INET socket first and |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1939 |
* if it fails return AF_INET6 socket. |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1940 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
1941 |
static int openSocketWithFallback(JNIEnv *env, const char *ifname) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1942 |
int sock; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1943 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1944 |
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1945 |
if (errno == EPROTONOSUPPORT) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1946 |
if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1947 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1948 |
(env, JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1949 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1950 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1951 |
} else { // errno is not NOSUPPORT |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1952 |
JNU_ThrowByNameWithMessageAndLastError |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1953 |
(env, JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed"); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1954 |
return -1; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1955 |
} |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1956 |
} |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1957 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1958 |
return sock; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1959 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1960 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1961 |
/* |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1962 |
* Enumerates and returns all IPv4 interfaces on BSD. |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1963 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1964 |
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1965 |
struct ifaddrs *ifa, *origifa; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1966 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1967 |
if (getifaddrs(&origifa) != 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1968 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
1969 |
(env, JNU_JAVANETPKG "SocketException", "getifaddrs() failed"); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1970 |
return ifs; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1971 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1972 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1973 |
for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) { |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1974 |
struct sockaddr *broadaddrP = NULL; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1975 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
1976 |
// ignore non IPv4 addresses |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1977 |
if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1978 |
continue; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1979 |
|
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1980 |
// set ifa_broadaddr, if there is one |
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1981 |
if ((ifa->ifa_flags & IFF_POINTOPOINT) == 0 && |
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1982 |
ifa->ifa_flags & IFF_BROADCAST) { |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1983 |
broadaddrP = ifa->ifa_dstaddr; |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1984 |
} |
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1985 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1986 |
// add interface to the list |
38885
42d2c26ffdf3
8158519: Incorrect network mask and broadcast address on Linux when there are multiple IPv4 addresses on an interface
chegar
parents:
38563
diff
changeset
|
1987 |
ifs = addif(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1988 |
broadaddrP, AF_INET, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1989 |
translateIPv4AddressToPrefix((struct sockaddr_in *) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1990 |
ifa->ifa_netmask)); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1991 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
1992 |
// if an exception occurred then free the list |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1993 |
if ((*env)->ExceptionOccurred(env)) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1994 |
freeifaddrs(origifa); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1995 |
freeif(ifs); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1996 |
return NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1997 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1998 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
1999 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2000 |
// free ifaddrs buffer |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2001 |
freeifaddrs(origifa); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2002 |
return ifs; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2003 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2004 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2005 |
/* |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2006 |
* Enumerates and returns all IPv6 interfaces on BSD. |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2007 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2008 |
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2009 |
struct ifaddrs *ifa, *origifa; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2010 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2011 |
if (getifaddrs(&origifa) != 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
2012 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
2013 |
(env, JNU_JAVANETPKG "SocketException", "getifaddrs() failed"); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2014 |
return ifs; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2015 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2016 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2017 |
for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
2018 |
// ignore non IPv6 addresses |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2019 |
if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET6) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2020 |
continue; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2021 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2022 |
// set scope ID to interface index |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2023 |
((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_scope_id = |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2024 |
getIndex(sock, ifa->ifa_name); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2025 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2026 |
// add interface to the list |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2027 |
ifs = addif(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, NULL, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2028 |
AF_INET6, |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2029 |
translateIPv6AddressToPrefix((struct sockaddr_in6 *) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2030 |
ifa->ifa_netmask)); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2031 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2032 |
// if an exception occurred then free the list |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2033 |
if ((*env)->ExceptionOccurred(env)) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2034 |
freeifaddrs(origifa); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2035 |
freeif(ifs); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2036 |
return NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2037 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2038 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2039 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2040 |
// free ifaddrs buffer |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2041 |
freeifaddrs(origifa); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2042 |
return ifs; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2043 |
} |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2044 |
|
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2045 |
/* |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2046 |
* Try to get the interface index. |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2047 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2048 |
static int getIndex(int sock, const char *name) { |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2049 |
#if !defined(__FreeBSD__) |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2050 |
int index = if_nametoindex(name); |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2051 |
return (index == 0) ? -1 : index; |
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2052 |
#else |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2053 |
struct ifreq if2; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2054 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2055 |
strncpy(if2.ifr_name, name, sizeof(if2.ifr_name) - 1); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2056 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2057 |
if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) < 0) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2058 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2059 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2060 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2061 |
return if2.ifr_index; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2062 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2063 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2064 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2065 |
/* |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2066 |
* Gets the Hardware address (usually MAC address) for the named interface. |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2067 |
* On return puts the data in buf, and returns the length, in byte, of the |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2068 |
* MAC address. Returns -1 if there is no hardware address on that interface. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2069 |
*/ |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2070 |
static int getMacAddress |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
2071 |
(JNIEnv *env, const char *ifname, const struct in_addr *addr, |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2072 |
unsigned char *buf) |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2073 |
{ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2074 |
struct ifaddrs *ifa0, *ifa; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2075 |
struct sockaddr *saddr; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2076 |
int i; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2077 |
|
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
2078 |
// grab the interface list |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2079 |
if (!getifaddrs(&ifa0)) { |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
2080 |
// cycle through the interfaces |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2081 |
for (i = 0, ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next, i++) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2082 |
saddr = ifa->ifa_addr; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
2083 |
// link layer contains the MAC address |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2084 |
if (saddr->sa_family == AF_LINK && !strcmp(ifname, ifa->ifa_name)) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2085 |
struct sockaddr_dl *sadl = (struct sockaddr_dl *) saddr; |
40741
e05878664d94
8163181: Further improvements for Unix NetworkInterface native implementation
clanger
parents:
39770
diff
changeset
|
2086 |
// check the address has the correct length |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2087 |
if (sadl->sdl_alen == ETHER_ADDR_LEN) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2088 |
memcpy(buf, (sadl->sdl_data + sadl->sdl_nlen), ETHER_ADDR_LEN); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2089 |
freeifaddrs(ifa0); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2090 |
return ETHER_ADDR_LEN; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2091 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2092 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2093 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2094 |
freeifaddrs(ifa0); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2095 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2096 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2097 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2098 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2099 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2100 |
static int getMTU(JNIEnv *env, int sock, const char *ifname) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2101 |
struct ifreq if2; |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2102 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2103 |
strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2104 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2105 |
if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) { |
39318
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
2106 |
JNU_ThrowByNameWithMessageAndLastError |
2006d1d41c8b
8158023: SocketExceptions contain too little information sometimes
clanger
parents:
38885
diff
changeset
|
2107 |
(env, JNU_JAVANETPKG "SocketException", "ioctl(SIOCGIFMTU) failed"); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2108 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2109 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2110 |
|
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2111 |
return if2.ifr_mtu; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2112 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2113 |
|
13564
3571e232ab03
7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
chegar
parents:
13245
diff
changeset
|
2114 |
static int getFlags(int sock, const char *ifname, int *flags) { |
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2115 |
struct ifreq if2; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2116 |
memset((char *)&if2, 0, sizeof(if2)); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2117 |
strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2118 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2119 |
if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2120 |
return -1; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2121 |
} |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2122 |
|
37898
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2123 |
if (sizeof(if2.ifr_flags) == sizeof(short)) { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2124 |
*flags = (if2.ifr_flags & 0xffff); |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2125 |
} else { |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2126 |
*flags = if2.ifr_flags; |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2127 |
} |
ac36c71a44f9
8156521: Minor fixes and cleanups in NetworkInterface.c
clanger
parents:
28549
diff
changeset
|
2128 |
return 0; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11355
diff
changeset
|
2129 |
} |
39770
53bcc005d1af
8160174: java.net.NetworkInterface - fixes and improvements for network interface listing
clanger
parents:
39318
diff
changeset
|
2130 |
#endif /* _ALLBSD_SOURCE */ |