changeset 17921:8ae76f95800a

7107883: getNetworkPrefixLength() does not return correct prefix length Reviewed-by: alanb, michaelm
author chegar
date Fri, 31 May 2013 09:30:44 +0100
parents eef25bc37ccd
children d56eec572de5
files jdk/src/solaris/native/java/net/NetworkInterface.c jdk/test/java/net/InterfaceAddress/NetworkPrefixLength.java
diffstat 2 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/solaris/native/java/net/NetworkInterface.c	Fri May 31 09:58:00 2013 +0200
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c	Fri May 31 09:30:44 2013 +0100
@@ -658,9 +658,9 @@
                     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 @@
     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;
-       }
      }
 
     /**
--- a/jdk/test/java/net/InterfaceAddress/NetworkPrefixLength.java	Fri May 31 09:58:00 2013 +0200
+++ b/jdk/test/java/net/InterfaceAddress/NetworkPrefixLength.java	Fri May 31 09:30:44 2013 +0100
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 6707289
+ * @bug 6707289 7107883
  * @summary InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
  */
 
@@ -47,6 +47,14 @@
                     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;
+                    }
+                }
             }
         }