8168771: Remove #ifdef AF_INET6 guards in libnet native coding
Reviewed-by: chegar
--- a/jdk/src/java.base/share/native/libnet/net_util.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/share/native/libnet/net_util.c Wed Nov 02 11:52:51 2016 +0100
@@ -203,7 +203,6 @@
JNIEXPORT jobject JNICALL
NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
jobject iaObj;
-#ifdef AF_INET6
if (him->sa_family == AF_INET6) {
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
jbyte *caddr = (jbyte *)&(him6->sin6_addr);
@@ -227,16 +226,14 @@
setInet6Address_scopeid(env, iaObj, scope);
}
*port = ntohs(him6->sin6_port);
- } else
-#endif /* AF_INET6 */
- {
- struct sockaddr_in *him4 = (struct sockaddr_in *)him;
- iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
- CHECK_NULL_RETURN(iaObj, NULL);
- setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
- setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
- *port = ntohs(him4->sin_port);
- }
+ } else {
+ struct sockaddr_in *him4 = (struct sockaddr_in *)him;
+ iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
+ CHECK_NULL_RETURN(iaObj, NULL);
+ setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
+ setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
+ *port = ntohs(him4->sin_port);
+ }
return iaObj;
}
@@ -245,7 +242,6 @@
{
jint family = AF_INET;
-#ifdef AF_INET6
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
AF_INET : AF_INET6;
if (him->sa_family == AF_INET6) {
@@ -279,22 +275,20 @@
return JNI_FALSE;
}
}
- } else
-#endif /* AF_INET6 */
- {
- struct sockaddr_in *him4 = (struct sockaddr_in *)him;
- int addrNew, addrCur;
- if (family != AF_INET) {
- return JNI_FALSE;
- }
- addrNew = ntohl(him4->sin_addr.s_addr);
- addrCur = getInetAddress_addr(env, iaObj);
- if (addrNew == addrCur) {
- return JNI_TRUE;
- } else {
- return JNI_FALSE;
- }
+ } else {
+ struct sockaddr_in *him4 = (struct sockaddr_in *)him;
+ int addrNew, addrCur;
+ if (family != AF_INET) {
+ return JNI_FALSE;
}
+ addrNew = ntohl(him4->sin_addr.s_addr);
+ addrCur = getInetAddress_addr(env, iaObj);
+ if (addrNew == addrCur) {
+ return JNI_TRUE;
+ } else {
+ return JNI_FALSE;
+ }
+ }
}
unsigned short
--- a/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c Wed Nov 02 11:52:51 2016 +0100
@@ -72,7 +72,7 @@
hostname[NI_MAXHOST] = '\0';
}
-#if defined(__solaris__) && defined(AF_INET6)
+#if defined(__solaris__)
if (ret == 0) {
/* Solaris doesn't want to give us a fully qualified domain name.
* We do a reverse lookup to try and get one. This works
@@ -251,9 +251,7 @@
int retLen = 0;
int getaddrinfo_error=0;
-#ifdef AF_INET6
struct addrinfo hints, *res, *resNew = NULL;
-#endif /* AF_INET6 */
initInetAddressIDs(env);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
@@ -265,7 +263,6 @@
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
CHECK_NULL_RETURN(hostname, NULL);
-#ifdef AF_INET6
/* Try once, with our static buffer. */
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
@@ -459,7 +456,6 @@
}
freeaddrinfo(res);
-#endif /* AF_INET6 */
return ret;
}
@@ -475,7 +471,6 @@
jstring ret = NULL;
-#ifdef AF_INET6
char host[NI_MAXHOST+1];
int error = 0;
int len = 0;
@@ -518,7 +513,6 @@
ret = (*env)->NewStringUTF(env, host);
CHECK_NULL_RETURN(ret, NULL);
}
-#endif /* AF_INET6 */
if (ret == NULL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", NULL);
@@ -533,7 +527,6 @@
fcntl(fd, F_SETFL, flags); \
}
-#ifdef AF_INET6
static jboolean
ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout,
struct sockaddr_in6* netif, jint ttl) {
@@ -640,7 +633,6 @@
close(fd);
return JNI_FALSE;
}
-#endif /* AF_INET6 */
/*
* Class: java_net_Inet6AddressImpl
@@ -654,7 +646,6 @@
jint timeout,
jbyteArray ifArray,
jint ttl, jint if_scope) {
-#ifdef AF_INET6
jbyte caddr[16];
jint fd, sz;
struct sockaddr_in6 him6;
@@ -803,7 +794,4 @@
close(fd);
return JNI_FALSE;
}
-#else /* AF_INET6 */
- return JNI_FALSE;
-#endif /* AF_INET6 */
}
--- a/jdk/src/java.base/unix/native/libnet/InetAddressImplFactory.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/InetAddressImplFactory.c Wed Nov 02 11:52:51 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -37,14 +37,10 @@
* Signature: ()I
*/
JNIEXPORT jboolean JNICALL
-Java_java_net_InetAddressImplFactory_isIPv6Supported(JNIEnv *env, jclass cls)
-{
-#ifdef AF_INET6
+Java_java_net_InetAddressImplFactory_isIPv6Supported(JNIEnv *env, jclass cls) {
if (ipv6_available()) {
return JNI_TRUE;
- } else
-#endif /* AF_INET6 */
- {
- return JNI_FALSE;
- }
+ } else {
+ return JNI_FALSE;
+ }
}
--- a/jdk/src/java.base/unix/native/libnet/NetworkInterface.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/NetworkInterface.c Wed Nov 02 11:52:51 2016 +0100
@@ -126,10 +126,7 @@
static netif *enumInterfaces(JNIEnv *env);
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs);
-
-#if defined(AF_INET6)
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs);
-#endif
static netif *addif(JNIEnv *env, int sock, const char *if_name, netif *ifs,
struct sockaddr *ifr_addrP,
@@ -312,11 +309,8 @@
(JNIEnv *env, jclass cls, jobject iaObj)
{
netif *ifs, *curr;
-#if defined(AF_INET6)
- int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ? AF_INET : AF_INET6;
-#else
- int family = AF_INET;
-#endif
+ int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ?
+ AF_INET : AF_INET6;
jobject obj = NULL;
jboolean match = JNI_FALSE;
@@ -342,9 +336,7 @@
match = JNI_TRUE;
break;
}
- }
-#if defined(AF_INET6)
- if (family == AF_INET6) {
+ } else if (family == AF_INET6) {
jbyte *bytes = (jbyte *)&(
((struct sockaddr_in6*)addrP->addr)->sin6_addr);
jbyte caddr[16];
@@ -362,7 +354,6 @@
break;
}
}
-#endif
}
if (match) {
@@ -706,7 +697,6 @@
return NULL;
}
}
-#if defined(AF_INET6)
if (addrP->family == AF_INET6) {
int scope=0;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
@@ -735,7 +725,6 @@
return NULL;
}
}
-#endif
(*env)->SetObjectArrayElement(env, addrArr, addr_index++, iaObj);
addrP = addrP->next;
@@ -796,25 +785,23 @@
}
// If IPv6 is available then enumerate IPv6 addresses.
-#if defined(AF_INET6)
- // User can disable ipv6 explicitly by -Djava.net.preferIPv4Stack=true,
- // so we have to call ipv6_available()
- if (ipv6_available()) {
- sock = openSocket(env, AF_INET6);
- if (sock < 0 && (*env)->ExceptionOccurred(env)) {
- freeif(ifs);
- return NULL;
- }
+ // User can disable ipv6 explicitly by -Djava.net.preferIPv4Stack=true,
+ // so we have to call ipv6_available()
+ if (ipv6_available()) {
+ sock = openSocket(env, AF_INET6);
+ if (sock < 0 && (*env)->ExceptionOccurred(env)) {
+ freeif(ifs);
+ return NULL;
+ }
- ifs = enumIPv6Interfaces(env, sock, ifs);
- close(sock);
+ ifs = enumIPv6Interfaces(env, sock, ifs);
+ close(sock);
- if ((*env)->ExceptionOccurred(env)) {
- freeif(ifs);
- return NULL;
- }
+ if ((*env)->ExceptionOccurred(env)) {
+ freeif(ifs);
+ return NULL;
}
-#endif
+ }
return ifs;
}
@@ -870,12 +857,8 @@
// Allocate for addr and brdcast at once
-#if defined(AF_INET6)
addr_size = (family == AF_INET) ? sizeof(struct sockaddr_in)
: sizeof(struct sockaddr_in6);
-#else
- addr_size = sizeof(struct sockaddr_in);
-#endif
CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr) + 2 * addr_size);
addrP->addr = (struct sockaddr *)((char *)addrP + sizeof(netaddr));
@@ -1064,7 +1047,6 @@
/** Linux **/
#if defined(__linux__)
-#if defined(AF_INET6)
/*
* Opens a socket for further ioctl calls. Tries AF_INET socket first and
* if it fails return AF_INET6 socket.
@@ -1090,11 +1072,6 @@
// IPv6 socket regardless of type of address of an interface.
return sock;
}
-#else
-static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
- return openSocket(env, AF_INET);
-}
-#endif
/*
* Enumerates and returns all IPv4 interfaces on Linux.
@@ -1178,8 +1155,6 @@
return ifs;
}
-#if defined(AF_INET6)
-
/*
* Enumerates and returns all IPv6 interfaces on Linux.
*/
@@ -1221,8 +1196,6 @@
return ifs;
}
-#endif /* AF_INET6 */
-
/*
* Try to get the interface index.
*/
@@ -1311,7 +1284,6 @@
/** AIX **/
#if defined(_AIX)
-#if defined(AF_INET6)
/*
* Opens a socket for further ioctl calls. Tries AF_INET socket first and
* if it fails return AF_INET6 socket.
@@ -1335,11 +1307,6 @@
return sock;
}
-#else
-static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
- return openSocket(env, AF_INET);
-}
-#endif
/*
* Enumerates and returns all IPv4 interfaces on AIX.
@@ -1423,8 +1390,6 @@
return ifs;
}
-#if defined(AF_INET6)
-
/*
* Enumerates and returns all IPv6 interfaces on AIX.
*/
@@ -1499,8 +1464,6 @@
return ifs;
}
-#endif /* AF_INET6 */
-
/*
* Try to get the interface index.
*/
@@ -1595,7 +1558,6 @@
/** Solaris **/
#if defined(__solaris__)
-#if defined(AF_INET6)
/*
* Opens a socket for further ioctl calls. Tries AF_INET socket first and
* if it fails return AF_INET6 socket.
@@ -1640,11 +1602,6 @@
return sock;
}
-#else
-static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
- return openSocket(env, AF_INET);
-}
-#endif
/*
* Enumerates and returns all IPv4 interfaces on Solaris.
@@ -1720,8 +1677,6 @@
return ifs;
}
-#if defined(AF_INET6)
-
/*
* Enumerates and returns all IPv6 interfaces on Solaris.
*/
@@ -1784,8 +1739,6 @@
return ifs;
}
-#endif /* AF_INET6 */
-
/*
* Try to get the interface index.
* (Not supported on Solaris 2.6 or 7)
@@ -1957,7 +1910,6 @@
/** BSD **/
#if defined(_ALLBSD_SOURCE)
-#if defined(AF_INET6)
/*
* Opens a socket for further ioctl calls. Tries AF_INET socket first and
* if it fails return AF_INET6 socket.
@@ -1981,11 +1933,6 @@
return sock;
}
-#else
-static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
- return openSocket(env, AF_INET);
-}
-#endif
/*
* Enumerates and returns all IPv4 interfaces on BSD.
@@ -2031,8 +1978,6 @@
return ifs;
}
-#if defined(AF_INET6)
-
/*
* Enumerates and returns all IPv6 interfaces on BSD.
*/
@@ -2073,8 +2018,6 @@
return ifs;
}
-#endif /* AF_INET6 */
-
/*
* Try to get the interface index.
*/
--- a/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c Wed Nov 02 11:52:51 2016 +0100
@@ -299,13 +299,10 @@
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
memset(&addr, 0, sizeof(addr));
-#ifdef AF_INET6
if (ipv6_available()) {
addr.sa6.sin6_family = AF_UNSPEC;
len = sizeof(struct sockaddr_in6);
- } else
-#endif
- {
+ } else {
addr.sa4.sin_family = AF_UNSPEC;
len = sizeof(struct sockaddr_in);
}
@@ -319,12 +316,9 @@
localPort = NET_GetPortFromSockaddr(&addr.sa);
if (localPort == 0) {
localPort = (*env)->GetIntField(env, this, pdsi_localPortID);
-#ifdef AF_INET6
if (addr.sa.sa_family == AF_INET6) {
addr.sa6.sin6_port = htons(localPort);
- } else
-#endif /* AF_INET6 */
- {
+ } else {
addr.sa4.sin_port = htons(localPort);
}
@@ -432,12 +426,9 @@
(*env)->GetByteArrayRegion(env, packetBuffer, packetBufferOffset, packetBufferLen,
(jbyte *)fullPacket);
-#ifdef AF_INET6
if (trafficClass != 0 && ipv6_available()) {
NET_SetTrafficClass(&rmtaddr.sa, trafficClass);
}
-#endif /* AF_INET6 */
-
/*
* Send the datagram.
@@ -538,12 +529,8 @@
}
iaObj = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
-#ifdef AF_INET6
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
AF_INET : AF_INET6;
-#else
- family = AF_INET;
-#endif
if (family == AF_INET) { /* this API can't handle IPV6 addresses */
int address = getInetAddress_addr(env, iaObj);
setInetAddress_addr(env, addressObj, address);
@@ -908,11 +895,7 @@
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
int arg, fd, t = 1;
char tmpbuf[1024];
-#ifdef AF_INET6
int domain = ipv6_available() ? AF_INET6 : AF_INET;
-#else
- int domain = AF_INET;
-#endif
if (IS_NULL(fdObj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -926,7 +909,6 @@
return;
}
-#ifdef AF_INET6
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
arg = 0;
@@ -937,7 +919,6 @@
return;
}
}
-#endif /* AF_INET6 */
#ifdef __APPLE__
arg = 65507;
@@ -977,7 +958,7 @@
}
#endif
-#if defined (__linux__) && defined (AF_INET6)
+#if defined (__linux__)
/*
* On Linux for IPv6 sockets we must set the hop limit
* to 1 to be compatible with default TTL of 1 for IPv4 sockets.
@@ -1078,7 +1059,6 @@
* Set outgoing multicast interface designated by a NetworkInterface.
* Throw exception if failed.
*/
-#ifdef AF_INET6
static void mcast_set_if_by_if_v6(JNIEnv *env, jobject this, int fd, jobject value) {
static jfieldID ni_indexID;
int index;
@@ -1103,9 +1083,7 @@
}
return;
}
-
}
-#endif /* AF_INET6 */
/*
* Set outgoing multicast interface designated by an InetAddress.
@@ -1127,7 +1105,6 @@
* Set outgoing multicast interface designated by an InetAddress.
* Throw exception if failed.
*/
-#ifdef AF_INET6
static void mcast_set_if_by_addr_v6(JNIEnv *env, jobject this, int fd, jobject value) {
static jclass ni_class;
if (ni_class == NULL) {
@@ -1149,7 +1126,6 @@
mcast_set_if_by_if_v6(env, this, fd, value);
}
-#endif
/*
* Sets the multicast interface.
@@ -1181,7 +1157,6 @@
/*
* value is an InetAddress.
*/
-#ifdef AF_INET6
#ifdef __linux__
mcast_set_if_by_addr_v4(env, this, fd, value);
if (ipv6_available()) {
@@ -1197,16 +1172,12 @@
mcast_set_if_by_addr_v4(env, this, fd, value);
}
#endif /* __linux__ */
-#else
- mcast_set_if_by_addr_v4(env, this, fd, value);
-#endif /* AF_INET6 */
}
if (opt == java_net_SocketOptions_IP_MULTICAST_IF2) {
/*
* value is a NetworkInterface.
*/
-#ifdef AF_INET6
#ifdef __linux__
mcast_set_if_by_if_v4(env, this, fd, value);
if (ipv6_available()) {
@@ -1222,9 +1193,6 @@
mcast_set_if_by_if_v4(env, this, fd, value);
}
#endif /* __linux__ */
-#else
- mcast_set_if_by_if_v4(env, this, fd, value);
-#endif /* AF_INET6 */
}
}
@@ -1256,7 +1224,6 @@
/*
* Enable/disable local loopback of multicast datagrams.
*/
-#ifdef AF_INET6
static void mcast_set_loop_v6(JNIEnv *env, jobject this, int fd, jobject value) {
jclass cls;
jfieldID fid;
@@ -1279,14 +1246,12 @@
}
}
-#endif /* AF_INET6 */
/*
* Sets the multicast loopback mode.
*/
static void setMulticastLoopbackMode(JNIEnv *env, jobject this, int fd,
jint opt, jobject value) {
-#ifdef AF_INET6
#ifdef __linux__
mcast_set_loop_v4(env, this, fd, value);
if (ipv6_available()) {
@@ -1302,9 +1267,6 @@
mcast_set_loop_v4(env, this, fd, value);
}
#endif /* __linux__ */
-#else
- mcast_set_loop_v4(env, this, fd, value);
-#endif /* AF_INET6 */
}
/*
@@ -1446,11 +1408,9 @@
jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) {
jboolean isIPV4 = JNI_TRUE;
-#ifdef AF_INET6
if (ipv6_available()) {
isIPV4 = JNI_FALSE;
}
-#endif
/*
* IPv4 implementation
@@ -1549,7 +1509,6 @@
}
-#ifdef AF_INET6
/*
* IPv6 implementation
*/
@@ -1667,7 +1626,6 @@
}
return ni;
}
-#endif
return NULL;
}
@@ -1805,7 +1763,6 @@
/*
* Set hops limit for a socket. Throw exception if failed.
*/
-#ifdef AF_INET6
static void setHopLimit(JNIEnv *env, int fd, jint ttl) {
int ittl = (int)ttl;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
@@ -1814,7 +1771,6 @@
(env, JNU_JAVANETPKG "SocketException", "Error setting socket option");
}
}
-#endif
/*
* Class: java_net_PlainDatagramSocketImpl
@@ -1837,7 +1793,6 @@
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
/* setsockopt to be correct TTL */
-#ifdef AF_INET6
#ifdef __linux__
setTTL(env, fd, ttl);
JNU_CHECK_EXCEPTION(env);
@@ -1851,9 +1806,6 @@
setTTL(env, fd, ttl);
}
#endif /* __linux__ */
-#else
- setTTL(env, fd, ttl);
-#endif /* AF_INET6 */
}
/*
@@ -1886,7 +1838,6 @@
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
/* getsockopt of TTL */
-#ifdef AF_INET6
if (ipv6_available()) {
int ttl = 0;
socklen_t len = sizeof(ttl);
@@ -1898,19 +1849,17 @@
return -1;
}
return (jint)ttl;
- } else
-#endif /* AF_INET6 */
- {
- u_char ttl = 0;
- socklen_t len = sizeof(ttl);
- if (getsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
- (char*)&ttl, &len) < 0) {
- JNU_ThrowByNameWithMessageAndLastError
- (env, JNU_JAVANETPKG "SocketException", "Error getting socket option");
- return -1;
- }
- return (jint)ttl;
+ } else {
+ u_char ttl = 0;
+ socklen_t len = sizeof(ttl);
+ if (getsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
+ (char*)&ttl, &len) < 0) {
+ JNU_ThrowByNameWithMessageAndLastError
+ (env, JNU_JAVANETPKG "SocketException", "Error getting socket option");
+ return -1;
}
+ return (jint)ttl;
+ }
}
@@ -1956,7 +1905,6 @@
/*
* Determine if this is an IPv4 or IPv6 join/leave.
*/
-#ifdef AF_INET6
ipv6_join_leave = ipv6_available();
#ifdef __linux__
@@ -1965,13 +1913,6 @@
}
#endif
-#else
- /*
- * IPv6 not compiled in
- */
- ipv6_join_leave = JNI_FALSE;
-#endif
-
/*
* For IPv4 join use IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP socket option
*
@@ -1996,7 +1937,7 @@
* NetworkInterface
*/
if (niObj != NULL) {
-#if defined(__linux__) && defined(AF_INET6)
+#if defined(__linux__)
if (ipv6_available()) {
static jfieldID ni_indexID;
@@ -2052,7 +1993,7 @@
if (niObj == NULL) {
-#if defined(__linux__) && defined(AF_INET6)
+#if defined(__linux__)
if (ipv6_available()) {
int index;
@@ -2108,7 +2049,7 @@
* should return ENOPROTOOPT. We assume this will be fixed in Linux
* at some stage.
*/
-#if defined(__linux__) && defined(AF_INET6)
+#if defined(__linux__)
if (errno == ENOPROTOOPT) {
if (ipv6_available()) {
ipv6_join_leave = JNI_TRUE;
@@ -2145,7 +2086,6 @@
* IPv6 join. If it's an IPv4 multicast group then we use an IPv4-mapped
* address.
*/
-#ifdef AF_INET6
{
struct ipv6_mreq mname6;
jbyteArray ipaddress;
@@ -2233,7 +2173,6 @@
}
}
}
-#endif
}
/*
--- a/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c Wed Nov 02 11:52:51 2016 +0100
@@ -162,11 +162,7 @@
jobject fdObj, ssObj;
int fd;
int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
-#ifdef AF_INET6
int domain = ipv6_available() ? AF_INET6 : AF_INET;
-#else
- int domain = AF_INET;
-#endif
if (socketExceptionCls == NULL) {
jclass c = (*env)->FindClass(env, "java/net/SocketException");
@@ -190,7 +186,6 @@
return;
}
-#ifdef AF_INET6
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
int arg = 0;
@@ -201,7 +196,6 @@
return;
}
}
-#endif /* AF_INET6 */
/*
* If this is a server socket then enable SO_REUSEADDR
@@ -271,11 +265,10 @@
}
setDefaultScopeID(env, &him.sa);
-#ifdef AF_INET6
if (trafficClass != 0 && ipv6_available()) {
NET_SetTrafficClass(&him.sa, trafficClass);
}
-#endif /* AF_INET6 */
+
if (timeout <= 0) {
connect_rv = NET_Connect(fd, &him.sa, len);
#ifdef __solaris__
--- a/jdk/src/java.base/unix/native/libnet/SdpSupport.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/SdpSupport.c Wed Nov 02 11:52:51 2016 +0100
@@ -56,11 +56,7 @@
int s;
#if defined(__solaris__)
- #ifdef AF_INET6
int domain = ipv6_available() ? AF_INET6 : AF_INET;
- #else
- int domain = AF_INET;
- #endif
s = socket(domain, SOCK_STREAM, PROTO_SDP);
#elif defined(__linux__)
/**
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.c Wed Nov 02 11:52:51 2016 +0100
@@ -306,11 +306,6 @@
jint IPv6_supported()
{
-#ifndef AF_INET6
- return JNI_FALSE;
-#endif
-
-#ifdef AF_INET6
int fd;
void *ipv6_fn;
SOCKETADDRESS sa;
@@ -415,7 +410,6 @@
} else {
return JNI_TRUE;
}
-#endif /* AF_INET6 */
}
#endif /* DONT_ENABLE_IPV6 */
@@ -466,7 +460,7 @@
}
}
-#if defined(__linux__) && defined(AF_INET6)
+#if defined(__linux__)
/* following code creates a list of addresses from the kernel
* routing table that are routed via the loopback address.
@@ -786,7 +780,6 @@
int *len, jboolean v4MappedAddress) {
jint family;
family = getInetAddress_family(env, iaObj);
-#ifdef AF_INET6
/* needs work. 1. family 2. clean up him6 etc deallocate memory */
if (ipv6_available() && !(family == java_net_InetAddress_IPv4 &&
v4MappedAddress == JNI_FALSE)) {
@@ -794,7 +787,6 @@
jbyte caddr[16];
jint address;
-
if (family == java_net_InetAddress_IPv4) {
// convert to IPv4-mapped address
memset((char *) caddr, 0, 16);
@@ -818,9 +810,9 @@
him6->sin6_port = htons(port);
memcpy((void *)&(him6->sin6_addr), caddr, sizeof(struct in6_addr) );
him6->sin6_family = AF_INET6;
- *len = sizeof(struct sockaddr_in6) ;
+ *len = sizeof(struct sockaddr_in6);
-#if defined(_ALLBSD_SOURCE) && defined(_AF_INET6)
+#if defined(_ALLBSD_SOURCE)
// XXXBSD: should we do something with scope id here ? see below linux comment
/* MMM: Come back to this! */
#endif
@@ -864,11 +856,11 @@
* try determine the appropriate interface.
*/
if (kernelIsV24()) {
- cached_scope_id = getDefaultIPv6Interface( &(him6->sin6_addr) );
+ cached_scope_id = getDefaultIPv6Interface(&(him6->sin6_addr));
} else {
- cached_scope_id = getLocalScopeID( (char *)&(him6->sin6_addr) );
+ cached_scope_id = getLocalScopeID((char *)&(him6->sin6_addr));
if (cached_scope_id == 0) {
- cached_scope_id = getDefaultIPv6Interface( &(him6->sin6_addr) );
+ cached_scope_id = getDefaultIPv6Interface(&(him6->sin6_addr));
}
}
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id);
@@ -896,46 +888,38 @@
}
}
#endif
- } else
-#endif /* AF_INET6 */
- {
- struct sockaddr_in *him4 = (struct sockaddr_in*)him;
- jint address;
- if (family == java_net_InetAddress_IPv6) {
- JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable");
- return -1;
- }
- memset((char *) him4, 0, sizeof(struct sockaddr_in));
- address = getInetAddress_addr(env, iaObj);
- him4->sin_port = htons((short) port);
- him4->sin_addr.s_addr = htonl(address);
- him4->sin_family = AF_INET;
- *len = sizeof(struct sockaddr_in);
+ } else {
+ struct sockaddr_in *him4 = (struct sockaddr_in *)him;
+ jint address;
+ if (family == java_net_InetAddress_IPv6) {
+ JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable");
+ return -1;
}
+ memset((char *)him4, 0, sizeof(struct sockaddr_in));
+ address = getInetAddress_addr(env, iaObj);
+ him4->sin_port = htons((short) port);
+ him4->sin_addr.s_addr = htonl(address);
+ him4->sin_family = AF_INET;
+ *len = sizeof(struct sockaddr_in);
+ }
return 0;
}
void
NET_SetTrafficClass(struct sockaddr *him, int trafficClass) {
-#ifdef AF_INET6
if (him->sa_family == AF_INET6) {
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
him6->sin6_flowinfo = htonl((trafficClass & 0xff) << 20);
}
-#endif /* AF_INET6 */
}
JNIEXPORT jint JNICALL
NET_GetPortFromSockaddr(struct sockaddr *him) {
-#ifdef AF_INET6
if (him->sa_family == AF_INET6) {
return ntohs(((struct sockaddr_in6*)him)->sin6_port);
-
- } else
-#endif /* AF_INET6 */
- {
- return ntohs(((struct sockaddr_in*)him)->sin_port);
- }
+ } else {
+ return ntohs(((struct sockaddr_in*)him)->sin_port);
+ }
}
int
@@ -1008,7 +992,6 @@
int i;
-#ifdef AF_INET6
if (ipv6_available()) {
switch (cmd) {
// Different multicast options if IPv6 is enabled
@@ -1031,7 +1014,6 @@
#endif
}
}
-#endif
/*
* Map the Java level option to the native level
@@ -1063,7 +1045,7 @@
* 0 if no matching interface
* >1 interface index to use for the link-local address.
*/
-#if defined(__linux__) && defined(AF_INET6)
+#if defined(__linux__)
int getDefaultIPv6Interface(struct in6_addr *target_addr) {
FILE *f;
char srcp[8][5];
@@ -1300,7 +1282,7 @@
if (level == IPPROTO_IP && opt == IP_TOS) {
int *iptos;
-#if defined(AF_INET6) && defined(__linux__)
+#if defined(__linux__)
if (ipv6_available()) {
int optval = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND,
@@ -1504,7 +1486,7 @@
int
NET_Bind(int fd, struct sockaddr *him, int len)
{
-#if defined(__solaris__) && defined(AF_INET6)
+#if defined(__solaris__)
int level = -1;
int exclbind = -1;
#endif
@@ -1568,7 +1550,7 @@
rv = bind(fd, him, len);
-#if defined(__solaris__) && defined(AF_INET6)
+#if defined(__solaris__)
if (rv < 0) {
int en = errno;
/* Restore *_EXCLBIND if the bind fails */
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.h Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.h Wed Nov 02 11:52:51 2016 +0100
@@ -84,18 +84,11 @@
#define MAX_HEAP_BUFFER_LEN 65536
#endif
-#ifdef AF_INET6
typedef union {
struct sockaddr sa;
struct sockaddr_in sa4;
struct sockaddr_in6 sa6;
} SOCKETADDRESS;
-#else
-typedef union {
- struct sockaddr sa;
- struct sockaddr_in sa4;
-} SOCKETADDRESS;
-#endif
/************************************************************************
* Utilities
@@ -103,10 +96,8 @@
#ifdef __linux__
int kernelIsV24();
-#ifdef AF_INET6
int getDefaultIPv6Interface(struct in6_addr *target_addr);
#endif
-#endif
#ifdef __solaris__
int net_getParam(char *driver, char *param);
--- a/jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c Wed Nov 02 10:43:48 2016 +0100
+++ b/jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c Wed Nov 02 11:52:51 2016 +0100
@@ -305,8 +305,6 @@
return ret;
}
-#ifdef AF_INET6
-
/**
* ping implementation using tcp port 7 (echo)
*/
@@ -468,7 +466,6 @@
return JNI_FALSE;
}
}
-#endif /* AF_INET6 */
/*
* Class: java_net_Inet6AddressImpl
@@ -482,7 +479,6 @@
jint timeout,
jbyteArray ifArray,
jint ttl, jint if_scope) {
-#ifdef AF_INET6
jbyte caddr[16];
jint sz;
struct sockaddr_in6 him6;
@@ -548,6 +544,5 @@
return ping6(env, netif, &him6, timeout, hIcmpFile);
}
-#endif /* AF_INET6 */
return JNI_FALSE;
}