RFR 7107883: getNetworkPrefixLength() does not return correct prefix length

Chris Hegarty chris.hegarty at oracle.com
Thu May 30 04:53:07 PDT 2013


The Unix native implementation that determines the network interface's 
broadcast address and network prefix/subnet mask, incorrectly ties the 
mask to the existence of a broadcast address. This should be changed so 
that the network prefix/subnet mask, if available, is exposed through 
the Java API, getNetworkPrefixLength, regardless of the broadcast address.

http://cr.openjdk.java.net/~chegar/7107883/webrev.00/webrev/

Creating a reliable automatic regression test for this be problematic. 
Also, there is already an existing test that verify that 
getNetworkPrefixLength returns values within specified bounds.

This issue can be easily seen with the loopback interface:

   >: ifconfig lo
   lo        Link encap:Local Loopback
             inet addr:127.0.0.1  Mask:255.0.0.0
             inet6 addr: ::1/128 Scope:Host
             UP LOOPBACK RUNNING  MTU:16436  Metric:1
             RX packets:722 errors:0 dropped:0 overruns:0 frame:0
             TX packets:722 errors:0 dropped:0 overruns:0 carrier:0
             collisions:0 txqueuelen:0
             RX bytes:102346 (102.3 KB)  TX bytes:102346 (102.3 KB)

   >: binaries/jdk1.7.0_07/bin/java Test lo
     <0:0:0:0:0:0:0:1%1>
     getBroadcast():null
     getNetworkPrefixLength():128
     <127.0.0.1>
     getBroadcast():null
     getNetworkPrefixLength():0

-Chris.



More information about the net-dev mailing list