8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding

Reviewed-by: alanb, chegar
This commit is contained in:
Christoph Langer 2017-02-15 14:51:16 +01:00
parent d6fbebf0bf
commit a6cc06162b
3 changed files with 23 additions and 62 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, 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
@ -90,29 +90,16 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
#if defined(__solaris__)
rv = connect(fd, 0, 0);
#else
int len;
SOCKETADDRESS sa;
socklen_t len = isIPv6 ? sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in);
memset(&sa, 0, sizeof(sa));
#ifdef AF_INET6
if (isIPv6) {
#if defined(_ALLBSD_SOURCE)
sa.sa6.sin6_family = AF_INET6;
sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET;
#else
sa.sa6.sin6_family = AF_UNSPEC;
sa.sa.sa_family = AF_UNSPEC;
#endif
len = sizeof(struct sockaddr_in6);
} else
#endif
{
#if defined(_ALLBSD_SOURCE)
sa.sa4.sin_family = AF_INET;
#else
sa.sa4.sin_family = AF_UNSPEC;
#endif
len = sizeof(struct sockaddr_in);
}
rv = connect(fd, &sa.sa, len);
@ -126,8 +113,9 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
*/
if (rv < 0 && errno == EAFNOSUPPORT)
rv = errno = 0;
#endif
#endif
#endif // defined(_ALLBSD_SOURCE) || defined(_AIX)
#endif // defined(__solaris__)
if (rv < 0)
handleSocketError(env, errno);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2017, 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,8 @@
#include "sun_nio_ch_InheritedChannel.h"
static int matchFamily(struct sockaddr *sa) {
int family = sa->sa_family;
#ifdef AF_INET6
if (ipv6_available()) {
return (family == AF_INET6);
}
#endif
return (family == AF_INET);
static int matchFamily(SOCKETADDRESS *sa) {
return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET));
}
JNIEXPORT void JNICALL
@ -63,7 +57,7 @@ Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
jint remote_port;
if (getpeername(fd, &sa.sa, &len) == 0) {
if (matchFamily(&sa.sa)) {
if (matchFamily(&sa)) {
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
}
}
@ -71,7 +65,6 @@ Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
return remote_ia;
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
{
@ -80,7 +73,7 @@ Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
jint remote_port = -1;
if (getpeername(fd, &sa.sa, &len) == 0) {
if (matchFamily(&sa.sa)) {
if (matchFamily(&sa)) {
NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
}
}
@ -92,7 +85,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
{
int sotype;
socklen_t arglen=sizeof(sotype);
socklen_t arglen = sizeof(sotype);
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
if (sotype == SOCK_STREAM)
return sun_nio_ch_InheritedChannel_SOCK_STREAM;
@ -123,7 +116,7 @@ Java_sun_nio_ch_InheritedChannel_dup2(JNIEnv *env, jclass cla, jint fd, jint fd2
JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_open0(JNIEnv *env, jclass cla, jstring path, jint oflag)
{
const char* str;
const char *str;
int oflag_actual;
/* convert to OS specific value */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, 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
@ -101,23 +101,21 @@
* Copy IPv6 group, interface index, and IPv6 source address
* into group_source_req structure.
*/
#ifdef AF_INET6
static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index,
jbyteArray source, struct group_source_req* req)
jbyteArray source, struct group_source_req *req)
{
struct sockaddr_in6* sin6;
req->gsr_interface = (uint32_t)index;
sin6 = (struct sockaddr_in6*)&(req->gsr_group);
sin6 = (struct sockaddr_in6 *)&(req->gsr_group);
sin6->sin6_family = AF_INET6;
COPY_INET6_ADDRESS(env, group, (jbyte*)&(sin6->sin6_addr));
COPY_INET6_ADDRESS(env, group, (jbyte *)&(sin6->sin6_addr));
sin6 = (struct sockaddr_in6*)&(req->gsr_source);
sin6 = (struct sockaddr_in6 *)&(req->gsr_source);
sin6->sin6_family = AF_INET6;
COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr));
COPY_INET6_ADDRESS(env, source, (jbyte *)&(sin6->sin6_addr));
}
#endif
#ifdef _AIX
@ -199,18 +197,13 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
{
int fd;
int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
#ifdef AF_INET6
int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET;
#else
int domain = AF_INET;
#endif
fd = socket(domain, type, 0);
if (fd < 0) {
return handleSocketError(env, errno);
}
#ifdef AF_INET6
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
int arg = 0;
@ -223,7 +216,6 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
return -1;
}
}
#endif
if (reuse) {
int arg = 1;
@ -250,9 +242,7 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
return -1;
}
}
#endif
#if defined(__linux__) && defined(AF_INET6)
/* By default, Linux uses the route default */
if (domain == AF_INET6 && type == SOCK_DGRAM) {
int arg = 1;
@ -569,7 +559,6 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobject fdo,
jbyteArray group, jint index, jbyteArray source)
{
#ifdef AF_INET6
struct ipv6_mreq mreq6;
struct group_source_req req;
int opt, n, optlen;
@ -600,21 +589,16 @@ Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobjec
handleSocketError(env, errno);
}
return 0;
#else
JNU_ThrowInternalError(env, "Should not get here");
return IOS_THROWN;
#endif /* AF_INET6 */
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo,
jbyteArray group, jint index, jbyteArray source)
{
#ifdef AF_INET6
#ifdef __APPLE__
#ifdef __APPLE__
/* no IPv6 exclude-mode filtering for now */
return IOS_UNAVAILABLE;
#else
#else
struct group_source_req req;
int n;
int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE;
@ -629,10 +613,6 @@ Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, j
handleSocketError(env, errno);
}
return 0;
#endif
#else
JNU_ThrowInternalError(env, "Should not get here");
return IOS_THROWN;
#endif
}