Attached is the diff file
-- Doychin Bondzhev dSoft-Bulgaria Ltd. PowerPro - billing & provisioning solution for Service providers PowerStor - Warehouse & POS http://www.dsoft-bg.com/ Mobile: +359888243116
diff -r e17beec1b64f src/java.base/unix/native/libnet/NetworkInterface.c
--- a/src/java.base/unix/native/libnet/NetworkInterface.c Sat May 28 09:47:28 2016 +0530
+++ b/src/java.base/unix/native/libnet/NetworkInterface.c Mon May 30 15:49:58 2016 +0300
@@ -49,6 +49,7 @@
#include <bits/ioctls.h>
#include <sys/utsname.h>
#include <stdio.h>
+#include <ifaddrs.h>
#endif
#if defined(_AIX)
@@ -136,6 +137,9 @@
static netif *addif(JNIEnv *env, int sock, const char *if_name, netif *ifs,
struct sockaddr *ifr_addrP, int family, short prefix);
+static netif *addif2(JNIEnv *env, int sock, const char *if_name, netif *ifs,
+ struct sockaddr *ifr_addrP, int family, short prefix,
+ struct sockaddr *brdcast);
static void freeif(netif *ifs);
static int openSocket(JNIEnv *env, int proto);
@@ -145,6 +149,7 @@
static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *name,
struct sockaddr *brdcast_store);
static short getSubnet(JNIEnv *env, int sock, const char *ifname);
+static short getSubnetFromMaskAddr(const struct sockaddr_in * netmask_addrP);
static int getIndex(int sock, const char *ifname);
static int getFlags(int sock, const char *ifname, int *flags);
@@ -863,8 +868,9 @@
}
}
-netif *addif(JNIEnv *env, int sock, const char *if_name, netif *ifs,
- struct sockaddr *ifr_addrP, int family, short prefix)
+netif *addif2(JNIEnv *env, int sock, const char *if_name, netif *ifs,
+ struct sockaddr *ifr_addrP, int family, short prefix,
+ struct sockaddr *brdcast)
{
netif *currif = ifs, *parent;
netaddr *addrP;
@@ -915,6 +921,11 @@
// Deal with broadcast addr & subnet mask
struct sockaddr *brdcast_to =
(struct sockaddr *) ((char *)addrP + sizeof(netaddr) + addr_size);
+#if defined(__linux__)
+ if (brdcast != NULL) {
+ addrP->brdcast = memcpy(brdcast_to, brdcast, addr_size);
+ }
+#else
addrP->brdcast = getBroadcast(env, sock, name, brdcast_to);
if ((*env)->ExceptionCheck(env) == JNI_TRUE) {
return ifs;
@@ -924,6 +935,7 @@
} else if((*env)->ExceptionCheck(env)) {
return ifs;
}
+#endif
}
// Deal with virtual interface with colon notation e.g. eth0:1
@@ -1023,6 +1035,12 @@
return ifs;
}
+netif *addif(JNIEnv *env, int sock, const char * if_name,
+ netif *ifs, struct sockaddr* ifr_addrP, int family,
+ short prefix) {
+ return addif2(env, sock, if_name, ifs, ifr_addrP, family, prefix, NULL);
+}
+
/*
* Opens a socket for further ioct calls. proto is one of AF_INET or AF_INET6.
*/
@@ -1042,6 +1060,65 @@
return sock;
}
+/*
+ * Count the number of non-zero bits
+ */
+static inline short mask2subnet(uint32_t mask) {
+ short ret = 0;
+
+ for (; mask; mask <<= 1) {
+ ++ret;
+ }
+
+ return ret;
+}
+
+static inline short getSubnetFromMaskAddr(const struct sockaddr_in * netmask_addrP) {
+ return (netmask_addrP != NULL) ? mask2subnet(ntohl(netmask_addrP->sin_addr.s_addr)) : 0;
+}
+
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+/*
+ * Enumerates and returns all IPv4 interfaces
+ */
+static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
+ struct ifaddrs *ifa, *origifa;
+ struct sockaddr *ba = NULL;
+ short subnet = 0;
+
+ if (getifaddrs(&origifa) != 0) {
+ NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
+ "getifaddrs() function failed");
+ return ifs;
+ }
+
+ for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
+ /* Skip non-AF_INET entries */
+ if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET) {
+ continue;
+ }
+
+#if defined(__linux__)
+ ba = (ifa->ifa_flags & IFF_BROADCAST) ? ifa->ifa_broadaddr : NULL;
+ subnet = getSubnetFromMaskAddr(((const struct sockaddr_in *)ifa->ifa_netmask));
+#endif
+
+ /* Add to the list */
+ ifs = addif2(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, AF_INET, subnet, ba);
+
+ /* If an exception occurred then free the list */
+ if ((*env)->ExceptionOccurred(env)) {
+ freeifaddrs(origifa);
+ freeif(ifs);
+ return NULL;
+ }
+ }
+
+ /* Free socket and buffer */
+ freeifaddrs(origifa);
+ return ifs;
+}
+#endif /* __linux__ || _ALLBSD_SOURCE */
/** Linux, AIX **/
#if defined(__linux__) || defined(_AIX)
@@ -1081,6 +1158,7 @@
}
#endif
+#if defined(_AIX)
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
struct ifconf ifc;
struct ifreq *ifreqP;
@@ -1089,30 +1167,18 @@
unsigned i;
int siocgifconfRequest = SIOCGIFCONF;
-#if defined(__linux__)
- // need to do a dummy SIOCGIFCONF to determine the buffer size.
- // SIOCGIFCOUNT doesn't work
- ifc.ifc_buf = NULL;
- if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
- NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
- "ioctl SIOCGIFCONF failed");
- return ifs;
- }
-#elif defined(_AIX)
ifc.ifc_buf = NULL;
if (ioctl(sock, SIOCGSIZIFCONF, &(ifc.ifc_len)) < 0) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"ioctl SIOCGSIZIFCONF failed");
return ifs;
}
-#endif /* __linux__ */
CHECKED_MALLOC3(buf, char *, ifc.ifc_len);
ifc.ifc_buf = buf;
-#if defined(_AIX)
siocgifconfRequest = CSIOCGIFCONF;
-#endif
+
if (ioctl(sock, siocgifconfRequest, (char *)&ifc) < 0) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"ioctl SIOCGIFCONF failed");
@@ -1123,9 +1189,7 @@
// Iterate through each interface
ifreqP = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++, ifreqP++) {
-#if defined(_AIX)
if (ifreqP->ifr_addr.sa_family != AF_INET) continue;
-#endif
// Add to the list
ifs = addif(env, sock, ifreqP->ifr_name, ifs,
(struct sockaddr *)&(ifreqP->ifr_addr), AF_INET, 0);
@@ -1142,6 +1206,7 @@
free(buf);
return ifs;
}
+#endif /* _AIX */
#if defined(AF_INET6) && defined(__linux__)
@@ -1879,36 +1944,6 @@
/*
* Enumerates and returns all IPv4 interfaces.
*/
-static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
- struct ifaddrs *ifa, *origifa;
-
- if (getifaddrs(&origifa) != 0) {
- NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
- "getifaddrs() function failed");
- return ifs;
- }
-
- for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
-
- // Skip non-AF_INET entries.
- if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
- continue;
-
- // Add to the list.
- ifs = addif(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, AF_INET, 0);
-
- // If an exception occurred then free the list.
- if ((*env)->ExceptionOccurred(env)) {
- freeifaddrs(origifa);
- freeif(ifs);
- return NULL;
- }
- }
-
- // Free socket and buffer
- freeifaddrs(origifa);
- return ifs;
-}
#ifdef AF_INET6
/*
<<attachment: doychin.vcf>>
smime.p7s
Description: S/MIME Cryptographic Signature
