--- a/jdk/src/java.base/share/native/libnet/net_util.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/share/native/libnet/net_util.c Fri Jan 13 13:12:21 2017 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -64,10 +64,10 @@
preferIPv4Stack = (*env)->CallStaticBooleanMethod(env, iCls, mid, s);
/*
- Since we have initialized and loaded the Socket library we will
- check now to whether we have IPv6 on this platform and if the
- supporting socket APIs are available
- */
+ * Since we have initialized and loaded the socket library we will
+ * check now whether we have IPv6 on this platform and if the
+ * supporting socket APIs are available
+ */
IPv6_available = IPv6_supported() & (!preferIPv4Stack);
/* check if SO_REUSEPORT is supported on this platform */
@@ -120,16 +120,16 @@
return JNI_TRUE;
}
-int getInet6Address_scopeid_set(JNIEnv *env, jobject iaObj) {
+jboolean getInet6Address_scopeid_set(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
- CHECK_NULL_RETURN(holder, -1);
+ CHECK_NULL_RETURN(holder, JNI_FALSE);
return (*env)->GetBooleanField(env, holder, ia6_scopeidsetID);
}
-int getInet6Address_scopeid(JNIEnv *env, jobject iaObj) {
+unsigned int getInet6Address_scopeid(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
- CHECK_NULL_RETURN(holder, -1);
- return (*env)->GetIntField(env, holder, ia6_scopeidID);
+ CHECK_NULL_RETURN(holder, 0);
+ return (unsigned int)(*env)->GetIntField(env, holder, ia6_scopeidID);
}
jboolean setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) {
@@ -201,11 +201,10 @@
}
JNIEXPORT jobject JNICALL
-NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
+NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port) {
jobject iaObj;
- if (him->sa_family == AF_INET6) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- jbyte *caddr = (jbyte *)&(him6->sin6_addr);
+ if (sa->sa.sa_family == AF_INET6) {
+ jbyte *caddr = (jbyte *)&sa->sa6.sin6_addr;
if (NET_IsIPv4Mapped(caddr)) {
int address;
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
@@ -214,42 +213,35 @@
setInetAddress_addr(env, iaObj, address);
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
} else {
- jint scope;
jboolean ret;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
CHECK_NULL_RETURN(iaObj, NULL);
- ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
+ ret = setInet6Address_ipaddress(env, iaObj, (char *)&sa->sa6.sin6_addr);
if (ret == JNI_FALSE)
return NULL;
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv6);
- scope = getScopeID(him);
- setInet6Address_scopeid(env, iaObj, scope);
+ setInet6Address_scopeid(env, iaObj, sa->sa6.sin6_scope_id);
}
- *port = ntohs(him6->sin6_port);
+ *port = ntohs(sa->sa6.sin6_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);
+ setInetAddress_addr(env, iaObj, ntohl(sa->sa4.sin_addr.s_addr));
+ *port = ntohs(sa->sa4.sin_port);
}
return iaObj;
}
-JNIEXPORT jint JNICALL
-NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
+JNIEXPORT jboolean JNICALL
+NET_SockaddrEqualsInetAddress(JNIEnv *env, SOCKETADDRESS *sa, jobject iaObj)
{
- jint family = AF_INET;
-
- family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
- AF_INET : AF_INET6;
- if (him->sa_family == AF_INET6) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- jbyte *caddrNew = (jbyte *)&(him6->sin6_addr);
+ jint family = getInetAddress_family(env, iaObj) ==
+ java_net_InetAddress_IPv4 ? AF_INET : AF_INET6;
+ if (sa->sa.sa_family == AF_INET6) {
+ jbyte *caddrNew = (jbyte *)&sa->sa6.sin6_addr;
if (NET_IsIPv4Mapped(caddrNew)) {
- int addrNew;
- int addrCur;
+ int addrNew, addrCur;
if (family == AF_INET6) {
return JNI_FALSE;
}
@@ -262,26 +254,24 @@
}
} else {
jbyte caddrCur[16];
- int scope;
-
if (family == AF_INET) {
return JNI_FALSE;
}
- scope = getInet6Address_scopeid(env, iaObj);
getInet6Address_ipaddress(env, iaObj, (char *)caddrCur);
- if (NET_IsEqual(caddrNew, caddrCur) && cmpScopeID(scope, him)) {
+ if (NET_IsEqual(caddrNew, caddrCur) &&
+ sa->sa6.sin6_scope_id == getInet6Address_scopeid(env, iaObj))
+ {
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);
+ addrNew = ntohl(sa->sa4.sin_addr.s_addr);
addrCur = getInetAddress_addr(env, iaObj);
if (addrNew == addrCur) {
return JNI_TRUE;
@@ -291,6 +281,15 @@
}
}
+JNIEXPORT jint JNICALL
+NET_GetPortFromSockaddr(SOCKETADDRESS *sa) {
+ if (sa->sa.sa_family == AF_INET6) {
+ return ntohs(sa->sa6.sin6_port);
+ } else {
+ return ntohs(sa->sa4.sin_port);
+ }
+}
+
unsigned short
in_cksum(unsigned short *addr, int len) {
int nleft = len;
--- a/jdk/src/java.base/share/native/libnet/net_util.h Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/share/native/libnet/net_util.h Fri Jan 13 13:12:21 2017 +0100
@@ -63,8 +63,8 @@
*/
extern jobject getInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj);
extern jboolean setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname);
-extern int getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj);
-extern int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj);
+extern jboolean getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj);
+extern unsigned int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj);
extern jboolean setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid);
extern jboolean getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest);
extern jboolean setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address);
@@ -132,24 +132,41 @@
JNIEXPORT jint JNICALL reuseport_available();
+/**
+ * This function will fill a SOCKETADDRESS structure from an InetAddress
+ * object.
+ *
+ * The parameter 'sa' must point to valid storage of size
+ * 'sizeof(SOCKETADDRESS)'.
+ *
+ * The parameter 'len' is a pointer to an int and is used for returning
+ * the actual sockaddr length, e.g. 'sizeof(struct sockaddr_in)' or
+ * 'sizeof(struct sockaddr_in6)'.
+ *
+ * If the type of the InetAddress object is IPv6, the function will fill a
+ * sockaddr_in6 structure. IPv6 must be available in that case, otherwise an
+ * exception is thrown.
+ * In the case of an IPv4 InetAddress, when IPv6 is available and
+ * v4MappedAddress is TRUE, this method will fill a sockaddr_in6 structure
+ * containing an IPv4 mapped IPv6 address. Otherwise a sockaddr_in
+ * structure will be filled.
+ */
JNIEXPORT int JNICALL
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
- struct sockaddr *him, int *len,
+ SOCKETADDRESS *sa, int *len,
jboolean v4MappedAddress);
JNIEXPORT jobject JNICALL
-NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port);
+NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port);
void platformInit();
void parseExclusiveBindProperty(JNIEnv *env);
-void NET_SetTrafficClass(struct sockaddr *him, int trafficClass);
+JNIEXPORT jint JNICALL NET_GetPortFromSockaddr(SOCKETADDRESS *sa);
-JNIEXPORT jint JNICALL NET_GetPortFromSockaddr(struct sockaddr *him);
-
-JNIEXPORT jint JNICALL
-NET_SockaddrEqualsInetAddress(JNIEnv *env,struct sockaddr *him, jobject iaObj);
+JNIEXPORT jboolean JNICALL
+NET_SockaddrEqualsInetAddress(JNIEnv *env, SOCKETADDRESS *sa, jobject iaObj);
int NET_IsIPv4Mapped(jbyte* caddr);
@@ -172,7 +189,7 @@
NET_SetSockOpt(int fd, int level, int opt, const void *arg, int len);
JNIEXPORT int JNICALL
-NET_Bind(int fd, struct sockaddr *him, int len);
+NET_Bind(int fd, SOCKETADDRESS *sa, int len);
JNIEXPORT int JNICALL
NET_MapSocketOption(jint cmd, int *level, int *optname);
@@ -183,10 +200,6 @@
JNIEXPORT jint JNICALL
NET_EnableFastTcpLoopback(int fd);
-int getScopeID(struct sockaddr *);
-
-int cmpScopeID(unsigned int, struct sockaddr *);
-
unsigned short in_cksum(unsigned short *addr, int len);
jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
--- a/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -211,7 +211,8 @@
{
int port;
int index = (family == AF_INET) ? i++ : j++;
- jobject o = NET_SockaddrToInetAddress(env, iter->ifa_addr, &port);
+ jobject o = NET_SockaddrToInetAddress(env,
+ (SOCKETADDRESS *)iter->ifa_addr, &port);
if (!o) {
freeifaddrs(ifa);
if (!(*env)->ExceptionCheck(env))
--- a/jdk/src/java.base/unix/native/libnet/NetworkInterface.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnet/NetworkInterface.c Fri Jan 13 13:12:21 2017 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -791,7 +791,7 @@
int sock;
sock = openSocket(env, AF_INET);
- if (sock < 0 && (*env)->ExceptionOccurred(env)) {
+ if (sock < 0) {
return NULL;
}
@@ -809,7 +809,7 @@
// so we have to call ipv6_available()
if (ipv6_available()) {
sock = openSocket(env, AF_INET6);
- if (sock < 0 && (*env)->ExceptionOccurred(env)) {
+ if (sock < 0) {
freeif(ifs);
return NULL;
}
--- a/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -99,7 +99,7 @@
CHECK_NULL_RETURN(i_class, NULL);
}
- return ( (*env)->NewObject(env, i_class, i_ctrID, i) );
+ return (*env)->NewObject(env, i_class, i_ctrID, i);
}
/*
@@ -118,10 +118,9 @@
CHECK_NULL_RETURN(b_class, NULL);
}
- return( (*env)->NewObject(env, b_class, b_ctrID, (jboolean)(b!=0)) );
+ return (*env)->NewObject(env, b_class, b_ctrID, (jboolean)(b != 0));
}
-
/*
* Returns the fd for a PlainDatagramSocketImpl or -1
* if closed.
@@ -134,7 +133,6 @@
return (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
-
/*
* Class: java_net_PlainDatagramSocketImpl
* Method: init
@@ -166,7 +164,6 @@
initInetAddressIDs(env);
JNU_CHECK_EXCEPTION(env);
Java_java_net_NetworkInterface_init(env, 0);
-
}
/*
@@ -176,13 +173,13 @@
*/
JNIEXPORT void JNICALL
Java_java_net_PlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
- jint localport, jobject iaObj) {
+ jint localport, jobject iaObj) {
/* fdObj is the FileDescriptor field on this */
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
/* fd is an int field on fdObj */
int fd;
int len = 0;
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
socklen_t slen = sizeof(SOCKETADDRESS);
if (IS_NULL(fdObj)) {
@@ -199,12 +196,13 @@
}
/* bind */
- if (NET_InetAddressToSockaddr(env, iaObj, localport, &him.sa, &len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, localport, &sa, &len,
+ JNI_TRUE) != 0) {
return;
}
- setDefaultScopeID(env, &him.sa);
+ setDefaultScopeID(env, &sa.sa);
- if (NET_Bind(fd, &him.sa, len) < 0) {
+ if (NET_Bind(fd, &sa, len) < 0) {
if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
errno == EPERM || errno == EACCES) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
@@ -221,13 +219,13 @@
/* Now that we're a connected socket, let's extract the port number
* that the system chose for us and store it in the Socket object.
*/
- if (getsockname(fd, &him.sa, &slen) == -1) {
+ if (getsockname(fd, &sa.sa, &slen) == -1) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
return;
}
- localport = NET_GetPortFromSockaddr(&him.sa);
+ localport = NET_GetPortFromSockaddr(&sa);
(*env)->SetIntField(env, this, pdsi_localPortID, localport);
} else {
@@ -263,7 +261,8 @@
return;
}
- if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr.sa, &len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr, &len,
+ JNI_TRUE) != 0) {
return;
}
@@ -290,6 +289,9 @@
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
SOCKETADDRESS addr;
socklen_t len;
+#if defined(__linux__)
+ int localPort = 0;
+#endif
#endif
if (IS_NULL(fdObj)) {
@@ -298,32 +300,31 @@
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
- memset(&addr, 0, sizeof(addr));
- if (ipv6_available()) {
- addr.sa6.sin6_family = AF_UNSPEC;
- len = sizeof(struct sockaddr_in6);
- } else {
- addr.sa4.sin_family = AF_UNSPEC;
- len = sizeof(struct sockaddr_in);
- }
- NET_Connect(fd, &addr.sa, len);
+ memset(&addr, 0, sizeof(addr));
+ if (ipv6_available()) {
+ addr.sa6.sin6_family = AF_UNSPEC;
+ len = sizeof(struct sockaddr_in6);
+ } else {
+ addr.sa4.sin_family = AF_UNSPEC;
+ len = sizeof(struct sockaddr_in);
+ }
+ NET_Connect(fd, &addr.sa, len);
-#ifdef __linux__
- int localPort = 0;
- if (getsockname(fd, &addr.sa, &len) == -1)
- return;
+#if defined(__linux__)
+ if (getsockname(fd, &addr.sa, &len) == -1)
+ return;
- localPort = NET_GetPortFromSockaddr(&addr.sa);
- if (localPort == 0) {
- localPort = (*env)->GetIntField(env, this, pdsi_localPortID);
- if (addr.sa.sa_family == AF_INET6) {
- addr.sa6.sin6_port = htons(localPort);
- } else {
- addr.sa4.sin_port = htons(localPort);
- }
+ localPort = NET_GetPortFromSockaddr(&addr);
+ if (localPort == 0) {
+ localPort = (*env)->GetIntField(env, this, pdsi_localPortID);
+ if (addr.sa.sa_family == AF_INET6) {
+ addr.sa6.sin6_port = htons(localPort);
+ } else {
+ addr.sa4.sin_port = htons(localPort);
+ }
- NET_Bind(fd, &addr.sa, len);
- }
+ NET_Bind(fd, &addr, len);
+ }
#endif
#else
@@ -355,8 +356,9 @@
/* The fdObj'fd */
jint fd;
- SOCKETADDRESS rmtaddr, *rmtaddrP = &rmtaddr;
- int len;
+ SOCKETADDRESS rmtaddr;
+ struct sockaddr *rmtaddrP = 0;
+ int len = 0;
if (IS_NULL(fdObj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -382,15 +384,14 @@
packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID);
packetBufferLen = (*env)->GetIntField(env, packet, dp_lengthID);
- if (connected) {
- /* arg to NET_Sendto () null in this case */
- len = 0;
- rmtaddrP = 0;
- } else {
+ // arg to NET_Sendto() null, if connected
+ if (!connected) {
packetPort = (*env)->GetIntField(env, packet, dp_portID);
- if (NET_InetAddressToSockaddr(env, packetAddress, packetPort, &rmtaddr.sa, &len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, packetAddress, packetPort, &rmtaddr,
+ &len, JNI_TRUE) != 0) {
return;
}
+ rmtaddrP = &rmtaddr.sa;
}
setDefaultScopeID(env, &rmtaddr.sa);
@@ -427,7 +428,7 @@
(*env)->GetByteArrayRegion(env, packetBuffer, packetBufferOffset, packetBufferLen,
(jbyte *)fullPacket);
if (trafficClass != 0 && ipv6_available()) {
- NET_SetTrafficClass(&rmtaddr.sa, trafficClass);
+ NET_SetTrafficClass(&rmtaddr, trafficClass);
}
/*
@@ -437,8 +438,7 @@
* ECONNREFUSED indicating that an ICMP port unreachable has
* received.
*/
- ret = NET_SendTo(fd, fullPacket, packetBufferLen, 0,
- (struct sockaddr *)rmtaddrP, len);
+ ret = NET_SendTo(fd, fullPacket, packetBufferLen, 0, rmtaddrP, len);
if (ret < 0) {
if (errno == ECONNREFUSED) {
@@ -510,7 +510,7 @@
#ifdef __solaris__
if (errno == ECONNREFUSED) {
int orig_errno = errno;
- (void) recv(fd, buf, 1, 0);
+ recv(fd, buf, 1, 0);
errno = orig_errno;
}
#endif
@@ -528,7 +528,7 @@
return 0;
}
- iaObj = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &rmtaddr, &port);
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
AF_INET : AF_INET6;
if (family == AF_INET) { /* this API can't handle IPV6 addresses */
@@ -676,18 +676,18 @@
*/
packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
if (packetAddress != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr.sa, packetAddress)) {
+ if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr, packetAddress)) {
/* force a new InetAddress to be created */
packetAddress = NULL;
}
}
if (packetAddress == NULL) {
- packetAddress = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
+ packetAddress = NET_SockaddrToInetAddress(env, &rmtaddr, &port);
/* stuff the new Inetaddress in the packet */
(*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
} else {
/* only get the new port number */
- port = NET_GetPortFromSockaddr(&rmtaddr.sa);
+ port = NET_GetPortFromSockaddr(&rmtaddr);
}
/* and fill in the data, remote address/port and such */
(*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
@@ -857,18 +857,19 @@
*/
packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
if (packetAddress != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr.sa, packetAddress)) {
+ if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr,
+ packetAddress)) {
/* force a new InetAddress to be created */
packetAddress = NULL;
}
}
if (packetAddress == NULL) {
- packetAddress = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
+ packetAddress = NET_SockaddrToInetAddress(env, &rmtaddr, &port);
/* stuff the new Inetaddress in the packet */
(*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
} else {
/* only get the new port number */
- port = NET_GetPortFromSockaddr(&rmtaddr.sa);
+ port = NET_GetPortFromSockaddr(&rmtaddr);
}
/* and fill in the data, remote address/port and such */
(*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
@@ -1040,6 +1041,7 @@
/*
* We need an ipv4 address here
*/
+ in.s_addr = 0;
for (i = 0; i < len; i++) {
addr = (*env)->GetObjectArrayElement(env, addrArray, i);
if (getInetAddress_family(env, addr) == java_net_InetAddress_IPv4) {
@@ -1049,7 +1051,7 @@
}
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
- (const char*)&in, sizeof(in)) < 0) {
+ (const char *)&in, sizeof(in)) < 0) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error setting socket option");
}
@@ -1670,17 +1672,17 @@
*/
if (opt == java_net_SocketOptions_SO_BINDADDR) {
/* find out local IP address */
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
socklen_t len = sizeof(SOCKETADDRESS);
int port;
jobject iaObj;
- if (getsockname(fd, &him.sa, &len) == -1) {
+ if (getsockname(fd, &sa.sa, &len) == -1) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
return NULL;
}
- iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &sa, &port);
return iaObj;
}
@@ -1969,6 +1971,7 @@
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
#ifdef __linux__
mname.imr_address.s_addr = htonl(getInetAddress_addr(env, addr));
+ mname.imr_ifindex = 0;
#else
mname.imr_interface.s_addr = htonl(getInetAddress_addr(env, addr));
#endif
@@ -2023,7 +2026,7 @@
#ifdef __linux__
mname.imr_address.s_addr = in.s_addr;
-
+ mname.imr_ifindex = 0;
#else
mname.imr_interface.s_addr = in.s_addr;
#endif
--- a/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -244,7 +244,7 @@
/* fd is an int field on iaObj */
jint fd;
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
/* The result of the connection */
int connect_rv = -1;
@@ -260,17 +260,18 @@
}
/* connect */
- if (NET_InetAddressToSockaddr(env, iaObj, port, &him.sa, &len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa, &len,
+ JNI_TRUE) != 0) {
return;
}
- setDefaultScopeID(env, &him.sa);
+ setDefaultScopeID(env, &sa.sa);
if (trafficClass != 0 && ipv6_available()) {
- NET_SetTrafficClass(&him.sa, trafficClass);
+ NET_SetTrafficClass(&sa, trafficClass);
}
if (timeout <= 0) {
- connect_rv = NET_Connect(fd, &him.sa, len);
+ connect_rv = NET_Connect(fd, &sa.sa, len);
#ifdef __solaris__
if (connect_rv == -1 && errno == EINPROGRESS ) {
@@ -319,7 +320,7 @@
SET_NONBLOCKING(fd);
/* no need to use NET_Connect as non-blocking */
- connect_rv = connect(fd, &him.sa, len);
+ connect_rv = connect(fd, &sa.sa, len);
/* connection not established immediately */
if (connect_rv != 0) {
@@ -467,11 +468,11 @@
* that the system chose for us and store it in the Socket object.
*/
socklen_t slen = sizeof(SOCKETADDRESS);
- if (getsockname(fd, &him.sa, &slen) == -1) {
+ if (getsockname(fd, &sa.sa, &slen) == -1) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
} else {
- localport = NET_GetPortFromSockaddr(&him.sa);
+ localport = NET_GetPortFromSockaddr(&sa);
(*env)->SetIntField(env, this, psi_localportID, localport);
}
}
@@ -490,8 +491,8 @@
jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
/* fd is an int field on fdObj */
int fd;
- int len;
- SOCKETADDRESS him;
+ int len = 0;
+ SOCKETADDRESS sa;
if (IS_NULL(fdObj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -506,13 +507,13 @@
}
/* bind */
- if (NET_InetAddressToSockaddr(env, iaObj, localport, &him.sa,
+ if (NET_InetAddressToSockaddr(env, iaObj, localport, &sa,
&len, JNI_TRUE) != 0) {
return;
}
- setDefaultScopeID(env, &him.sa);
+ setDefaultScopeID(env, &sa.sa);
- if (NET_Bind(fd, &him.sa, len) < 0) {
+ if (NET_Bind(fd, &sa, len) < 0) {
if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
errno == EPERM || errno == EACCES) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
@@ -533,12 +534,12 @@
/* Now that we're a connected socket, let's extract the port number
* that the system chose for us and store it in the Socket object.
*/
- if (getsockname(fd, &him.sa, &slen) == -1) {
+ if (getsockname(fd, &sa.sa, &slen) == -1) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
return;
}
- localport = NET_GetPortFromSockaddr(&him.sa);
+ localport = NET_GetPortFromSockaddr(&sa);
(*env)->SetIntField(env, this, psi_localportID, localport);
} else {
(*env)->SetIntField(env, this, psi_localportID, localport);
@@ -606,7 +607,7 @@
/* accepted fd */
jint newfd;
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
socklen_t slen = sizeof(SOCKETADDRESS);
if (IS_NULL(fdObj)) {
@@ -661,7 +662,7 @@
return;
}
- newfd = NET_Accept(fd, &him.sa, &slen);
+ newfd = NET_Accept(fd, &sa.sa, &slen);
/* connection accepted */
if (newfd >= 0) {
@@ -709,7 +710,7 @@
/*
* fill up the remote peer port and address in the new socket structure.
*/
- socketAddressObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
+ socketAddressObj = NET_SockaddrToInetAddress(env, &sa, &port);
if (socketAddressObj == NULL) {
/* should be pending exception */
close(newfd);
@@ -944,19 +945,19 @@
* SO_BINDADDR isn't a socket option
*/
if (cmd == java_net_SocketOptions_SO_BINDADDR) {
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
socklen_t len = sizeof(SOCKETADDRESS);
int port;
jobject iaObj;
jclass iaCntrClass;
jfieldID iaFieldID;
- if (getsockname(fd, &him.sa, &len) < 0) {
+ if (getsockname(fd, &sa.sa, &len) < 0) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
return -1;
}
- iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &sa, &port);
CHECK_NULL_RETURN(iaObj, -1);
iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj);
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.c Fri Jan 13 13:12:21 2017 +0100
@@ -234,29 +234,6 @@
}
return kernelV24;
}
-
-int getScopeID (struct sockaddr *him) {
- struct sockaddr_in6 *hext = (struct sockaddr_in6 *)him;
- return hext->sin6_scope_id;
-}
-
-int cmpScopeID (unsigned int scope, struct sockaddr *him) {
- struct sockaddr_in6 *hext = (struct sockaddr_in6 *)him;
- return hext->sin6_scope_id == scope;
-}
-
-#else
-
-int getScopeID (struct sockaddr *him) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- return him6->sin6_scope_id;
-}
-
-int cmpScopeID (unsigned int scope, struct sockaddr *him) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- return him6->sin6_scope_id == scope;
-}
-
#endif
void
@@ -775,30 +752,32 @@
return 0;
}
-/* In the case of an IPv4 Inetaddress this method will return an
- * IPv4 mapped address where IPv6 is available and v4MappedAddress is TRUE.
- * Otherwise it will return a sockaddr_in structure for an IPv4 InetAddress.
-*/
+/**
+ * See net_util.h for documentation
+ */
JNIEXPORT int JNICALL
-NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him,
- int *len, jboolean v4MappedAddress) {
- jint family;
- family = getInetAddress_family(env, iaObj);
- /* needs work. 1. family 2. clean up him6 etc deallocate memory */
- if (ipv6_available() && !(family == java_net_InetAddress_IPv4 &&
- v4MappedAddress == JNI_FALSE)) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
+NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
+ SOCKETADDRESS *sa, int *len,
+ jboolean v4MappedAddress)
+{
+ jint family = getInetAddress_family(env, iaObj);
+ memset((char *)sa, 0, sizeof(SOCKETADDRESS));
+
+ if (ipv6_available() &&
+ !(family == java_net_InetAddress_IPv4 &&
+ v4MappedAddress == JNI_FALSE))
+ {
jbyte caddr[16];
jint address;
if (family == java_net_InetAddress_IPv4) {
// convert to IPv4-mapped address
- memset((char *) caddr, 0, 16);
+ memset((char *)caddr, 0, 16);
address = getInetAddress_addr(env, iaObj);
if (address == INADDR_ANY) {
/* we would always prefer IPv6 wildcard address
- caddr[10] = 0xff;
- caddr[11] = 0xff; */
+ * caddr[10] = 0xff;
+ * caddr[11] = 0xff; */
} else {
caddr[10] = 0xff;
caddr[11] = 0xff;
@@ -810,22 +789,19 @@
} else {
getInet6Address_ipaddress(env, iaObj, (char *)caddr);
}
- memset((char *)him6, 0, sizeof(struct sockaddr_in6));
- 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);
+ sa->sa6.sin6_port = htons(port);
+ memcpy((void *)&sa->sa6.sin6_addr, caddr, sizeof(struct in6_addr));
+ sa->sa6.sin6_family = AF_INET6;
+ if (len != NULL) {
+ *len = sizeof(struct sockaddr_in6);
+ }
-#if defined(_ALLBSD_SOURCE)
-// XXXBSD: should we do something with scope id here ? see below linux comment
-/* MMM: Come back to this! */
-#endif
-
+#ifdef __linux__
/*
* On Linux if we are connecting to a link-local address
* we need to specify the interface in the scope_id (2.4 kernel only)
*
- * If the scope was cached the we use the cached value. If not cached but
+ * If the scope was cached then we use the cached value. If not cached but
* specified in the Inet6Address we use that, but we first check if the
* address needs to be routed via the loopback interface. In this case,
* we override the specified value with that of the loopback interface.
@@ -833,9 +809,8 @@
* we try to determine a value from the routing table. In all these
* cases the used value is cached for further use.
*/
-#ifdef __linux__
- if (IN6_IS_ADDR_LINKLOCAL(&(him6->sin6_addr))) {
- int cached_scope_id = 0, scope_id = 0;
+ if (IN6_IS_ADDR_LINKLOCAL(&sa->sa6.sin6_addr)) {
+ unsigned int cached_scope_id = 0, scope_id = 0;
if (ia6_cachedscopeidID) {
cached_scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID);
@@ -850,7 +825,7 @@
/* check user-specified value for loopback case
* that needs to be overridden
*/
- if (kernelIsV24() && needsLoopbackRoute (&him6->sin6_addr)) {
+ if (kernelIsV24() && needsLoopbackRoute(&sa->sa6.sin6_addr)) {
cached_scope_id = lo_scope_id;
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id);
}
@@ -860,11 +835,11 @@
* try determine the appropriate interface.
*/
if (kernelIsV24()) {
- cached_scope_id = getDefaultIPv6Interface(&(him6->sin6_addr));
+ cached_scope_id = getDefaultIPv6Interface(&sa->sa6.sin6_addr);
} else {
- cached_scope_id = getLocalScopeID((char *)&(him6->sin6_addr));
+ cached_scope_id = getLocalScopeID((char *)&(sa->sa6.sin6_addr));
if (cached_scope_id == 0) {
- cached_scope_id = getDefaultIPv6Interface(&(him6->sin6_addr));
+ cached_scope_id = getDefaultIPv6Interface(&sa->sa6.sin6_addr);
}
}
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id);
@@ -876,53 +851,37 @@
* If we have a scope_id use the extended form
* of sockaddr_in6.
*/
-
- struct sockaddr_in6 *him6 =
- (struct sockaddr_in6 *)him;
- him6->sin6_scope_id = cached_scope_id != 0 ?
- cached_scope_id : scope_id;
- *len = sizeof(struct sockaddr_in6);
+ sa->sa6.sin6_scope_id = cached_scope_id == 0 ? scope_id : cached_scope_id;
}
#else
- /* handle scope_id for solaris */
-
+ /* handle scope_id */
if (family != java_net_InetAddress_IPv4) {
if (ia6_scopeidID) {
- him6->sin6_scope_id = getInet6Address_scopeid(env, iaObj);
+ sa->sa6.sin6_scope_id = getInet6Address_scopeid(env, iaObj);
}
}
#endif
} else {
- struct sockaddr_in *him4 = (struct sockaddr_in *)him;
jint address;
- if (family == java_net_InetAddress_IPv6) {
+ if (family != java_net_InetAddress_IPv4) {
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);
+ sa->sa4.sin_port = htons(port);
+ sa->sa4.sin_addr.s_addr = htonl(address);
+ sa->sa4.sin_family = AF_INET;
+ if (len != NULL) {
+ *len = sizeof(struct sockaddr_in);
+ }
}
return 0;
}
void
-NET_SetTrafficClass(struct sockaddr *him, int trafficClass) {
- if (him->sa_family == AF_INET6) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- him6->sin6_flowinfo = htonl((trafficClass & 0xff) << 20);
- }
-}
-
-JNIEXPORT jint JNICALL
-NET_GetPortFromSockaddr(struct sockaddr *him) {
- if (him->sa_family == AF_INET6) {
- return ntohs(((struct sockaddr_in6*)him)->sin6_port);
- } else {
- return ntohs(((struct sockaddr_in*)him)->sin_port);
+NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass) {
+ if (sa->sa.sa_family == AF_INET6) {
+ sa->sa6.sin6_flowinfo = htonl((trafficClass & 0xff) << 20);
}
}
@@ -1488,7 +1447,7 @@
*
*/
int
-NET_Bind(int fd, struct sockaddr *him, int len)
+NET_Bind(int fd, SOCKETADDRESS *sa, int len)
{
#if defined(__solaris__)
int level = -1;
@@ -1503,9 +1462,8 @@
* ## When IPv6 is enabled this will be an IPv4-mapped
* ## with family set to AF_INET6
*/
- if (him->sa_family == AF_INET) {
- struct sockaddr_in *sa = (struct sockaddr_in *)him;
- if ((ntohl(sa->sin_addr.s_addr) & 0x7f0000ff) == 0x7f0000ff) {
+ if (sa->sa.sa_family == AF_INET) {
+ if ((ntohl(sa->sa4.sin_addr.s_addr) & 0x7f0000ff) == 0x7f0000ff) {
errno = EADDRNOTAVAIL;
return -1;
}
@@ -1524,8 +1482,9 @@
*/
alen = sizeof(arg);
- if (useExclBind || getsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
- (char *)&arg, &alen) == 0) {
+ if (useExclBind ||
+ getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&arg, &alen) == 0)
+ {
if (useExclBind || arg == 0) {
/*
* SO_REUSEADDR is disabled or sun.net.useExclusiveBind
@@ -1533,8 +1492,8 @@
* UDP_EXCLBIND
*/
alen = sizeof(arg);
- if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&arg,
- &alen) == 0) {
+ if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&arg, &alen) == 0)
+ {
if (arg == SOCK_STREAM) {
level = IPPROTO_TCP;
exclbind = TCP_EXCLBIND;
@@ -1545,14 +1504,13 @@
}
arg = 1;
- setsockopt(fd, level, exclbind, (char *)&arg,
- sizeof(arg));
+ setsockopt(fd, level, exclbind, (char *)&arg, sizeof(arg));
}
}
#endif
- rv = bind(fd, him, len);
+ rv = bind(fd, &sa->sa, len);
#if defined(__solaris__)
if (rv < 0) {
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.h Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.h Fri Jan 13 13:12:21 2017 +0100
@@ -30,32 +30,6 @@
#include <sys/poll.h>
#include <sys/socket.h>
-int NET_Timeout(int s, long timeout);
-int NET_Timeout0(int s, long timeout, long currentTime);
-int NET_Read(int s, void* buf, size_t len);
-int NET_NonBlockingRead(int s, void* buf, size_t len);
-int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime);
-long NET_GetCurrentTime();
-int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
- struct sockaddr *from, socklen_t *fromlen);
-int NET_ReadV(int s, const struct iovec * vector, int count);
-int NET_Send(int s, void *msg, int len, unsigned int flags);
-int NET_SendTo(int s, const void *msg, int len, unsigned int
- flags, const struct sockaddr *to, int tolen);
-int NET_Writev(int s, const struct iovec * vector, int count);
-int NET_Connect(int s, struct sockaddr *addr, int addrlen);
-int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
-int NET_SocketClose(int s);
-int NET_Dup2(int oldfd, int newfd);
-int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
-int NET_SocketAvailable(int s, jint *pbytes);
-
-void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
- const char* hostname,
- int gai_error);
-void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
- const char *defaultDetail);
-
/************************************************************************
* Macros and constants
*/
@@ -91,9 +65,36 @@
} SOCKETADDRESS;
/************************************************************************
- * Utilities
+ * Functions
*/
+int NET_Timeout(int s, long timeout);
+int NET_Timeout0(int s, long timeout, long currentTime);
+int NET_Read(int s, void* buf, size_t len);
+int NET_NonBlockingRead(int s, void* buf, size_t len);
+int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime);
+long NET_GetCurrentTime();
+int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
+ struct sockaddr *from, socklen_t *fromlen);
+int NET_ReadV(int s, const struct iovec * vector, int count);
+int NET_Send(int s, void *msg, int len, unsigned int flags);
+int NET_SendTo(int s, const void *msg, int len, unsigned int
+ flags, const struct sockaddr *to, int tolen);
+int NET_Writev(int s, const struct iovec * vector, int count);
+int NET_Connect(int s, struct sockaddr *addr, int addrlen);
+int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
+int NET_SocketClose(int s);
+int NET_Dup2(int oldfd, int newfd);
+int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
+int NET_SocketAvailable(int s, jint *pbytes);
+
+void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
+ const char* hostname,
+ int gai_error);
+void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
+ const char *defaultDetail);
+void NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass);
+
#ifdef __linux__
int kernelIsV24();
int getDefaultIPv6Interface(struct in6_addr *target_addr);
--- a/jdk/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -181,11 +181,11 @@
*/
senderAddr = (*env)->GetObjectField(env, this, dci_senderAddrID);
if (senderAddr != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, &sa.sa, senderAddr)) {
+ if (!NET_SockaddrEqualsInetAddress(env, &sa, senderAddr)) {
senderAddr = NULL;
} else {
jint port = (*env)->GetIntField(env, this, dci_senderPortID);
- if (port != NET_GetPortFromSockaddr(&sa.sa)) {
+ if (port != NET_GetPortFromSockaddr(&sa)) {
senderAddr = NULL;
}
}
@@ -193,7 +193,7 @@
if (senderAddr == NULL) {
jobject isa = NULL;
int port = 0;
- jobject ia = NET_SockaddrToInetAddress(env, &sa.sa, &port);
+ jobject ia = NET_SockaddrToInetAddress(env, &sa, &port);
if (ia != NULL) {
isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
}
@@ -201,7 +201,7 @@
(*env)->SetObjectField(env, this, dci_senderAddrID, ia);
(*env)->SetIntField(env, this, dci_senderPortID,
- NET_GetPortFromSockaddr(&sa.sa));
+ NET_GetPortFromSockaddr(&sa));
(*env)->SetObjectField(env, this, dci_senderID, isa);
}
return n;
@@ -215,14 +215,14 @@
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
SOCKETADDRESS sa;
- int sa_len = sizeof(SOCKETADDRESS);
+ int sa_len = 0;
jint n = 0;
if (len > MAX_PACKET_LEN) {
len = MAX_PACKET_LEN;
}
- if (NET_InetAddressToSockaddr(env, destAddress, destPort, &sa.sa,
+ if (NET_InetAddressToSockaddr(env, destAddress, destPort, &sa,
&sa_len, preferIPv6) != 0) {
return IOS_THROWN;
}
--- a/jdk/src/java.base/unix/native/libnio/ch/InheritedChannel.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnio/ch/InheritedChannel.c Fri Jan 13 13:12:21 2017 +0100
@@ -64,7 +64,7 @@
if (getpeername(fd, &sa.sa, &len) == 0) {
if (matchFamily(&sa.sa)) {
- remote_ia = NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port);
+ remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
}
}
@@ -81,7 +81,7 @@
if (getpeername(fd, &sa.sa, &len) == 0) {
if (matchFamily(&sa.sa)) {
- NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port);
+ NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
}
}
--- a/jdk/src/java.base/unix/native/libnio/ch/Net.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnio/ch/Net.c Fri Jan 13 13:12:21 2017 +0100
@@ -274,15 +274,15 @@
jboolean useExclBind, jobject iao, int port)
{
SOCKETADDRESS sa;
- int sa_len = sizeof(SOCKETADDRESS);
+ int sa_len = 0;
int rv = 0;
- if (NET_InetAddressToSockaddr(env, iao, port, &sa.sa, &sa_len,
+ if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len,
preferIPv6) != 0) {
return;
}
- rv = NET_Bind(fdval(env, fdo), &sa.sa, sa_len);
+ rv = NET_Bind(fdval(env, fdo), &sa, sa_len);
if (rv != 0) {
handleSocketError(env, errno);
}
@@ -300,10 +300,10 @@
jobject fdo, jobject iao, jint port)
{
SOCKETADDRESS sa;
- int sa_len = sizeof(SOCKETADDRESS);
+ int sa_len = 0;
int rv;
- if (NET_InetAddressToSockaddr(env, iao, port, &sa.sa, &sa_len,
+ if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len,
preferIPv6) != 0) {
return IOS_THROWN;
}
@@ -349,7 +349,7 @@
return -1;
#endif /* _ALLBSD_SOURCE */
}
- return NET_GetPortFromSockaddr(&sa.sa);
+ return NET_GetPortFromSockaddr(&sa);
}
JNIEXPORT jobject JNICALL
@@ -382,7 +382,7 @@
return NULL;
#endif /* _ALLBSD_SOURCE */
}
- return NET_SockaddrToInetAddress(env, &sa.sa, &port);
+ return NET_SockaddrToInetAddress(env, &sa, &port);
}
JNIEXPORT jint JNICALL
--- a/jdk/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -112,7 +112,7 @@
}
(*env)->SetIntField(env, newfdo, fd_fdID, newfd);
- remote_ia = NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port);
+ remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
CHECK_NULL_RETURN(isa, IOS_THROWN);
--- a/jdk/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -53,7 +53,7 @@
break;
}
if (recvfrom(fd, buf, 1, MSG_PEEK,
- (struct sockaddr *)&rmtaddr, &addrlen) != SOCKET_ERROR) {
+ &rmtaddr.sa, &addrlen) != SOCKET_ERROR) {
break;
}
if (WSAGetLastError() != WSAECONNRESET) {
@@ -61,7 +61,7 @@
break;
}
- recvfrom(fd, buf, 1, 0, (struct sockaddr *)&rmtaddr, &addrlen);
+ recvfrom(fd, buf, 1, 0, &rmtaddr.sa, &addrlen);
got_icmp = JNI_TRUE;
}
@@ -134,14 +134,13 @@
JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketBind
(JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port, jboolean exclBind) {
SOCKETADDRESS sa;
- int rv;
- int sa_len = sizeof(sa);
+ int rv, sa_len = 0;
- if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&sa,
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
&sa_len, JNI_TRUE) != 0) {
return;
}
- rv = NET_WinBind(fd, (struct sockaddr *)&sa, sa_len, exclBind);
+ rv = NET_WinBind(fd, &sa, sa_len, exclBind);
if (rv == SOCKET_ERROR) {
if (WSAGetLastError() == WSAEACCES) {
@@ -159,17 +158,15 @@
JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketConnect
(JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port) {
SOCKETADDRESS sa;
- int rv;
- int sa_len = sizeof(sa);
+ int rv, sa_len = 0, t = TRUE;
DWORD x1, x2; /* ignored result codes */
- int t = TRUE;
- if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&sa,
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
&sa_len, JNI_TRUE) != 0) {
return;
}
- rv = connect(fd, (struct sockaddr *)&sa, sa_len);
+ rv = connect(fd, &sa.sa, sa_len);
if (rv == SOCKET_ERROR) {
NET_ThrowNew(env, WSAGetLastError(), "connect");
return;
@@ -192,7 +189,7 @@
int t = FALSE;
memset(&sa, 0, sa_len);
- connect(fd, (struct sockaddr *)&sa, sa_len);
+ connect(fd, &sa.sa, sa_len);
/* see comment in socketCreate */
WSAIoctl(fd, SIO_UDP_CONNRESET, &t, sizeof(t), &x1, sizeof(x1), &x2, 0, 0);
@@ -219,7 +216,7 @@
SOCKETADDRESS sa;
int len = sizeof(sa);
- if (getsockname(fd, (struct sockaddr *)&sa, &len) == SOCKET_ERROR) {
+ if (getsockname(fd, &sa.sa, &len) == SOCKET_ERROR) {
NET_ThrowNew(env, WSAGetLastError(), "getsockname");
return -1;
}
@@ -238,12 +235,12 @@
jobject iaObj;
int port;
- if (getsockname(fd, (struct sockaddr *)&sa, &len) == SOCKET_ERROR) {
+ if (getsockname(fd, &sa.sa, &len) == SOCKET_ERROR) {
NET_ThrowNew(env, WSAGetLastError(), "Error getting socket name");
return NULL;
}
- iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &sa, &port);
return iaObj;
}
@@ -316,7 +313,7 @@
/* receive the packet */
rv = recvfrom(fd, fullPacket, packetBufferLen, flags,
- (struct sockaddr *)&sa, &sa_len);
+ &sa.sa, &sa_len);
if (rv == SOCKET_ERROR && (WSAGetLastError() == WSAECONNRESET)) {
/* An icmp port unreachable - we must receive this as Windows
@@ -383,15 +380,13 @@
*/
packetAddress = (*env)->GetObjectField(env, dpObj, dp_addressID);
if (packetAddress != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&sa,
- packetAddress)) {
+ if (!NET_SockaddrEqualsInetAddress(env, &sa, packetAddress)) {
/* force a new InetAddress to be created */
packetAddress = NULL;
}
}
if (packetAddress == NULL) {
- packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa,
- &port);
+ packetAddress = NET_SockaddrToInetAddress(env, &sa, &port);
if (packetAddress != NULL) {
/* stuff the new Inetaddress into the packet */
(*env)->SetObjectField(env, dpObj, dp_addressID, packetAddress);
@@ -422,20 +417,18 @@
(JNIEnv *env, jclass clazz, jint fd, jbyteArray data, jint offset, jint length,
jobject iaObj, jint port, jboolean connected) {
SOCKETADDRESS sa;
- int sa_len = sizeof(sa);
- SOCKETADDRESS *sap = &sa;
+ int rv, sa_len = 0;
+ struct sockaddr *sap = 0;
char BUF[MAX_BUFFER_LEN];
char *fullPacket;
- int rv;
- if (connected) {
- sap = 0; /* arg to sendto () null in this case */
- sa_len = 0;
- } else {
- if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&sa,
- &sa_len, JNI_TRUE) != 0) {
+ // if already connected, sap arg to sendto() is null
+ if (!connected) {
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
+ &sa_len, JNI_TRUE) != 0) {
return;
}
+ sap = &sa.sa;
}
if (length > MAX_BUFFER_LEN) {
@@ -456,7 +449,7 @@
(*env)->GetByteArrayRegion(env, data, offset, length,
(jbyte *)fullPacket);
- rv = sendto(fd, fullPacket, length, 0, (struct sockaddr *)sap, sa_len);
+ rv = sendto(fd, fullPacket, length, 0, sap, sa_len);
if (rv == SOCKET_ERROR) {
if (rv == -1) {
NET_ThrowNew(env, WSAGetLastError(), "Datagram send failed");
--- a/jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -89,15 +89,14 @@
jboolean exclBind)
{
SOCKETADDRESS sa;
- int rv;
- int sa_len = sizeof(sa);
+ int rv, sa_len = 0;
- if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&sa,
- &sa_len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
+ &sa_len, JNI_TRUE) != 0) {
return;
}
- rv = NET_WinBind(fd, (struct sockaddr *)&sa, sa_len, exclBind);
+ rv = NET_WinBind(fd, &sa, sa_len, exclBind);
if (rv == SOCKET_ERROR)
NET_ThrowNew(env, WSAGetLastError(), "NET_Bind");
@@ -111,15 +110,14 @@
JNIEXPORT jint JNICALL Java_java_net_DualStackPlainSocketImpl_connect0
(JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port) {
SOCKETADDRESS sa;
- int rv;
- int sa_len = sizeof(sa);
+ int rv, sa_len = 0;
- if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&sa,
- &sa_len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
+ &sa_len, JNI_TRUE) != 0) {
return -1;
}
- rv = connect(fd, (struct sockaddr *)&sa, sa_len);
+ rv = connect(fd, &sa.sa, sa_len);
if (rv == SOCKET_ERROR) {
int err = WSAGetLastError();
if (err == WSAEWOULDBLOCK) {
@@ -217,7 +215,7 @@
SOCKETADDRESS sa;
int len = sizeof(sa);
- if (getsockname(fd, (struct sockaddr *)&sa, &len) == SOCKET_ERROR) {
+ if (getsockname(fd, &sa.sa, &len) == SOCKET_ERROR) {
if (WSAGetLastError() == WSAENOTSOCK) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Socket closed");
@@ -243,11 +241,11 @@
jclass iaContainerClass;
jfieldID iaFieldID;
- if (getsockname(fd, (struct sockaddr *)&sa, &len) == SOCKET_ERROR) {
+ if (getsockname(fd, &sa.sa, &len) == SOCKET_ERROR) {
NET_ThrowNew(env, WSAGetLastError(), "Error getting socket name");
return;
}
- iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &sa, &port);
CHECK_NULL(iaObj);
iaContainerClass = (*env)->GetObjectClass(env, iaContainerObj);
@@ -283,7 +281,7 @@
int len = sizeof(sa);
memset((char *)&sa, 0, len);
- newfd = accept(fd, (struct sockaddr *)&sa, &len);
+ newfd = accept(fd, &sa.sa, &len);
if (newfd == INVALID_SOCKET) {
if (WSAGetLastError() == -2) {
@@ -298,7 +296,7 @@
SetHandleInformation((HANDLE)(UINT_PTR)newfd, HANDLE_FLAG_INHERIT, 0);
- ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+ ia = NET_SockaddrToInetAddress(env, &sa, &port);
isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
(*env)->SetObjectArrayElement(env, isaa, 0, isa);
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -420,18 +420,13 @@
jboolean exclBind) {
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
jobject fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
-
- int fd, fd1 = -1, family;
int ipv6_supported = ipv6_available();
-
+ int fd, fd1 = -1, lcladdrlen = 0;
SOCKETADDRESS lcladdr;
- int lcladdrlen = sizeof(SOCKETADDRESS);
- int address;
- memset((char *)&lcladdr, 0, sizeof(lcladdr));
-
- family = getInetAddress_family(env, addressObj);
- if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
+ if (getInetAddress_family(env, addressObj) == java_net_InetAddress_IPv6 &&
+ !ipv6_supported)
+ {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Protocol family not supported");
return;
@@ -446,14 +441,13 @@
fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID);
}
}
+
if (IS_NULL(addressObj)) {
JNU_ThrowNullPointerException(env, "argument address");
return;
- } else {
- address = getInetAddress_addr(env, addressObj);
}
- if (NET_InetAddressToSockaddr(env, addressObj, port, &lcladdr.sa,
+ if (NET_InetAddressToSockaddr(env, addressObj, port, &lcladdr,
&lcladdrlen, JNI_FALSE) != 0) {
return;
}
@@ -493,7 +487,7 @@
return;
}
} else {
- if (NET_WinBind(fd, &lcladdr.sa, lcladdrlen, exclBind) == -1) {
+ if (NET_WinBind(fd, &lcladdr, lcladdrlen, exclBind) == -1) {
if (WSAGetLastError() == WSAEACCES) {
WSASetLastError(WSAEADDRINUSE);
}
@@ -507,7 +501,7 @@
NET_ThrowCurrent(env, "getsockname");
return;
}
- port = ntohs((u_short) GET_PORT (&lcladdr));
+ port = ntohs((u_short)GET_PORT(&lcladdr));
}
(*env)->SetIntField(env, this, pdsi_localPortID, port);
}
@@ -520,27 +514,25 @@
*/
JNIEXPORT void JNICALL
-Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject this,
- jobject address, jint port) {
- /* The object's field */
+Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0
+ (JNIEnv *env, jobject this, jobject address, jint port)
+{
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
jobject fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
- /* The fdObj'fd */
- jint fd=-1, fd1=-1, fdc;
- /* The packetAddress address, family and port */
- jint addr, family;
+ jint fd = -1, fd1 = -1, fdc, family;
SOCKETADDRESS rmtaddr;
- int rmtaddrlen;
- int ipv6_supported = ipv6_available();
+ int rmtaddrlen = 0;
if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Socket closed");
return;
}
+
if (!IS_NULL(fdObj)) {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
+
if (!IS_NULL(fd1Obj)) {
fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID);
}
@@ -550,10 +542,8 @@
return;
}
- addr = getInetAddress_addr(env, address);
-
family = getInetAddress_family(env, address);
- if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
+ if (family == java_net_InetAddress_IPv6 && !ipv6_available()) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Protocol family not supported");
return;
@@ -572,12 +562,12 @@
res = WSAIoctl(fdc,SIO_UDP_CONNRESET,&t,sizeof(t),&x1,sizeof(x1),&x2,0,0);
}
- if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr.sa,
+ if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr,
&rmtaddrlen, JNI_FALSE) != 0) {
return;
}
- if (connect(fdc, &rmtaddr.sa, sizeof(rmtaddr)) == -1) {
+ if (connect(fdc, &rmtaddr.sa, rmtaddrlen) == -1) {
NET_ThrowCurrent(env, "connect");
return;
}
@@ -631,9 +621,9 @@
* Signature: (Ljava/net/DatagramPacket;)V
*/
JNIEXPORT void JNICALL
-Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
- jobject packet) {
-
+Java_java_net_TwoStacksPlainDatagramSocketImpl_send
+ (JNIEnv *env, jobject this, jobject packet)
+{
char BUF[MAX_BUFFER_LEN];
char *fullPacket;
jobject fdObj;
@@ -647,11 +637,10 @@
jbyteArray packetBuffer;
jboolean connected;
- SOCKETADDRESS rmtaddr, *addrp = &rmtaddr;
+ SOCKETADDRESS rmtaddr;
+ struct sockaddr *addrp = 0;
int addrlen = 0;
- memset((char *)&rmtaddr, 0, sizeof(rmtaddr));
-
if (IS_NULL(packet)) {
JNU_ThrowNullPointerException(env, "null packet");
return;
@@ -696,14 +685,13 @@
packetBufferLen = MAX_PACKET_LEN;
}
- if (connected) {
- addrp = 0; /* arg to sendto () null in this case */
- addrlen = 0;
- } else {
- if (NET_InetAddressToSockaddr(env, iaObj, packetPort, &rmtaddr.sa,
+ // sockaddr arg to sendto() is null if already connected
+ if (!connected) {
+ if (NET_InetAddressToSockaddr(env, iaObj, packetPort, &rmtaddr,
&addrlen, JNI_FALSE) != 0) {
return;
}
+ addrp = &rmtaddr.sa;
}
if (packetBufferLen > MAX_BUFFER_LEN) {
@@ -753,11 +741,12 @@
fullPacket = &(BUF[0]);
}
- (*env)->GetByteArrayRegion(env, packetBuffer, packetBufferOffset, packetBufferLen,
- (jbyte *)fullPacket);
- if (sendto(fd, fullPacket, packetBufferLen, 0,
- (struct sockaddr *)addrp, addrlen) == SOCKET_ERROR) {
- NET_ThrowCurrent(env, "Datagram send failed");
+ (*env)->GetByteArrayRegion(env, packetBuffer, packetBufferOffset,
+ packetBufferLen, (jbyte *)fullPacket);
+ if (sendto(fd, fullPacket, packetBufferLen, 0, addrp,
+ addrlen) == SOCKET_ERROR)
+ {
+ NET_ThrowCurrent(env, "Datagram send failed");
}
if (packetBufferLen > MAX_BUFFER_LEN) {
@@ -1147,14 +1136,14 @@
*/
packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
if (packetAddress != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, &remote_addr.sa,
+ if (!NET_SockaddrEqualsInetAddress(env, &remote_addr,
packetAddress)) {
/* force a new InetAddress to be created */
packetAddress = NULL;
}
}
if (packetAddress == NULL) {
- packetAddress = NET_SockaddrToInetAddress(env, &remote_addr.sa,
+ packetAddress = NET_SockaddrToInetAddress(env, &remote_addr,
&port);
/* stuff the new Inetaddress in the packet */
(*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
@@ -1431,20 +1420,21 @@
* can't update any existing InetAddress because it is immutable
*/
packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
-
if (packetAddress != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, &remote_addr.sa, packetAddress)) {
+ if (!NET_SockaddrEqualsInetAddress(env, &remote_addr,
+ packetAddress)) {
/* force a new InetAddress to be created */
packetAddress = NULL;
}
}
if (packetAddress == NULL) {
- packetAddress = NET_SockaddrToInetAddress(env, &remote_addr.sa, &port);
+ packetAddress = NET_SockaddrToInetAddress(env, &remote_addr,
+ &port);
/* stuff the new Inetaddress in the packet */
(*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
} else {
/* only get the new port number */
- port = NET_GetPortFromSockaddr(&remote_addr.sa);
+ port = NET_GetPortFromSockaddr(&remote_addr);
}
/* populate the packet */
(*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
@@ -1528,7 +1518,7 @@
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
jobject fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
int ipv6_supported = ipv6_available();
- int fd=-1, fd1=-1;
+ int fd = -1, fd1 = -1;
if (IS_NULL(fdObj) && (!ipv6_supported || IS_NULL(fd1Obj))) {
return;
@@ -1799,7 +1789,7 @@
Java_java_net_TwoStacksPlainDatagramSocketImpl_socketNativeSetOption
(JNIEnv *env,jobject this, jint opt,jobject value)
{
- int fd=-1, fd1=-1;
+ int fd = -1, fd1 = -1;
int levelv4 = 0, levelv6 = 0, optnamev4 = 0, optnamev6 = 0, optlen = 0;
union {
int i;
@@ -2167,7 +2157,7 @@
Java_java_net_TwoStacksPlainDatagramSocketImpl_socketGetOption
(JNIEnv *env, jobject this, jint opt)
{
- int fd=-1, fd1=-1;
+ int fd = -1, fd1 = -1;
int level, optname, optlen;
union {
int i;
@@ -2255,7 +2245,7 @@
(JNIEnv *env, jobject this, jint family)
{
int fd = -1, fd1 = -1;
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
int len = 0;
int port;
jobject iaObj;
@@ -2288,12 +2278,12 @@
return NULL;
}
- if (getsockname(fd, &him.sa, &len) == -1) {
+ if (getsockname(fd, &sa.sa, &len) == -1) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
return NULL;
}
- iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &sa, &port);
return iaObj;
}
@@ -2430,7 +2420,7 @@
int len, family;
int ipv6_supported = ipv6_available();
- int cmd ;
+ int cmd;
memset((char *)&in, 0, sizeof(in));
memset((char *)&name, 0, sizeof(name));
@@ -2452,7 +2442,7 @@
return;
}
- if (NET_InetAddressToSockaddr(env, iaObj, 0, &name.sa, &len, JNI_FALSE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, 0, &name, &len, JNI_FALSE) != 0) {
return;
}
@@ -2473,7 +2463,7 @@
return;
}
if (IS_NULL(niObj)) {
- len = sizeof (in);
+ len = sizeof(in);
if (NET_GetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF,
(char *)&in, &len) < 0) {
NET_ThrowCurrent(env, "get IP_MULTICAST_IF failed");
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -175,8 +175,8 @@
*/
JNIEXPORT void JNICALL
Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this,
- jobject iaObj, jint port,
- jint timeout)
+ jobject iaObj, jint port,
+ jint timeout)
{
jint localport = (*env)->GetIntField(env, this, psi_localportID);
@@ -193,11 +193,11 @@
jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
/* The result of the connection */
int connect_res;
- memset((char *)&him, 0, sizeof(him));
+ memset((char *)&sa, 0, sizeof(sa));
if (!IS_NULL(fdObj)) {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
@@ -212,11 +212,12 @@
return;
}
- if (NET_InetAddressToSockaddr(env, iaObj, port, &him.sa, &len, JNI_FALSE) != 0) {
- return;
+ if (NET_InetAddressToSockaddr(env, iaObj, port, &sa, &len,
+ JNI_FALSE) != 0) {
+ return;
}
- family = him.sa.sa_family;
+ family = sa.sa.sa_family;
if (family == AF_INET6) {
if (!ipv6_supported) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -248,7 +249,7 @@
(*env)->SetObjectField(env, this, psi_fd1ID, NULL);
if (timeout <= 0) {
- connect_res = connect(fd, &him.sa, sizeof(SOCKETADDRESS));
+ connect_res = connect(fd, &sa.sa, sizeof(SOCKETADDRESS));
if (connect_res == SOCKET_ERROR) {
connect_res = WSAGetLastError();
}
@@ -261,7 +262,7 @@
ioctlsocket(fd, FIONBIO, &optval);
/* initiate the connect */
- connect_res = connect(fd, &him.sa, sizeof(SOCKETADDRESS));
+ connect_res = connect(fd, &sa.sa, sizeof(SOCKETADDRESS));
if (connect_res == SOCKET_ERROR) {
if (WSAGetLastError() != WSAEWOULDBLOCK) {
connect_res = WSAGetLastError();
@@ -362,7 +363,7 @@
*/
u_short port;
int len = sizeof(SOCKETADDRESS);
- if (getsockname(fd, &him.sa, &len) == -1) {
+ if (getsockname(fd, &sa.sa, &len) == -1) {
if (WSAGetLastError() == WSAENOTSOCK) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Socket closed");
@@ -371,7 +372,7 @@
}
return;
}
- port = ntohs((u_short)GET_PORT(&him));
+ port = ntohs((u_short)GET_PORT(&sa));
(*env)->SetIntField(env, this, psi_localportID, (int) port);
}
}
@@ -396,7 +397,7 @@
int family;
int rv;
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
fdObj = (*env)->GetObjectField(env, this, psi_fdID);
fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
@@ -424,13 +425,13 @@
return;
}
- if (NET_InetAddressToSockaddr(env, iaObj, localport, &him.sa, &len,
+ if (NET_InetAddressToSockaddr(env, iaObj, localport, &sa, &len,
JNI_FALSE) != 0) {
return;
}
if (ipv6_supported) {
struct ipv6bind v6bind;
- v6bind.addr = &him;
+ v6bind.addr = &sa.sa;
v6bind.ipv4_fd = fd;
v6bind.ipv6_fd = fd1;
rv = NET_BindV6(&v6bind, exclBind);
@@ -462,7 +463,7 @@
(*env)->SetObjectField(env, this, psi_fd1ID, NULL);
}
} else {
- rv = NET_WinBind(fd, &him.sa, len, exclBind);
+ rv = NET_WinBind(fd, &sa, len, exclBind);
}
if (rv == -1) {
@@ -481,11 +482,11 @@
int len = sizeof(SOCKETADDRESS);
u_short port;
- if (getsockname(him.sa.sa_family == AF_INET ? fd: fd1, &him.sa, &len) == -1) {
+ if (getsockname(sa.sa.sa_family == AF_INET ? fd : fd1, &sa.sa, &len) == -1) {
NET_ThrowCurrent(env, "getsockname in plain socketBind");
return;
}
- port = ntohs((u_short) GET_PORT (&him));
+ port = ntohs((u_short) GET_PORT (&sa));
(*env)->SetIntField(env, this, psi_localportID, (int)port);
} else {
@@ -529,7 +530,7 @@
JNU_ThrowNullPointerException(env, "socket address");
return;
}
- if (NET_InetAddressToSockaddr(env, address, 0, &addr.sa, &addrlen,
+ if (NET_InetAddressToSockaddr(env, address, 0, &addr, &addrlen,
JNI_FALSE) != 0) {
return;
}
@@ -585,7 +586,7 @@
/* the fd int field on fdObj */
jint fd=-1, fd1=-1;
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
jint len;
if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) {
@@ -676,7 +677,7 @@
}
}
}
- fd = accept(fd, &him.sa, &len);
+ fd = accept(fd, &sa.sa, &len);
if (fd < 0) {
/* REMIND: SOCKET CLOSED PROBLEM */
if (fd == -2) {
@@ -691,7 +692,7 @@
SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, 0);
(*env)->SetIntField(env, socketFdObj, IO_fd_fdID, fd);
- if (him.sa.sa_family == AF_INET) {
+ if (sa.sa.sa_family == AF_INET) {
if (inet4Cls == NULL) {
jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
if (c != NULL) {
@@ -717,7 +718,7 @@
return;
}
- setInetAddress_addr(env, socketAddressObj, ntohl(him.sa4.sin_addr.s_addr));
+ setInetAddress_addr(env, socketAddressObj, ntohl(sa.sa4.sin_addr.s_addr));
setInetAddress_family(env, socketAddressObj, java_net_InetAddress_IPv4);
(*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj);
} else {
@@ -743,14 +744,14 @@
NET_SocketClose(fd);
return;
}
- setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.sa6.sin6_addr);
+ setInet6Address_ipaddress(env, socketAddressObj, (char *)&sa.sa6.sin6_addr);
setInetAddress_family(env, socketAddressObj, java_net_InetAddress_IPv6);
- setInet6Address_scopeid(env, socketAddressObj, him.sa6.sin6_scope_id);
+ setInet6Address_scopeid(env, socketAddressObj, sa.sa6.sin6_scope_id);
}
/* fields common to AF_INET and AF_INET6 */
- port = ntohs ((u_short) GET_PORT (&him));
+ port = ntohs ((u_short)GET_PORT(&sa));
(*env)->SetIntField(env, socket, psi_portID, (int)port);
port = (*env)->GetIntField(env, this, psi_localportID);
(*env)->SetIntField(env, socket, psi_localportID, port);
@@ -1025,14 +1026,14 @@
* SO_BINDADDR isn't a socket option
*/
if (opt == java_net_SocketOptions_SO_BINDADDR) {
- SOCKETADDRESS him;
+ SOCKETADDRESS sa;
int len = sizeof(SOCKETADDRESS);
int port;
jobject iaObj;
jclass iaCntrClass;
jfieldID iaFieldID;
- memset((char *)&him, 0, len);
+ memset((char *)&sa, 0, len);
if (fd == -1) {
/* must be an IPV6 only socket. Case where both sockets are != -1
@@ -1041,12 +1042,12 @@
fd = getFD1 (env, this);
}
- if (getsockname(fd, &him.sa, &len) < 0) {
+ if (getsockname(fd, &sa.sa, &len) < 0) {
JNU_ThrowByNameWithMessageAndLastError
(env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
return -1;
}
- iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
+ iaObj = NET_SockaddrToInetAddress(env, &sa, &port);
CHECK_NULL_RETURN(iaObj, -1);
iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj);
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.c Fri Jan 13 13:12:21 2017 +0100
@@ -488,10 +488,10 @@
* Should be only called by the wrapper method NET_WinBind
*/
JNIEXPORT int JNICALL
-NET_Bind(int s, struct sockaddr *him, int len)
+NET_Bind(int s, SOCKETADDRESS *sa, int len)
{
int rv = 0;
- rv = bind(s, him, len);
+ rv = bind(s, &sa->sa, len);
if (rv == SOCKET_ERROR) {
/*
@@ -511,11 +511,11 @@
* if required, and then calls NET_BIND
*/
JNIEXPORT int JNICALL
-NET_WinBind(int s, struct sockaddr *him, int len, jboolean exclBind)
+NET_WinBind(int s, SOCKETADDRESS *sa, int len, jboolean exclBind)
{
if (exclBind == JNI_TRUE)
setExclusiveBind(s);
- return NET_Bind(s, him, len);
+ return NET_Bind(s, sa, len);
}
JNIEXPORT int JNICALL
@@ -677,8 +677,8 @@
if (family == AF_INET && (b->addr->sa4.sin_addr.s_addr != INADDR_ANY)) {
/* bind to v4 only */
int ret;
- ret = NET_WinBind((int)b->ipv4_fd, (struct sockaddr *)b->addr,
- sizeof(SOCKETADDRESS), exclBind);
+ ret = NET_WinBind((int)b->ipv4_fd, b->addr,
+ sizeof(SOCKETADDRESS), exclBind);
if (ret == SOCKET_ERROR) {
CLOSE_SOCKETS_AND_RETURN;
}
@@ -689,7 +689,7 @@
if (family == AF_INET6 && (!IN6_IS_ADDR_ANY(&b->addr->sa6.sin6_addr))) {
/* bind to v6 only */
int ret;
- ret = NET_WinBind((int)b->ipv6_fd, (struct sockaddr *)b->addr,
+ ret = NET_WinBind((int)b->ipv6_fd, b->addr,
sizeof(SOCKETADDRESS), exclBind);
if (ret == SOCKET_ERROR) {
CLOSE_SOCKETS_AND_RETURN;
@@ -719,7 +719,7 @@
oaddr.sa4.sin_addr.s_addr = INADDR_ANY;
}
- rv = NET_WinBind(fd, (struct sockaddr *)b->addr, sizeof(SOCKETADDRESS), exclBind);
+ rv = NET_WinBind(fd, b->addr, sizeof(SOCKETADDRESS), exclBind);
if (rv == SOCKET_ERROR) {
CLOSE_SOCKETS_AND_RETURN;
}
@@ -731,7 +731,7 @@
}
bound_port = GET_PORT (b->addr);
SET_PORT (&oaddr, bound_port);
- if ((rv = NET_WinBind(ofd, &oaddr.sa,
+ if ((rv = NET_WinBind(ofd, &oaddr,
sizeof(SOCKETADDRESS), exclBind)) == SOCKET_ERROR) {
int retries;
int sotype, arglen=sizeof(sotype);
@@ -768,7 +768,7 @@
/* bind random port on first socket */
SET_PORT (&oaddr, 0);
- rv = NET_WinBind(ofd, &oaddr.sa, sizeof(SOCKETADDRESS), exclBind);
+ rv = NET_WinBind(ofd, &oaddr, sizeof(SOCKETADDRESS), exclBind);
if (rv == SOCKET_ERROR) {
CLOSE_SOCKETS_AND_RETURN;
}
@@ -784,8 +784,7 @@
}
bound_port = GET_PORT (&oaddr);
SET_PORT (b->addr, bound_port);
- rv = NET_WinBind(fd, (struct sockaddr *)b->addr,
- sizeof(SOCKETADDRESS), exclBind);
+ rv = NET_WinBind(fd, b->addr, sizeof(SOCKETADDRESS), exclBind);
if (rv != SOCKET_ERROR) {
if (family == AF_INET) {
@@ -853,31 +852,33 @@
return result == SOCKET_ERROR ? WSAGetLastError() : 0;
}
-/* If address types is IPv6, then IPv6 must be available. Otherwise
- * no address can be generated. In the case of an IPv4 Inetaddress this
- * method will return an IPv4 mapped address where IPv6 is available and
- * v4MappedAddress is TRUE. Otherwise it will return a sockaddr_in
- * structure for an IPv4 InetAddress.
-*/
+/**
+ * See net_util.h for documentation
+ */
JNIEXPORT int JNICALL
-NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him,
- int *len, jboolean v4MappedAddress) {
- jint family, iafam;
- iafam = getInetAddress_family(env, iaObj);
- family = (iafam == java_net_InetAddress_IPv4)? AF_INET : AF_INET6;
- if (ipv6_available() && !(family == AF_INET && v4MappedAddress == JNI_FALSE)) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
+NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
+ SOCKETADDRESS *sa, int *len,
+ jboolean v4MappedAddress)
+{
+ jint family = getInetAddress_family(env, iaObj);
+ memset((char *)sa, 0, sizeof(SOCKETADDRESS));
+
+ if (ipv6_available() &&
+ !(family == java_net_InetAddress_IPv4 &&
+ v4MappedAddress == JNI_FALSE))
+ {
jbyte caddr[16];
- jint address, scopeid = 0;
- jint cached_scope_id = 0;
+ jint address;
+ unsigned int scopeid = 0, cached_scope_id = 0;
- if (family == AF_INET) { /* will convert to IPv4-mapped address */
- memset((char *) caddr, 0, 16);
+ if (family == java_net_InetAddress_IPv4) {
+ // convert to IPv4-mapped address
+ memset((char *)caddr, 0, 16);
address = getInetAddress_addr(env, iaObj);
if (address == INADDR_ANY) {
/* we would always prefer IPv6 wildcard address
- caddr[10] = 0xff;
- caddr[11] = 0xff; */
+ * caddr[10] = 0xff;
+ * caddr[11] = 0xff; */
} else {
caddr[10] = 0xff;
caddr[11] = 0xff;
@@ -889,46 +890,39 @@
} else {
getInet6Address_ipaddress(env, iaObj, (char *)caddr);
scopeid = getInet6Address_scopeid(env, iaObj);
- cached_scope_id = (jint)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID);
+ cached_scope_id = (unsigned int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID);
}
-
- memset((char *)him6, 0, sizeof(struct sockaddr_in6));
- him6->sin6_port = (u_short) htons((u_short)port);
- memcpy((void *)&(him6->sin6_addr), caddr, sizeof(struct in6_addr) );
- him6->sin6_family = AF_INET6;
- if ((family == AF_INET6) && IN6_IS_ADDR_LINKLOCAL( &(him6->sin6_addr) )
- && (!scopeid && !cached_scope_id)) {
- cached_scope_id = getDefaultIPv6Interface(env, him6);
+ sa->sa6.sin6_port = (u_short)htons((u_short)port);
+ memcpy((void *)&sa->sa6.sin6_addr, caddr, sizeof(struct in6_addr));
+ sa->sa6.sin6_family = AF_INET6;
+ if ((family == java_net_InetAddress_IPv6) &&
+ IN6_IS_ADDR_LINKLOCAL(&sa->sa6.sin6_addr) &&
+ (!scopeid && !cached_scope_id))
+ {
+ cached_scope_id = getDefaultIPv6Interface(env, &sa->sa6);
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id);
}
- him6->sin6_scope_id = scopeid != 0 ? scopeid : cached_scope_id;
- *len = sizeof(struct sockaddr_in6) ;
+ sa->sa6.sin6_scope_id = scopeid == 0 ? cached_scope_id : scopeid;
+ if (len != NULL) {
+ *len = sizeof(struct sockaddr_in6);
+ }
} else {
- struct sockaddr_in *him4 = (struct sockaddr_in *)him;
jint address;
- if (family != AF_INET) {
- JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable");
- return -1;
+ if (family != java_net_InetAddress_IPv4) {
+ 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 = (u_long) htonl(address);
- him4->sin_family = AF_INET;
- *len = sizeof(struct sockaddr_in);
+ sa->sa4.sin_port = htons((short)port);
+ sa->sa4.sin_addr.s_addr = (u_long)htonl(address);
+ sa->sa4.sin_family = AF_INET;
+ if (len != NULL) {
+ *len = sizeof(struct sockaddr_in);
+ }
}
return 0;
}
-JNIEXPORT jint JNICALL
-NET_GetPortFromSockaddr(struct sockaddr *him) {
- if (him->sa_family == AF_INET6) {
- return ntohs(((struct sockaddr_in6 *)him)->sin6_port);
- } else {
- return ntohs(((struct sockaddr_in *)him)->sin_port);
- }
-}
-
int
NET_IsIPv4Mapped(jbyte* caddr) {
int i;
@@ -961,16 +955,6 @@
return 1;
}
-int getScopeID(struct sockaddr *him) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- return him6->sin6_scope_id;
-}
-
-int cmpScopeID(unsigned int scope, struct sockaddr *him) {
- struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
- return him6->sin6_scope_id == scope;
-}
-
/**
* Wrapper for select/poll with timeout on a single file descriptor.
*
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.h Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.h Fri Jan 13 13:12:21 2017 +0100
@@ -121,7 +121,7 @@
JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind *b, jboolean exclBind);
-JNIEXPORT int JNICALL NET_WinBind(int s, struct sockaddr *him, int len,
+JNIEXPORT int JNICALL NET_WinBind(int s, SOCKETADDRESS *sa, int len,
jboolean exclBind);
/* XP versions of the native routines */
--- a/jdk/src/java.base/windows/native/libnio/ch/DatagramChannelImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnio/ch/DatagramChannelImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -96,7 +96,7 @@
break;
}
if (recvfrom(fd, buf, 1, MSG_PEEK,
- (struct sockaddr *)&sa, &addrlen) != SOCKET_ERROR) {
+ &sa.sa, &addrlen) != SOCKET_ERROR) {
break;
}
if (WSAGetLastError() != WSAECONNRESET) {
@@ -104,7 +104,7 @@
break;
}
- recvfrom(fd, buf, 1, 0, (struct sockaddr *)&sa, &addrlen);
+ recvfrom(fd, buf, 1, 0, &sa.sa, &addrlen);
got_icmp = JNI_TRUE;
}
@@ -122,7 +122,7 @@
memset(&sa, 0, sa_len);
- rv = connect((SOCKET)fd, (struct sockaddr *)&sa, sa_len);
+ rv = connect((SOCKET)fd, &sa.sa, sa_len);
if (rv == SOCKET_ERROR) {
handleSocketError(env, WSAGetLastError());
} else {
@@ -153,7 +153,7 @@
(char *)buf,
len,
0,
- (struct sockaddr *)&sa,
+ &sa.sa,
&sa_len);
if (n == SOCKET_ERROR) {
@@ -182,12 +182,11 @@
*/
senderAddr = (*env)->GetObjectField(env, this, dci_senderAddrID);
if (senderAddr != NULL) {
- if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&sa,
- senderAddr)) {
+ if (!NET_SockaddrEqualsInetAddress(env, &sa, senderAddr)) {
senderAddr = NULL;
} else {
jint port = (*env)->GetIntField(env, this, dci_senderPortID);
- if (port != NET_GetPortFromSockaddr((struct sockaddr *)&sa)) {
+ if (port != NET_GetPortFromSockaddr(&sa)) {
senderAddr = NULL;
}
}
@@ -195,7 +194,7 @@
if (senderAddr == NULL) {
jobject isa = NULL;
int port;
- jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+ jobject ia = NET_SockaddrToInetAddress(env, &sa, &port);
if (ia != NULL) {
isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
}
@@ -204,7 +203,7 @@
// update cachedSenderInetAddress/cachedSenderPort
(*env)->SetObjectField(env, this, dci_senderAddrID, ia);
(*env)->SetIntField(env, this, dci_senderPortID,
- NET_GetPortFromSockaddr((struct sockaddr *)&sa));
+ NET_GetPortFromSockaddr(&sa));
(*env)->SetObjectField(env, this, dci_senderID, isa);
}
return n;
@@ -219,21 +218,15 @@
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
SOCKETADDRESS sa;
- int sa_len;
+ int sa_len = 0;
jint rv = 0;
- if (NET_InetAddressToSockaddr(env, destAddress, destPort,
- (struct sockaddr *)&sa,
- &sa_len, preferIPv6) != 0) {
+ if (NET_InetAddressToSockaddr(env, destAddress, destPort, &sa,
+ &sa_len, preferIPv6) != 0) {
return IOS_THROWN;
}
- rv = sendto((SOCKET)fd,
- buf,
- len,
- 0,
- (struct sockaddr *)&sa,
- sa_len);
+ rv = sendto((SOCKET)fd, buf, len, 0, &sa.sa, sa_len);
if (rv == SOCKET_ERROR) {
int theErr = (jint)WSAGetLastError();
if (theErr == WSAEWOULDBLOCK) {
--- a/jdk/src/java.base/windows/native/libnio/ch/Net.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnio/ch/Net.c Fri Jan 13 13:12:21 2017 +0100
@@ -168,13 +168,13 @@
{
SOCKETADDRESS sa;
int rv;
- int sa_len;
+ int sa_len = 0;
- if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) {
- return;
+ if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, preferIPv6) != 0) {
+ return;
}
- rv = NET_WinBind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len, isExclBind);
+ rv = NET_WinBind(fdval(env, fdo), &sa, sa_len, isExclBind);
if (rv == SOCKET_ERROR)
NET_ThrowNew(env, WSAGetLastError(), "bind");
}
@@ -194,14 +194,14 @@
{
SOCKETADDRESS sa;
int rv;
- int sa_len;
+ int sa_len = 0;
SOCKET s = (SOCKET)fdval(env, fdo);
- if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) {
+ if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, preferIPv6) != 0) {
return IOS_THROWN;
}
- rv = connect(s, (struct sockaddr *)&sa, sa_len);
+ rv = connect(s, &sa.sa, sa_len);
if (rv != 0) {
int err = WSAGetLastError();
if (err == WSAEINPROGRESS || err == WSAEWOULDBLOCK) {
@@ -226,7 +226,7 @@
SOCKETADDRESS sa;
int sa_len = sizeof(sa);
- if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+ if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
int error = WSAGetLastError();
if (error == WSAEINVAL) {
return 0;
@@ -234,7 +234,7 @@
NET_ThrowNew(env, error, "getsockname");
return IOS_THROWN;
}
- return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
+ return NET_GetPortFromSockaddr(&sa);
}
JNIEXPORT jobject JNICALL
@@ -244,11 +244,11 @@
int sa_len = sizeof(sa);
int port;
- if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+ if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
NET_ThrowNew(env, WSAGetLastError(), "getsockname");
return NULL;
}
- return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+ return NET_SockaddrToInetAddress(env, &sa, &port);
}
JNIEXPORT jint JNICALL
@@ -257,7 +257,7 @@
SOCKETADDRESS sa;
int sa_len = sizeof(sa);
- if (getpeername(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+ if (getpeername(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
int error = WSAGetLastError();
if (error == WSAEINVAL) {
return 0;
@@ -265,7 +265,7 @@
NET_ThrowNew(env, error, "getsockname");
return IOS_THROWN;
}
- return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
+ return NET_GetPortFromSockaddr(&sa);
}
JNIEXPORT jobject JNICALL
@@ -275,11 +275,11 @@
int sa_len = sizeof(sa);
int port;
- if (getpeername(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+ if (getpeername(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
NET_ThrowNew(env, WSAGetLastError(), "getsockname");
return NULL;
}
- return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+ return NET_SockaddrToInetAddress(env, &sa, &port);
}
JNIEXPORT jint JNICALL
--- a/jdk/src/java.base/windows/native/libnio/ch/ServerSocketChannelImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnio/ch/ServerSocketChannelImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -95,7 +95,7 @@
int addrlen = sizeof(sa);
memset((char *)&sa, 0, sizeof(sa));
- newfd = (jint)accept(ssfd, (struct sockaddr *)&sa, &addrlen);
+ newfd = (jint)accept(ssfd, &sa.sa, &addrlen);
if (newfd == INVALID_SOCKET) {
int theErr = (jint)WSAGetLastError();
if (theErr == WSAEWOULDBLOCK) {
@@ -107,7 +107,7 @@
SetHandleInformation((HANDLE)(UINT_PTR)newfd, HANDLE_FLAG_INHERIT, 0);
(*env)->SetIntField(env, newfdo, fd_fdID, newfd);
- remote_ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, (int *)&remote_port);
+ remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
--- a/jdk/src/java.base/windows/native/libnio/ch/WindowsAsynchronousSocketChannelImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/java.base/windows/native/libnio/ch/WindowsAsynchronousSocketChannelImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -88,26 +88,21 @@
Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_connect0(JNIEnv* env, jclass this,
jlong socket, jboolean preferIPv6, jobject iao, jint port, jlong ov)
{
- SOCKET s = (SOCKET) jlong_to_ptr(socket);
- OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov);
+ SOCKET s = (SOCKET)jlong_to_ptr(socket);
+ OVERLAPPED *lpOverlapped = (OVERLAPPED *)jlong_to_ptr(ov);
SOCKETADDRESS sa;
- int sa_len;
+ int sa_len = 0;
BOOL res;
- if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) {
+ if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len,
+ preferIPv6) != 0) {
return IOS_THROWN;
}
ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED));
- res = (*ConnectEx_func)(s,
- (struct sockaddr *)&sa,
- sa_len,
- NULL,
- 0,
- NULL,
- lpOverlapped);
+ res = (*ConnectEx_func)(s, &sa.sa, sa_len, NULL, 0, NULL, lpOverlapped);
if (res == 0) {
int error = GetLastError();
if (error == ERROR_IO_PENDING) {
--- a/jdk/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c Fri Jan 13 13:12:21 2017 +0100
@@ -418,7 +418,6 @@
(JNIEnv *env, jclass klass, jint fd, jobject resultContainerObj,
jlong address, jint length, jboolean peek) {
SOCKETADDRESS sa;
- int sa_len = sizeof(SOCKETADDRESS);
ssize_t rv = 0;
jlong *addr = jlong_to_ptr(address);
struct iovec iov[1];
@@ -429,7 +428,7 @@
/* Set up the msghdr structure for receiving */
memset(msg, 0, sizeof (*msg));
msg->msg_name = &sa;
- msg->msg_namelen = sa_len;
+ msg->msg_namelen = sizeof(sa);
iov->iov_base = addr;
iov->iov_len = length;
msg->msg_iov = iov;
@@ -538,7 +537,7 @@
jobject targetAddress, jint targetPort, jint assocId, jint streamNumber,
jboolean unordered, jint ppid) {
SOCKETADDRESS sa;
- int sa_len = sizeof(SOCKETADDRESS);
+ int sa_len = 0;
ssize_t rv = 0;
jlong *addr = jlong_to_ptr(address);
struct iovec iov[1];
@@ -555,13 +554,12 @@
* Association already existing, assocId != -1, targetAddress = preferred addr
*/
if (targetAddress != NULL /*&& assocId <= 0*/) {
- if (NET_InetAddressToSockaddr(env, targetAddress, targetPort, &sa.sa,
+ if (NET_InetAddressToSockaddr(env, targetAddress, targetPort, &sa,
&sa_len, JNI_TRUE) != 0) {
return IOS_THROWN;
}
} else {
- memset(&sa, '\x0', sa_len);
- sa_len = 0;
+ memset(&sa, '\x0', sizeof(sa));
}
/* Set up the msghdr structure for sending */
--- a/jdk/src/jdk.sctp/unix/native/libsctp/SctpNet.c Fri Jan 13 01:07:50 2017 -0800
+++ b/jdk/src/jdk.sctp/unix/native/libsctp/SctpNet.c Fri Jan 13 13:12:21 2017 +0100
@@ -211,22 +211,22 @@
(JNIEnv *env, jclass klass, jint fd, jobjectArray addrs, jint port,
jint addrsLength, jboolean add, jboolean preferIPv6) {
SOCKETADDRESS *sap, *tmpSap;
- int i, sa_len = sizeof(SOCKETADDRESS);
+ int i;
jobject ia;
if (addrsLength < 1)
return;
- if ((sap = calloc(addrsLength, sa_len)) == NULL) {
- JNU_ThrowOutOfMemoryError(env, "heap allocation failure");
+ if ((sap = calloc(addrsLength, sizeof(SOCKETADDRESS))) == NULL) {
+ JNU_ThrowOutOfMemoryError(env, "heap allocation failure");
return;
}
tmpSap = sap;
for (i = 0; i < addrsLength; i++) {
ia = (*env)->GetObjectArrayElement(env, addrs, i);
- if (NET_InetAddressToSockaddr(env, ia, port, (struct sockaddr*)tmpSap,
- &sa_len, preferIPv6) != 0) {
+ if (NET_InetAddressToSockaddr(env, ia, port, tmpSap, NULL,
+ preferIPv6) != 0) {
free(sap);
return;
}
@@ -262,11 +262,11 @@
Java_sun_nio_ch_sctp_SctpNet_connect0
(JNIEnv *env, jclass clazz, int fd, jobject iao, jint port) {
SOCKETADDRESS sa;
- int sa_len = sizeof(SOCKETADDRESS);
+ int sa_len = 0;
int rv;
- if (NET_InetAddressToSockaddr(env, iao, port, &sa.sa,
- &sa_len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len,
+ JNI_TRUE) != 0) {
return IOS_THROWN;
}
@@ -311,8 +311,7 @@
}
}
-void initializeISA
- (JNIEnv* env) {
+void initializeISA(JNIEnv* env) {
if (isaCls == 0) {
jclass c = (*env)->FindClass(env, "java/net/InetSocketAddress");
CHECK_NULL(c);
@@ -325,8 +324,7 @@
}
}
-jobject SockAddrToInetSocketAddress
- (JNIEnv *env, struct sockaddr* sap) {
+jobject SockAddrToInetSocketAddress(JNIEnv *env, SOCKETADDRESS *sap) {
int port = 0;
jobject ia = NET_SockaddrToInetAddress(env, sap, &port);
@@ -347,9 +345,9 @@
* Signature: (I)[Ljava/net/SocketAddress;
*/
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getLocalAddresses0
- (JNIEnv *env, jclass klass, jint fd) {
+ (JNIEnv *env, jclass klass, jint fd)
+{
void *addr_buf, *laddr;
- struct sockaddr* sap;
int i, addrCount;
jobjectArray isaa;
@@ -377,38 +375,35 @@
}
laddr = addr_buf;
- for (i=0; i<addrCount; i++) {
+ for (i = 0; i < addrCount; i++) {
int port = 0;
- jobject isa = NULL, ia;
- sap = (struct sockaddr*)addr_buf;
- ia = NET_SockaddrToInetAddress(env, sap, &port);
+ jobject ia, isa = NULL;
+ ia = NET_SockaddrToInetAddress(env, (SOCKETADDRESS *)addr_buf, &port);
if (ia != NULL)
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
if (isa == NULL)
break;
(*env)->SetObjectArrayElement(env, isaa, i, isa);
- if (sap->sa_family == AF_INET)
- addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
+ if (((struct sockaddr *)addr_buf)->sa_family == AF_INET)
+ addr_buf = ((struct sockaddr_in *)addr_buf) + 1;
else
- addr_buf = ((struct sockaddr_in6*)addr_buf) + 1;
+ addr_buf = ((struct sockaddr_in6 *)addr_buf) + 1;
}
nio_sctp_freeladdrs(laddr);
return isaa;
}
-jobjectArray getRemoteAddresses
- (JNIEnv *env, jint fd, sctp_assoc_t id) {
+jobjectArray getRemoteAddresses(JNIEnv *env, jint fd, sctp_assoc_t id) {
void *addr_buf, *paddr;
- struct sockaddr* sap;
int i, addrCount;
jobjectArray isaa;
#if __solaris__
if ((addrCount = nio_sctp_getpaddrs(fd, id, (void **)&addr_buf)) == -1) {
#else /* __linux__ */
- if ((addrCount = nio_sctp_getpaddrs(fd, id, (struct sockaddr**)&addr_buf)) == -1) {
+ if ((addrCount = nio_sctp_getpaddrs(fd, id, (struct sockaddr **)&addr_buf)) == -1) {
#endif
handleSocketError(env, errno);
return NULL;
@@ -429,25 +424,23 @@
}
paddr = addr_buf;
- for (i=0; i<addrCount; i++) {
- jobject ia, isa = NULL;
+ for (i = 0; i < addrCount; i++) {
int port = 0;
- sap = (struct sockaddr*)addr_buf;
- ia = NET_SockaddrToInetAddress(env, sap, &port);
+ jobject ia, isa = NULL;
+ ia = NET_SockaddrToInetAddress(env, (SOCKETADDRESS *)addr_buf, &port);
if (ia != NULL)
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
if (isa == NULL)
break;
(*env)->SetObjectArrayElement(env, isaa, i, isa);
- if (sap->sa_family == AF_INET)
- addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
+ if (((struct sockaddr *)addr_buf)->sa_family == AF_INET)
+ addr_buf = ((struct sockaddr_in *)addr_buf) + 1;
else
- addr_buf = ((struct sockaddr_in6*)addr_buf) + 1;
+ addr_buf = ((struct sockaddr_in6 *)addr_buf) + 1;
}
nio_sctp_freepaddrs(paddr);
-
return isaa;
}
@@ -579,7 +572,6 @@
(JNIEnv *env, jclass klass, jint fd, jint assocId) {
struct sctp_setprim prim;
unsigned int prim_len = sizeof(prim);
- struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr;
prim.ssp_assoc_id = assocId;
@@ -589,7 +581,7 @@
return NULL;
}
- return SockAddrToInetSocketAddress(env, sap);
+ return SockAddrToInetSocketAddress(env, (SOCKETADDRESS *)&prim.ssp_addr);
}
/*
@@ -600,11 +592,10 @@
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setPrimAddrOption0
(JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) {
struct sctp_setprim prim;
- struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr;
- int sap_len = sizeof(sap);
- if (NET_InetAddressToSockaddr(env, iaObj, port, sap,
- &sap_len, JNI_TRUE) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, port,
+ (SOCKETADDRESS *)&prim.ssp_addr,
+ NULL, JNI_TRUE) != 0) {
return;
}
@@ -625,18 +616,17 @@
(JNIEnv *env, jclass klass, jint fd, jint assocId,
jobject iaObj, jint port, jboolean preferIPv6) {
struct sctp_setpeerprim prim;
- struct sockaddr* sap = (struct sockaddr*)&prim.sspp_addr;
- int sap_len = sizeof(sap);
- if (NET_InetAddressToSockaddr(env, iaObj, port, sap,
- &sap_len, preferIPv6) != 0) {
+ if (NET_InetAddressToSockaddr(env, iaObj, port,
+ (SOCKETADDRESS *)&prim.sspp_addr,
+ NULL, preferIPv6) != 0) {
return;
}
prim.sspp_assoc_id = assocId;
if (setsockopt(fd, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &prim,
- sizeof(prim)) < 0) {
+ sizeof(prim)) < 0) {
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"sun.nio.ch.SctpNet.setPeerPrimAddrOption0");
}