From f51218f1b98e6f1950ebe17dd8889332700d3b53 Mon Sep 17 00:00:00 2001 From: chegar Date: Fri, 31 May 2013 09:30:44 +0100 Subject: [PATCH] 7107883: getNetworkPrefixLength() does not return correct prefix length Reviewed-by: alanb, michaelm --- src/solaris/native/java/net/NetworkInterface.c | 9 +++------ .../java/net/InterfaceAddress/NetworkPrefixLength.java | 10 +++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/solaris/native/java/net/NetworkInterface.c b/src/solaris/native/java/net/NetworkInterface.c index f887bbc63..68633db5a 100644 --- a/src/solaris/native/java/net/NetworkInterface.c +++ b/src/solaris/native/java/net/NetworkInterface.c @@ -658,9 +658,9 @@ jobject createNetworkInterface(JNIEnv *env, netif *ifs) { if (ia2Obj) { setInetAddress_addr(env, ia2Obj, htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr)); (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj); - (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask); } } + (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask); (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj); } } @@ -887,15 +887,12 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, addrP->mask = prefix; addrP->next = 0; if (family == AF_INET) { - /* - * Deal with broadcast addr & subnet mask - */ + // Deal with broadcast addr & subnet mask struct sockaddr * brdcast_to = (struct sockaddr *) ((char *) addrP + sizeof(netaddr) + addr_size); addrP->brdcast = getBroadcast(env, sock, name, brdcast_to ); - if (addrP->brdcast && (mask = getSubnet(env, sock, name)) != -1) { + if ((mask = getSubnet(env, sock, name)) != -1) addrP->mask = mask; - } } /** diff --git a/test/java/net/InterfaceAddress/NetworkPrefixLength.java b/test/java/net/InterfaceAddress/NetworkPrefixLength.java index 211086e73..448973eb0 100644 --- a/test/java/net/InterfaceAddress/NetworkPrefixLength.java +++ b/test/java/net/InterfaceAddress/NetworkPrefixLength.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 6707289 + * @bug 6707289 7107883 * @summary InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc */ @@ -47,6 +47,14 @@ public class NetworkPrefixLength { passed = false; debug(nic.getName(), iaddr); } + InetAddress ia = iaddr.getAddress(); + if (ia.isLoopbackAddress() && ia instanceof Inet4Address) { + // assumption: prefix length will always be 8 + if (iaddr.getNetworkPrefixLength() != 8) { + out.println("Expected prefix of 8, got " + iaddr); + passed = false; + } + } } } -- GitLab