提交 14d95380 编写于 作者: I igerasim

8193419: Better Internet address support

Reviewed-by: chegar, rriggs, igerasim, skoivu, rhalade
上级 403e3a8e
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -297,6 +297,22 @@ JNU_NotifyAll(JNIEnv *env, jobject object); ...@@ -297,6 +297,22 @@ JNU_NotifyAll(JNIEnv *env, jobject object);
} \ } \
} while (0) \ } while (0) \
#define CHECK_NULL_THROW_NPE(env, x, msg) \
do { \
if ((x) == NULL) { \
JNU_ThrowNullPointerException((env), (msg));\
return; \
} \
} while(0) \
#define CHECK_NULL_THROW_NPE_RETURN(env, x, msg, z)\
do { \
if ((x) == NULL) { \
JNU_ThrowNullPointerException((env), (msg));\
return (z); \
} \
} while(0) \
#define CHECK_NULL_RETURN(x, y) \ #define CHECK_NULL_RETURN(x, y) \
do { \ do { \
if ((x) == NULL) { \ if ((x) == NULL) { \
......
/* /*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -168,32 +168,38 @@ int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) { ...@@ -168,32 +168,38 @@ int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) {
void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) { void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
(*env)->SetIntField(env, holder, iac_addressID, address); (*env)->SetIntField(env, holder, iac_addressID, address);
} }
void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) { void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
(*env)->SetIntField(env, holder, iac_familyID, family); (*env)->SetIntField(env, holder, iac_familyID, family);
} }
void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) { void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
(*env)->SetObjectField(env, holder, iac_hostNameID, host); (*env)->SetObjectField(env, holder, iac_hostNameID, host);
(*env)->SetObjectField(env, holder, iac_origHostNameID, host); (*env)->SetObjectField(env, holder, iac_origHostNameID, host);
} }
int getInetAddress_addr(JNIEnv *env, jobject iaObj) { int getInetAddress_addr(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", -1);
return (*env)->GetIntField(env, holder, iac_addressID); return (*env)->GetIntField(env, holder, iac_addressID);
} }
int getInetAddress_family(JNIEnv *env, jobject iaObj) { int getInetAddress_family(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", -1);
return (*env)->GetIntField(env, holder, iac_familyID); return (*env)->GetIntField(env, holder, iac_familyID);
} }
jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) { jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID); jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", NULL);
return (*env)->GetObjectField(env, holder, iac_hostNameID); return (*env)->GetObjectField(env, holder, iac_hostNameID);
} }
...@@ -215,7 +221,9 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { ...@@ -215,7 +221,9 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
CHECK_NULL_RETURN(iaObj, NULL); CHECK_NULL_RETURN(iaObj, NULL);
address = NET_IPv4MappedToIPv4(caddr); address = NET_IPv4MappedToIPv4(caddr);
setInetAddress_addr(env, iaObj, address); setInetAddress_addr(env, iaObj, address);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
setInetAddress_family(env, iaObj, IPv4); setInetAddress_family(env, iaObj, IPv4);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
} else { } else {
jint scope; jint scope;
int ret; int ret;
...@@ -224,6 +232,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { ...@@ -224,6 +232,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr)); ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
CHECK_NULL_RETURN(ret, NULL); CHECK_NULL_RETURN(ret, NULL);
setInetAddress_family(env, iaObj, IPv6); setInetAddress_family(env, iaObj, IPv6);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
scope = getScopeID(him); scope = getScopeID(him);
setInet6Address_scopeid(env, iaObj, scope); setInet6Address_scopeid(env, iaObj, scope);
} }
...@@ -235,7 +244,9 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { ...@@ -235,7 +244,9 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
CHECK_NULL_RETURN(iaObj, NULL); CHECK_NULL_RETURN(iaObj, NULL);
setInetAddress_family(env, iaObj, IPv4); setInetAddress_family(env, iaObj, IPv4);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
*port = ntohs(him4->sin_port); *port = ntohs(him4->sin_port);
} }
return iaObj; return iaObj;
...@@ -248,6 +259,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj) ...@@ -248,6 +259,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
#ifdef AF_INET6 #ifdef AF_INET6
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6; family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
if (him->sa_family == AF_INET6) { if (him->sa_family == AF_INET6) {
#ifdef WIN32 #ifdef WIN32
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him; struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
...@@ -263,6 +275,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj) ...@@ -263,6 +275,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
} }
addrNew = NET_IPv4MappedToIPv4(caddrNew); addrNew = NET_IPv4MappedToIPv4(caddrNew);
addrCur = getInetAddress_addr(env, iaObj); addrCur = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
if (addrNew == addrCur) { if (addrNew == addrCur) {
return JNI_TRUE; return JNI_TRUE;
} else { } else {
...@@ -294,6 +307,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj) ...@@ -294,6 +307,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
} }
addrNew = ntohl(him4->sin_addr.s_addr); addrNew = ntohl(him4->sin_addr.s_addr);
addrCur = getInetAddress_addr(env, iaObj); addrCur = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
if (addrNew == addrCur) { if (addrNew == addrCur) {
return JNI_TRUE; return JNI_TRUE;
} else { } else {
......
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -236,7 +236,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -236,7 +236,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn; goto cleanupAndReturn;
} }
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)(iterator->ai_addr))->sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)(iterator->ai_addr))->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, name); setInetAddress_hostName(env, iaObj, name);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, retLen - i -1, iaObj); (*env)->SetObjectArrayElement(env, ret, retLen - i -1, iaObj);
i++; i++;
iterator = iterator->ai_next; iterator = iterator->ai_next;
...@@ -479,7 +483,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -479,7 +483,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn; goto cleanupAndReturn;
} }
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host); setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, i++, iaObj); (*env)->SetObjectArrayElement(env, ret, i++, iaObj);
iterator = iterator->ai_next; iterator = iterator->ai_next;
} }
......
/* /*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -221,6 +221,8 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6) ...@@ -221,6 +221,8 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
return NULL; return NULL;
} }
setInetAddress_hostName(env, o, name); setInetAddress_hostName(env, o, name);
if ((*env)->ExceptionCheck(env))
goto done;
(*env)->SetObjectArrayElement(env, result, index, o); (*env)->SetObjectArrayElement(env, result, index, o);
(*env)->DeleteLocalRef(env, o); (*env)->DeleteLocalRef(env, o);
} }
...@@ -411,7 +413,11 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -411,7 +413,11 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn; goto cleanupAndReturn;
} }
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host); setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj); (*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
inetIndex++; inetIndex++;
} else if (iterator->ai_family == AF_INET6) { } else if (iterator->ai_family == AF_INET6) {
...@@ -433,6 +439,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -433,6 +439,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
setInet6Address_scopeid(env, iaObj, scope); setInet6Address_scopeid(env, iaObj, scope);
} }
setInetAddress_hostName(env, iaObj, host); setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj); (*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj);
inet6Index++; inet6Index++;
} }
......
/* /*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -332,14 +332,14 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0 ...@@ -332,14 +332,14 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
(JNIEnv *env, jclass cls, jobject iaObj) (JNIEnv *env, jclass cls, jobject iaObj)
{ {
netif *ifs, *curr; netif *ifs, *curr;
jobject obj = NULL;
jboolean match = JNI_FALSE;
#if defined(AF_INET6) #if defined(AF_INET6)
int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6; int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
#else #else
int family = AF_INET; int family = AF_INET;
#endif #endif
jobject obj = NULL;
jboolean match = JNI_FALSE;
ifs = enumInterfaces(env); ifs = enumInterfaces(env);
if (ifs == NULL) { if (ifs == NULL) {
return NULL; return NULL;
...@@ -357,7 +357,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0 ...@@ -357,7 +357,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
int address1 = htonl( int address1 = htonl(
((struct sockaddr_in *)addrP->addr)->sin_addr.s_addr); ((struct sockaddr_in *)addrP->addr)->sin_addr.s_addr);
int address2 = getInetAddress_addr(env, iaObj); int address2 = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (address1 == address2) { if (address1 == address2) {
match = JNI_TRUE; match = JNI_TRUE;
break; break;
...@@ -703,6 +703,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { ...@@ -703,6 +703,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
if (iaObj) { if (iaObj) {
setInetAddress_addr(env, iaObj, htonl( setInetAddress_addr(env, iaObj, htonl(
((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr)); ((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
} else { } else {
return NULL; return NULL;
} }
...@@ -715,6 +716,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { ...@@ -715,6 +716,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
if (ia2Obj) { if (ia2Obj) {
setInetAddress_addr(env, ia2Obj, htonl( setInetAddress_addr(env, ia2Obj, htonl(
((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr)); ((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj); (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
} else { } else {
return NULL; return NULL;
......
/* /*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -569,12 +569,15 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this, ...@@ -569,12 +569,15 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port); iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
#ifdef AF_INET6 #ifdef AF_INET6
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6; family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION_RETURN(env, -1);
#else #else
family = AF_INET; family = AF_INET;
#endif #endif
if (family == AF_INET) { /* this API can't handle IPV6 addresses */ if (family == AF_INET) { /* this API can't handle IPV6 addresses */
int address = getInetAddress_addr(env, iaObj); int address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
setInetAddress_addr(env, addressObj, address); setInetAddress_addr(env, addressObj, address);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
} }
return port; return port;
} }
...@@ -1108,7 +1111,9 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val ...@@ -1108,7 +1111,9 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
addr = (*env)->GetObjectArrayElement(env, addrArray, i); addr = (*env)->GetObjectArrayElement(env, addrArray, i);
if (getInetAddress_family(env, addr) == IPv4) { if (getInetAddress_family(env, addr) == IPv4) {
JNU_CHECK_EXCEPTION(env);
in.s_addr = htonl(getInetAddress_addr(env, addr)); in.s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION(env);
break; break;
} }
} }
...@@ -1162,6 +1167,7 @@ static void mcast_set_if_by_addr_v4(JNIEnv *env, jobject this, int fd, jobject v ...@@ -1162,6 +1167,7 @@ static void mcast_set_if_by_addr_v4(JNIEnv *env, jobject this, int fd, jobject v
in.s_addr = htonl( getInetAddress_addr(env, value) ); in.s_addr = htonl( getInetAddress_addr(env, value) );
JNU_CHECK_EXCEPTION(env);
if (JVM_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF, if (JVM_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF,
(const char*)&in, sizeof(in)) < 0) { (const char*)&in, sizeof(in)) < 0) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
...@@ -1528,6 +1534,7 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) { ...@@ -1528,6 +1534,7 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) {
CHECK_NULL_RETURN(addr, NULL); CHECK_NULL_RETURN(addr, NULL);
setInetAddress_addr(env, addr, ntohl(in.s_addr)); setInetAddress_addr(env, addr, ntohl(in.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
/* /*
* For IP_MULTICAST_IF return InetAddress * For IP_MULTICAST_IF return InetAddress
...@@ -1990,6 +1997,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this, ...@@ -1990,6 +1997,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
#ifdef __linux__ #ifdef __linux__
if (getInetAddress_family(env, iaObj) == IPv4) { if (getInetAddress_family(env, iaObj) == IPv4) {
JNU_CHECK_EXCEPTION(env);
ipv6_join_leave = JNI_FALSE; ipv6_join_leave = JNI_FALSE;
} }
#endif #endif
...@@ -2037,6 +2045,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this, ...@@ -2037,6 +2045,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
} }
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj)); mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
mname.imr_address.s_addr = 0; mname.imr_address.s_addr = 0;
mname.imr_ifindex = (*env)->GetIntField(env, niObj, ni_indexID); mname.imr_ifindex = (*env)->GetIntField(env, niObj, ni_indexID);
mname_len = sizeof(struct ip_mreqn); mname_len = sizeof(struct ip_mreqn);
...@@ -2055,10 +2064,13 @@ static void mcast_join_leave(JNIEnv *env, jobject this, ...@@ -2055,10 +2064,13 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
addr = (*env)->GetObjectArrayElement(env, addrArray, 0); addr = (*env)->GetObjectArrayElement(env, addrArray, 0);
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj)); mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
#ifdef __linux__ #ifdef __linux__
mname.imr_address.s_addr = htonl(getInetAddress_addr(env, addr)); mname.imr_address.s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION(env);
#else #else
mname.imr_interface.s_addr = htonl(getInetAddress_addr(env, addr)); mname.imr_interface.s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION(env);
#endif #endif
mname_len = sizeof(struct ip_mreq); mname_len = sizeof(struct ip_mreq);
} }
...@@ -2094,6 +2106,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this, ...@@ -2094,6 +2106,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
} }
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj)); mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
mname.imr_address.s_addr = 0 ; mname.imr_address.s_addr = 0 ;
mname.imr_ifindex = index; mname.imr_ifindex = index;
mname_len = sizeof(struct ip_mreqn); mname_len = sizeof(struct ip_mreqn);
...@@ -2116,6 +2129,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this, ...@@ -2116,6 +2129,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
mname.imr_interface.s_addr = in.s_addr; mname.imr_interface.s_addr = in.s_addr;
#endif #endif
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj)); mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
mname_len = sizeof(struct ip_mreq); mname_len = sizeof(struct ip_mreq);
} }
} }
...@@ -2181,10 +2195,12 @@ static void mcast_join_leave(JNIEnv *env, jobject this, ...@@ -2181,10 +2195,12 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
jint family; jint family;
jint address; jint address;
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6; family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION(env);
if (family == AF_INET) { /* will convert to IPv4-mapped address */ if (family == AF_INET) { /* will convert to IPv4-mapped address */
memset((char *) caddr, 0, 16); memset((char *) caddr, 0, 16);
address = getInetAddress_addr(env, iaObj); address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION(env);
caddr[10] = 0xff; caddr[10] = 0xff;
caddr[11] = 0xff; caddr[11] = 0xff;
......
/* /*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -786,6 +786,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr ...@@ -786,6 +786,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
int *len, jboolean v4MappedAddress) { int *len, jboolean v4MappedAddress) {
jint family; jint family;
family = getInetAddress_family(env, iaObj); family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
#ifdef AF_INET6 #ifdef AF_INET6
/* needs work. 1. family 2. clean up him6 etc deallocate memory */ /* needs work. 1. family 2. clean up him6 etc deallocate memory */
if (ipv6_available() && !(family == IPv4 && v4MappedAddress == JNI_FALSE)) { if (ipv6_available() && !(family == IPv4 && v4MappedAddress == JNI_FALSE)) {
...@@ -797,6 +798,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr ...@@ -797,6 +798,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
if (family == IPv4) { /* will convert to IPv4-mapped address */ if (family == IPv4) { /* will convert to IPv4-mapped address */
memset((char *) caddr, 0, 16); memset((char *) caddr, 0, 16);
address = getInetAddress_addr(env, iaObj); address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (address == INADDR_ANY) { if (address == INADDR_ANY) {
/* we would always prefer IPv6 wildcard address /* we would always prefer IPv6 wildcard address
caddr[10] = 0xff; caddr[10] = 0xff;
...@@ -905,6 +907,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr ...@@ -905,6 +907,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
} }
memset((char *) him4, 0, sizeof(struct sockaddr_in)); memset((char *) him4, 0, sizeof(struct sockaddr_in));
address = getInetAddress_addr(env, iaObj); address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
him4->sin_port = htons((short) port); him4->sin_port = htons((short) port);
him4->sin_addr.s_addr = (uint32_t) htonl(address); him4->sin_addr.s_addr = (uint32_t) htonl(address);
him4->sin_family = AF_INET; him4->sin_family = AF_INET;
......
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -195,6 +195,8 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -195,6 +195,8 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn; goto cleanupAndReturn;
} }
setInetAddress_addr(env, iaObj, ntohl(address)); setInetAddress_addr(env, iaObj, ntohl(address));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, 0, iaObj); (*env)->SetObjectArrayElement(env, ret, 0, iaObj);
JNU_ReleaseStringPlatformChars(env, host, hostname); JNU_ReleaseStringPlatformChars(env, host, hostname);
return ret; return ret;
...@@ -228,7 +230,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -228,7 +230,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn; goto cleanupAndReturn;
} }
setInetAddress_addr(env, iaObj, ntohl((*addrp)->s_addr)); setInetAddress_addr(env, iaObj, ntohl((*addrp)->s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host); setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, i, iaObj); (*env)->SetObjectArrayElement(env, ret, i, iaObj);
addrp++; addrp++;
i++; i++;
......
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -219,7 +219,11 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -219,7 +219,11 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn; goto cleanupAndReturn;
} }
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host); setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj); (*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
inetIndex ++; inetIndex ++;
} else if (iterator->ai_family == AF_INET6) { } else if (iterator->ai_family == AF_INET6) {
...@@ -240,6 +244,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -240,6 +244,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
setInet6Address_scopeid(env, iaObj, scope); setInet6Address_scopeid(env, iaObj, scope);
} }
setInetAddress_hostName(env, iaObj, host); setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj); (*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj);
inet6Index ++; inet6Index ++;
} }
......
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -593,6 +593,7 @@ jobject createNetworkInterface ...@@ -593,6 +593,7 @@ jobject createNetworkInterface
/* default ctor will set family to AF_INET */ /* default ctor will set family to AF_INET */
setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (addrs->mask != -1) { if (addrs->mask != -1) {
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
if (ibObj == NULL) { if (ibObj == NULL) {
...@@ -606,6 +607,7 @@ jobject createNetworkInterface ...@@ -606,6 +607,7 @@ jobject createNetworkInterface
return NULL; return NULL;
} }
setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr)); setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj); (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask); (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
...@@ -761,8 +763,9 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0 ...@@ -761,8 +763,9 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
(JNIEnv *env, jclass cls, jobject iaObj) (JNIEnv *env, jclass cls, jobject iaObj)
{ {
netif *ifList, *curr; netif *ifList, *curr;
jint addr = getInetAddress_addr(env, iaObj);
jobject netifObj = NULL; jobject netifObj = NULL;
jint addr = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
if (ipv6_available()) { if (ipv6_available()) {
......
/* /*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -552,6 +552,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) ...@@ -552,6 +552,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr)); setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID); ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
if (ibObj == NULL) { if (ibObj == NULL) {
free_netaddr(netaddrP); free_netaddr(netaddrP);
...@@ -564,6 +565,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) ...@@ -564,6 +565,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
return NULL; return NULL;
} }
setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr)); setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj); (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask); (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj); (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
......
/* /*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -439,12 +439,13 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this, ...@@ -439,12 +439,13 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
memset((char *)&lcladdr, 0, sizeof(lcladdr)); memset((char *)&lcladdr, 0, sizeof(lcladdr));
family = getInetAddress_family(env, addressObj); family = getInetAddress_family(env, addressObj);
JNU_CHECK_EXCEPTION(env);
if (family == IPv6 && !ipv6_supported) { if (family == IPv6 && !ipv6_supported) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Protocol family not supported"); "Protocol family not supported");
return; return;
} }
JNU_CHECK_EXCEPTION(env);
if (IS_NULL(fdObj) || (ipv6_supported && IS_NULL(fd1Obj))) { if (IS_NULL(fdObj) || (ipv6_supported && IS_NULL(fd1Obj))) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
return; return;
...@@ -459,6 +460,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this, ...@@ -459,6 +460,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
return; return;
} else { } else {
address = getInetAddress_addr(env, addressObj); address = getInetAddress_addr(env, addressObj);
JNU_CHECK_EXCEPTION(env);
} }
if (NET_InetAddressToSockaddr(env, addressObj, port, (struct sockaddr *)&lcladdr, &lcladdrlen, JNI_FALSE) != 0) { if (NET_InetAddressToSockaddr(env, addressObj, port, (struct sockaddr *)&lcladdr, &lcladdrlen, JNI_FALSE) != 0) {
...@@ -562,8 +564,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject thi ...@@ -562,8 +564,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject thi
} }
addr = getInetAddress_addr(env, address); addr = getInetAddress_addr(env, address);
JNU_CHECK_EXCEPTION(env);
family = getInetAddress_family(env, address); family = getInetAddress_family(env, address);
JNU_CHECK_EXCEPTION(env);
if (family == IPv6 && !ipv6_supported) { if (family == IPv6 && !ipv6_supported) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Protocol family not supported"); "Protocol family not supported");
...@@ -681,6 +684,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this, ...@@ -681,6 +684,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
} }
family = getInetAddress_family(env, iaObj); family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION(env);
if (family == IPv4) { if (family == IPv4) {
fdObj = (*env)->GetObjectField(env, this, pdsi_fdID); fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
} else { } else {
...@@ -731,6 +735,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this, ...@@ -731,6 +735,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
* Check is not necessary on these OSes */ * Check is not necessary on these OSes */
if (connected) { if (connected) {
address = getInetAddress_addr(env, iaObj); address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION(env);
} else { } else {
address = ntohl(rmtaddr.him4.sin_addr.s_addr); address = ntohl(rmtaddr.him4.sin_addr.s_addr);
} }
...@@ -841,6 +846,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this, ...@@ -841,6 +846,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
return -1; return -1;
} else { } else {
address = getInetAddress_addr(env, addressObj); address = getInetAddress_addr(env, addressObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
/* We only handle IPv4 for now. Will support IPv6 once its in the os */ /* We only handle IPv4 for now. Will support IPv6 once its in the os */
family = AF_INET; family = AF_INET;
} }
...@@ -923,7 +929,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this, ...@@ -923,7 +929,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
return 0; return 0;
} }
setInetAddress_addr(env, addressObj, ntohl(remote_addr.sin_addr.s_addr)); setInetAddress_addr(env, addressObj, ntohl(remote_addr.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, -1);
setInetAddress_family(env, addressObj, IPv4); setInetAddress_family(env, addressObj, IPv4);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
/* return port */ /* return port */
return ntohs(remote_addr.sin_port); return ntohs(remote_addr.sin_port);
...@@ -1630,6 +1638,7 @@ static int getInetAddrFromIf (JNIEnv *env, int family, jobject nif, jobject *iad ...@@ -1630,6 +1638,7 @@ static int getInetAddrFromIf (JNIEnv *env, int family, jobject nif, jobject *iad
int fam; int fam;
addr = (*env)->GetObjectArrayElement(env, addrArray, i); addr = (*env)->GetObjectArrayElement(env, addrArray, i);
fam = getInetAddress_family(env, addr); fam = getInetAddress_family(env, addr);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (fam == family) { if (fam == family) {
*iaddr = addr; *iaddr = addr;
return 0; return 0;
...@@ -1648,6 +1657,7 @@ static int getInet4AddrFromIf (JNIEnv *env, jobject nif, struct in_addr *iaddr) ...@@ -1648,6 +1657,7 @@ static int getInet4AddrFromIf (JNIEnv *env, jobject nif, struct in_addr *iaddr)
} }
iaddr->s_addr = htonl(getInetAddress_addr(env, addr)); iaddr->s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION_RETURN(env, -1);
return 0; return 0;
} }
...@@ -1752,6 +1762,7 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, ...@@ -1752,6 +1762,7 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1,
struct in_addr in; struct in_addr in;
in.s_addr = htonl(getInetAddress_addr(env, value)); in.s_addr = htonl(getInetAddress_addr(env, value));
JNU_CHECK_EXCEPTION(env);
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
(const char*)&in, sizeof(in)) < 0) { (const char*)&in, sizeof(in)) < 0) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
...@@ -1993,7 +2004,7 @@ static jobject getIPv4NetworkInterface (JNIEnv *env, jobject this, int fd, jint ...@@ -1993,7 +2004,7 @@ static jobject getIPv4NetworkInterface (JNIEnv *env, jobject this, int fd, jint
CHECK_NULL_RETURN(addr, NULL); CHECK_NULL_RETURN(addr, NULL);
setInetAddress_addr(env, addr, ntohl(in.s_addr)); setInetAddress_addr(env, addr, ntohl(in.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
/* /*
* For IP_MULTICAST_IF return InetAddress * For IP_MULTICAST_IF return InetAddress
*/ */
......
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -414,6 +414,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this, ...@@ -414,6 +414,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this,
fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
family = getInetAddress_family(env, iaObj); family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION(env);
if (family == IPv6 && !ipv6_supported) { if (family == IPv6 && !ipv6_supported) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
...@@ -731,7 +732,9 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this, ...@@ -731,7 +732,9 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
} }
setInetAddress_addr(env, socketAddressObj, ntohl(him.him4.sin_addr.s_addr)); setInetAddress_addr(env, socketAddressObj, ntohl(him.him4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION(env);
setInetAddress_family(env, socketAddressObj, IPv4); setInetAddress_family(env, socketAddressObj, IPv4);
JNU_CHECK_EXCEPTION(env);
(*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj); (*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj);
} else { } else {
/* AF_INET6 -> Inet6Address */ /* AF_INET6 -> Inet6Address */
...@@ -758,6 +761,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this, ...@@ -758,6 +761,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
} }
setInet6Address_ipaddress(env, socketAddressObj, (const char *)&him.him6.sin6_addr); setInet6Address_ipaddress(env, socketAddressObj, (const char *)&him.him6.sin6_addr);
setInetAddress_family(env, socketAddressObj, IPv6); setInetAddress_family(env, socketAddressObj, IPv6);
JNU_CHECK_EXCEPTION(env);
setInet6Address_scopeid(env, socketAddressObj, him.him6.sin6_scope_id); setInet6Address_scopeid(env, socketAddressObj, him.him6.sin6_scope_id);
} }
......
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -875,6 +875,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr ...@@ -875,6 +875,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
int *len, jboolean v4MappedAddress) { int *len, jboolean v4MappedAddress) {
jint family, iafam; jint family, iafam;
iafam = getInetAddress_family(env, iaObj); iafam = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
family = (iafam == IPv4)? AF_INET : AF_INET6; family = (iafam == IPv4)? AF_INET : AF_INET6;
if (ipv6_available() && !(family == AF_INET && v4MappedAddress == JNI_FALSE)) { if (ipv6_available() && !(family == AF_INET && v4MappedAddress == JNI_FALSE)) {
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him; struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
...@@ -885,6 +886,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr ...@@ -885,6 +886,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
if (family == AF_INET) { /* will convert to IPv4-mapped address */ if (family == AF_INET) { /* will convert to IPv4-mapped address */
memset((char *) caddr, 0, 16); memset((char *) caddr, 0, 16);
address = getInetAddress_addr(env, iaObj); address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (address == INADDR_ANY) { if (address == INADDR_ANY) {
/* we would always prefer IPv6 wildcard address /* we would always prefer IPv6 wildcard address
caddr[10] = 0xff; caddr[10] = 0xff;
...@@ -923,6 +925,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr ...@@ -923,6 +925,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
} }
memset((char *) him4, 0, sizeof(struct sockaddr_in)); memset((char *) him4, 0, sizeof(struct sockaddr_in));
address = getInetAddress_addr(env, iaObj); address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
him4->sin_port = htons((short) port); him4->sin_port = htons((short) port);
him4->sin_addr.s_addr = (u_long) htonl(address); him4->sin_addr.s_addr = (u_long) htonl(address);
him4->sin_family = AF_INET; him4->sin_family = AF_INET;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册