static byte [ ] inet6AsByteArray ( InetAddress ia ) { if ( ia instanceof Inet6Address ) { return ia . getAddress ( ) ; } // need to construct IPv4-mapped address if ( ia instanceof Inet4Address ) { byte [ ] ip4address = ia . getAddress ( ) ; byte [ ] address = new byte [ 16 ] ; address [ 10 ] = ( byte ) 0xff ; address [ 11 ] = ( byte ) 0xff ; address [ 12 ] = ip4address [ 0 ] ; address [ 13 ] = ip4address [ 1 ] ; address [ 14 ] = ip4address [ 2 ] ; address [ 15 ] = ip4address [ 3 ] ; return address ; } throw new AssertionError ( "Should not reach here" ) ; }
Returns an IPv6 address as a byte array