public boolean inetAddressOnNetwork ( InetAddress ia ) { int i = ( _o1 << 24 ) | ( _o2 << 16 ) | ( _o3 << 8 ) | ( _o4 << 0 ) ; byte [ ] barr = ia . getAddress ( ) ; if ( barr . length != 4 ) { return false ; } int j = ( ( ( int ) barr [ 0 ] & 0xff ) << 24 ) | ( ( ( int ) barr [ 1 ] & 0xff ) << 16 ) | ( ( ( int ) barr [ 2 ] & 0xff ) << 8 ) | ( ( ( int ) barr [ 3 ] & 0xff ) << 0 ) ; // Do mask math in 64-bit to handle 32-bit wrapping cases. long mask1 = ( ( long ) 1 << ( 32 - _bits ) ) ; long mask2 = mask1 - 1 ; long mask3 = ~ mask2 ; int mask4 = ( int ) ( mask3 & 0xffffffff ) ; if ( ( i & mask4 ) == ( j & mask4 ) ) { return true ; } return false ; }
Test if an internet address lives on this user specified network .