< prev index next >

src/java.base/share/classes/sun/net/util/IPAddressUtil.java

Print this page
@@ -279,18 +279,30 @@
              return newAddr;
          }
          return null;
      }
  
+ 
+     /**
+      * Returns the address value, as an int, of an IPv4-mapped IPv6 address.
+      */
+     public static int intFromIPv4MappedAddress(byte[] addr) {
+         assert isIPv4MappedAddress(addr);
+         return ((addr[12] & 0xFF) << 24) |
+                ((addr[13] & 0xFF) << 16) |
+                ((addr[14] & 0xFF) << 8)  |
+                 (addr[15] & 0xFF);
+     }
+ 
      /**
       * Utility routine to check if the InetAddress is an
       * IPv4 mapped IPv6 address.
       *
       * @return a <code>boolean</code> indicating if the InetAddress is
       * an IPv4 mapped IPv6 address; or false if address is IPv4 address.
       */
-     private static boolean isIPv4MappedAddress(byte[] addr) {
+     public static boolean isIPv4MappedAddress(byte[] addr) {
          if (addr.length < INADDR16SZ) {
              return false;
          }
          if ((addr[0] == 0x00) && (addr[1] == 0x00) &&
              (addr[2] == 0x00) && (addr[3] == 0x00) &&
< prev index next >