Results 1 to 9 of 9

Thread: Constructing an InetAddress from a byte[]

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Constructing an InetAddress from a byte[]

    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.
    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());
    Even hardcoding the values of the ip address into a byte[] wouldn't work since java dosen't have unsigned primative types.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width