Results 1 to 5 of 5

Thread: Need an InetAddress using a host

  1. #1

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

    Resolved Need an InetAddress using a host

    Im adding password authentication to some code but I seem to have run into a problem. All of the requestPasswordAuthentication methods within the Authenticator class take an InetAddress object as an arg. I can't figure out how to get an instance of an InetAddres object just using a host name. The only methods that return a new instance are the following. With the last not returning an InetAddress but an IP address for the given host name.
    Code:
    static InetAddress getByAddress(byte[] addr)
    static InetAddress getByAddress(String host, byte[] addr)
    static InetAddress getByName(String host)
    I could use getByName(String host) to get the ip address then parse it into a byte array to use for getByAddress(byte[] addr) but that's really a pain.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Need an InetAddress using a host

    Wait a moment. How can it return an IP address if the return type is InetAddress?
    Besides which, the InetAddress type is merely a wrapper around an IP address.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

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

    Re: Need an InetAddress using a host

    I must have read the docs wrong. They say the following......
    Parameters:
    host - the specified host, or null.

    Returns:
    an IP address for the given host name.

  4. #4

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

    Re: Need an InetAddress using a host

    Can't figure out why the code keeps throwing an java.net.UnknownHostException. I am prretty sure it's thrown at the line where the stream is opened from the URL. The URL is correct or the runtime would throw a java.net.MalformedURLException.
    Code:
    buff = new BufferedReader(new InputStreamReader(new URL(target).openStream()));

  5. #5

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

    Re: Need an InetAddress using a host

    Seems a UnknownHostException is thrown if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address. I guess the DNS canno't determine the ip address of msn.com and a few other sites I tried.

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