private static byte [ ] parseDottedQuad ( String address ) { String [ ] splitString = address . split ( "\\." ) ; if ( splitString . length == 4 ) { int [ ] ints = new int [ 4 ] ; byte [ ] bytes = new byte [ 4 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { ints [ i ] = Integer . parseInt ( splitString [ i ] ) ; if ( ints [ i ] < 0 || ints [ i ] > 255 ) { throw new IllegalArgumentException ( "Invalid ip4Address or netmask" ) ; } bytes [ i ] = toByte ( ints [ i ] ) ; //a pox on java and it's signed bytes } return bytes ; } else { throw new IllegalArgumentException ( "Address must be in dotted quad notation" ) ; } }
parse ip4 address as dotted quad notation into bytes