8157811: Additional minor fixes and cleanups in Networking native code
Reviewed-by: alanb, clanger, dsamersoff, msheppar
This commit is contained in:
parent
28f80af02a
commit
c4db92a027
@ -158,7 +158,10 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = (*env)->NewStringUTF(env, hostname);
|
name = (*env)->NewStringUTF(env, hostname);
|
||||||
CHECK_NULL_RETURN(name, NULL);
|
if (name == NULL) {
|
||||||
|
freeifaddrs(ifa);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Iterate over the interfaces, and total up the number of IPv4 and IPv6
|
/* Iterate over the interfaces, and total up the number of IPv4 and IPv6
|
||||||
* addresses we have. Also keep a count of loopback addresses. We need to
|
* addresses we have. Also keep a count of loopback addresses. We need to
|
||||||
|
@ -243,6 +243,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
|
|||||||
if (name_utf == NULL) {
|
if (name_utf == NULL) {
|
||||||
if (!(*env)->ExceptionCheck(env))
|
if (!(*env)->ExceptionCheck(env))
|
||||||
JNU_ThrowOutOfMemoryError(env, NULL);
|
JNU_ThrowOutOfMemoryError(env, NULL);
|
||||||
|
freeif(ifs);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +520,7 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0
|
|||||||
}
|
}
|
||||||
if ((sock = openSocketWithFallback(env, name_utf)) < 0) {
|
if ((sock = openSocketWithFallback(env, name_utf)) < 0) {
|
||||||
(*env)->ReleaseStringUTFChars(env, name, name_utf);
|
(*env)->ReleaseStringUTFChars(env, name, name_utf);
|
||||||
return JNI_FALSE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_NULL(addrArray)) {
|
if (!IS_NULL(addrArray)) {
|
||||||
@ -664,7 +665,7 @@ jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the array of InetAddresses
|
// Create the array of InetAddresses
|
||||||
addrArr = (*env)->NewObjectArray(env, addr_count, ia_class, NULL);
|
addrArr = (*env)->NewObjectArray(env, addr_count, ia_class, NULL);
|
||||||
if (addrArr == NULL) {
|
if (addrArr == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1829,7 +1830,7 @@ static int getFlags(int sock, const char *ifname, int *flags) {
|
|||||||
strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1);
|
strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1);
|
||||||
|
|
||||||
if (ioctl(sock, SIOCGLIFFLAGS, (char *)&if2) < 0) {
|
if (ioctl(sock, SIOCGLIFFLAGS, (char *)&if2) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*flags = if2.lifr_flags;
|
*flags = if2.lifr_flags;
|
||||||
@ -1859,8 +1860,7 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
|
|||||||
"IPV6 Socket creation failed");
|
"IPV6 Socket creation failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else { // errno is not NOSUPPORT
|
||||||
else{ // errno is not NOSUPPORT
|
|
||||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
|
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
|
||||||
"IPV4 Socket creation failed");
|
"IPV4 Socket creation failed");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -95,8 +95,8 @@ void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
|
|||||||
CHECK_NULL(c);
|
CHECK_NULL(c);
|
||||||
c = (*env)->NewGlobalRef(env, c);
|
c = (*env)->NewGlobalRef(env, c);
|
||||||
CHECK_NULL(c);
|
CHECK_NULL(c);
|
||||||
ni_defaultIndexID = (*env)->GetStaticFieldID(
|
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I");
|
||||||
env, c, "defaultIndex", "I");
|
CHECK_NULL(ni_defaultIndexID);
|
||||||
ni_class = c;
|
ni_class = c;
|
||||||
}
|
}
|
||||||
int defaultIndex;
|
int defaultIndex;
|
||||||
@ -118,8 +118,8 @@ int getDefaultScopeID(JNIEnv *env) {
|
|||||||
CHECK_NULL_RETURN(c, 0);
|
CHECK_NULL_RETURN(c, 0);
|
||||||
c = (*env)->NewGlobalRef(env, c);
|
c = (*env)->NewGlobalRef(env, c);
|
||||||
CHECK_NULL_RETURN(c, 0);
|
CHECK_NULL_RETURN(c, 0);
|
||||||
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c,
|
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I");
|
||||||
"defaultIndex", "I");
|
CHECK_NULL_RETURN(ni_defaultIndexID, 0);
|
||||||
ni_class = c;
|
ni_class = c;
|
||||||
}
|
}
|
||||||
defaultIndex = (*env)->GetStaticIntField(env, ni_class,
|
defaultIndex = (*env)->GetStaticIntField(env, ni_class,
|
||||||
|
Loading…
Reference in New Issue
Block a user