After reading a question on this topic over at jguru i tried to figure out how an InetAddress object could be constructed using an ip address in the form of a byte[].
Figuring the ip address is most likely a String(say if a host is resolved to an IpAddress) i tried to construct a byte array to make another InetAddress object but the code simply fails because the byte array is too long.
Even hardcoding the values of the ip address into a byte[] wouldn't work since java dosen't have unsigned primative types.Code:InetAddress inet = InetAddress.getByName("www.sun.com"); String ip = inet.getHostAddress(); System.out.println(ip); InetAddress inet2 = InetAddress.getByAddress(ip.getBytes()); System.out.println(inet2.getHostAddress());![]()




Reply With Quote