8168771: Remove #ifdef AF_INET6 guards in libnet native coding

Reviewed-by: chegar
This commit is contained in:
Christoph Langer 2016-11-02 11:52:51 +01:00
parent fb5635d6df
commit cc20838f95
10 changed files with 89 additions and 272 deletions

View File

@ -203,7 +203,6 @@ jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
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 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
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 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
{
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 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
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

View File

@ -72,7 +72,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
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 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
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 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
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 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
freeaddrinfo(res);
#endif /* AF_INET6 */
return ret;
}
@ -475,7 +471,6 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
jstring ret = NULL;
#ifdef AF_INET6
char host[NI_MAXHOST+1];
int error = 0;
int len = 0;
@ -518,7 +513,6 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
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 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
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 @@ ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout,
close(fd);
return JNI_FALSE;
}
#endif /* AF_INET6 */
/*
* Class: java_net_Inet6AddressImpl
@ -654,7 +646,6 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
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 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
close(fd);
return JNI_FALSE;
}
#else /* AF_INET6 */
return JNI_FALSE;
#endif /* AF_INET6 */
}

View File

@ -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;
}
}

View File

@ -126,10 +126,7 @@ static int getFlags0(JNIEnv *env, jstring ifname);
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 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
(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 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
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 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
break;
}
}
#endif
}
if (match) {
@ -706,7 +697,6 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
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 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
return NULL;
}
}
#endif
(*env)->SetObjectArrayElement(env, addrArr, addr_index++, iaObj);
addrP = addrP->next;
@ -796,25 +785,23 @@ static netif *enumInterfaces(JNIEnv *env) {
}
// 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;
}
ifs = enumIPv6Interfaces(env, sock, ifs);
close(sock);
if ((*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;
}
#endif
ifs = enumIPv6Interfaces(env, sock, ifs);
close(sock);
if ((*env)->ExceptionOccurred(env)) {
freeif(ifs);
return NULL;
}
}
return ifs;
}
@ -870,12 +857,8 @@ static netif *addif(JNIEnv *env, int sock, const char *if_name, netif *ifs,
// 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 @@ static int openSocket(JNIEnv *env, int proto) {
/** 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 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
// 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 @@ static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#if defined(AF_INET6)
/*
* Enumerates and returns all IPv6 interfaces on Linux.
*/
@ -1221,8 +1196,6 @@ static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#endif /* AF_INET6 */
/*
* Try to get the interface index.
*/
@ -1311,7 +1284,6 @@ static int getFlags(int sock, const char *ifname, int *flags) {
/** 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 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
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 @@ static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#if defined(AF_INET6)
/*
* Enumerates and returns all IPv6 interfaces on AIX.
*/
@ -1499,8 +1464,6 @@ static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#endif /* AF_INET6 */
/*
* Try to get the interface index.
*/
@ -1595,7 +1558,6 @@ static int getFlags(int sock, const char *ifname, int *flags) {
/** 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 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
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 @@ static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#if defined(AF_INET6)
/*
* Enumerates and returns all IPv6 interfaces on Solaris.
*/
@ -1784,8 +1739,6 @@ static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#endif /* AF_INET6 */
/*
* Try to get the interface index.
* (Not supported on Solaris 2.6 or 7)
@ -1957,7 +1910,6 @@ static int getFlags(int sock, const char *ifname, int *flags) {
/** 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 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
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 @@ static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#if defined(AF_INET6)
/*
* Enumerates and returns all IPv6 interfaces on BSD.
*/
@ -2073,8 +2018,6 @@ static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
return ifs;
}
#endif /* AF_INET6 */
/*
* Try to get the interface index.
*/

View File

@ -299,13 +299,10 @@ Java_java_net_PlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject this, jin
#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 @@ Java_java_net_PlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject this, jin
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 @@ Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
(*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 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
}
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 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
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 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
return;
}
#ifdef AF_INET6
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
arg = 0;
@ -937,7 +919,6 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
return;
}
}
#endif /* AF_INET6 */
#ifdef __APPLE__
arg = 65507;
@ -977,7 +958,7 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
}
#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 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val
* 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 @@ static void mcast_set_if_by_if_v6(JNIEnv *env, jobject this, int fd, jobject val
}
return;
}
}
#endif /* AF_INET6 */
/*
* Set outgoing multicast interface designated by an InetAddress.
@ -1127,7 +1105,6 @@ static void mcast_set_if_by_addr_v4(JNIEnv *env, jobject this, int fd, jobject v
* 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 @@ static void mcast_set_if_by_addr_v6(JNIEnv *env, jobject this, int fd, jobject v
mcast_set_if_by_if_v6(env, this, fd, value);
}
#endif
/*
* Sets the multicast interface.
@ -1181,7 +1157,6 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd,
/*
* 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 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd,
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 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd,
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 @@ static void mcast_set_loop_v4(JNIEnv *env, jobject this, int fd, jobject value)
/*
* 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 @@ static void mcast_set_loop_v6(JNIEnv *env, jobject this, int fd, jobject value)
}
}
#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 @@ static void setMulticastLoopbackMode(JNIEnv *env, jobject this, int fd,
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 @@ Java_java_net_PlainDatagramSocketImpl_socketSetOption0
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 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) {
}
#ifdef AF_INET6
/*
* IPv6 implementation
*/
@ -1667,7 +1626,6 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) {
}
return ni;
}
#endif
return NULL;
}
@ -1805,7 +1763,6 @@ static void setTTL(JNIEnv *env, int fd, jint ttl) {
/*
* 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 @@ static void setHopLimit(JNIEnv *env, int fd, jint ttl) {
(env, JNU_JAVANETPKG "SocketException", "Error setting socket option");
}
}
#endif
/*
* Class: java_net_PlainDatagramSocketImpl
@ -1837,7 +1793,6 @@ Java_java_net_PlainDatagramSocketImpl_setTimeToLive(JNIEnv *env, jobject this,
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 @@ Java_java_net_PlainDatagramSocketImpl_setTimeToLive(JNIEnv *env, jobject this,
setTTL(env, fd, ttl);
}
#endif /* __linux__ */
#else
setTTL(env, fd, ttl);
#endif /* AF_INET6 */
}
/*
@ -1886,7 +1838,6 @@ Java_java_net_PlainDatagramSocketImpl_getTimeToLive(JNIEnv *env, jobject this) {
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 @@ Java_java_net_PlainDatagramSocketImpl_getTimeToLive(JNIEnv *env, jobject this) {
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 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
/*
* Determine if this is an IPv4 or IPv6 join/leave.
*/
#ifdef AF_INET6
ipv6_join_leave = ipv6_available();
#ifdef __linux__
@ -1965,13 +1913,6 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
}
#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 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
* NetworkInterface
*/
if (niObj != NULL) {
#if defined(__linux__) && defined(AF_INET6)
#if defined(__linux__)
if (ipv6_available()) {
static jfieldID ni_indexID;
@ -2052,7 +1993,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
if (niObj == NULL) {
#if defined(__linux__) && defined(AF_INET6)
#if defined(__linux__)
if (ipv6_available()) {
int index;
@ -2108,7 +2049,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
* 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 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
* 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 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
}
}
}
#endif
}
/*

View File

@ -162,11 +162,7 @@ Java_java_net_PlainSocketImpl_socketCreate(JNIEnv *env, jobject this,
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 @@ Java_java_net_PlainSocketImpl_socketCreate(JNIEnv *env, jobject this,
return;
}
#ifdef AF_INET6
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
int arg = 0;
@ -201,7 +196,6 @@ Java_java_net_PlainSocketImpl_socketCreate(JNIEnv *env, jobject this,
return;
}
}
#endif /* AF_INET6 */
/*
* If this is a server socket then enable SO_REUSEADDR
@ -271,11 +265,10 @@ Java_java_net_PlainSocketImpl_socketConnect(JNIEnv *env, jobject this,
}
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__

View File

@ -56,11 +56,7 @@ static int create(JNIEnv* env)
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__)
/**

View File

@ -306,11 +306,6 @@ jint IPv6_supported()
jint IPv6_supported()
{
#ifndef AF_INET6
return JNI_FALSE;
#endif
#ifdef AF_INET6
int fd;
void *ipv6_fn;
SOCKETADDRESS sa;
@ -415,7 +410,6 @@ jint IPv6_supported()
} else {
return JNI_TRUE;
}
#endif /* AF_INET6 */
}
#endif /* DONT_ENABLE_IPV6 */
@ -466,7 +460,7 @@ void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
}
}
#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 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
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 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
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 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
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 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
* 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 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
}
}
#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 @@ NET_MapSocketOption(jint cmd, int *level, int *optname) {
int i;
#ifdef AF_INET6
if (ipv6_available()) {
switch (cmd) {
// Different multicast options if IPv6 is enabled
@ -1031,7 +1014,6 @@ NET_MapSocketOption(jint cmd, int *level, int *optname) {
#endif
}
}
#endif
/*
* Map the Java level option to the native level
@ -1063,7 +1045,7 @@ NET_MapSocketOption(jint cmd, int *level, int *optname) {
* 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 @@ NET_SetSockOpt(int fd, int level, int opt, const void *arg,
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 @@ NET_SetSockOpt(int fd, int level, int opt, const void *arg,
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 @@ NET_Bind(int fd, struct sockaddr *him, int len)
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 */

View File

@ -84,18 +84,11 @@ void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
#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 @@ typedef union {
#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);

View File

@ -305,8 +305,6 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
return ret;
}
#ifdef AF_INET6
/**
* ping implementation using tcp port 7 (echo)
*/
@ -468,7 +466,6 @@ ping6(JNIEnv *env,
return JNI_FALSE;
}
}
#endif /* AF_INET6 */
/*
* Class: java_net_Inet6AddressImpl
@ -482,7 +479,6 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
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 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
return ping6(env, netif, &him6, timeout, hIcmpFile);
}
#endif /* AF_INET6 */
return JNI_FALSE;
}