LinkLocal Address ( InetAddress.getByName throws UnknownHostException )

Discussion in 'Java' started by saggar, Jun 15, 2011.

  1. saggar

    saggar Guest

    Hi,

    I used the following code to create a InetAddress from lilnklocal
    address ( returned by getifaddrs function).
    try{
    InetAddress add =
    InetAddress.getByName("fe80::216:3eff:fe38:74e8%eth0");
    }
    catch(UnknownHostException uhe){
    System.out.println("Caught unknownhost exception ");
    System.out.println("Message: "+uhe.getMessage());
    uhe.printStackTrace();
    }


    But it fails with the following message.

    java.net.UnknownHostException: no scope_id found
    at java.net.Inet6Address.deriveNumericScope(Inet6Address.java:
    358)
    at java.net.Inet6Address.initif(Inet6Address.java:321)
    at java.net.Inet6Address.initstr(Inet6Address.java:306)
    at java.net.Inet6Address.<init>(Inet6Address.java:232)
    at java.net.InetAddress.getAllByName(InetAddress.java:1062)
    at java.net.InetAddress.getAllByName(InetAddress.java:1009)
    at java.net.InetAddress.getByName(InetAddress.java:959)

    What could be the possible reasons for it ? Is it specific to JDK
    version ?

    -Sunil
    saggar, Jun 15, 2011
    #1
    1. Advertising

  2. saggar

    Lewis Bloch Guest

    On Jun 14, 11:15 pm, saggar <> wrote:
    > Hi,
    >
    > I used the following code to create a InetAddress from lilnklocal
    > address ( returned by getifaddrs function).
    >    try{
    >         InetAddress add =
    > InetAddress.getByName("fe80::216:3eff:fe38:74e8%eth0");
    >      }
    >      catch(UnknownHostException uhe){
    >         System.out.println("Caught unknownhost exception ");
    >         System.out.println("Message: "+uhe.getMessage());
    >         uhe.printStackTrace();
    >     }
    >
    > But it fails with the following message.
    >
    > java.net.UnknownHostException: no scope_id found
    >         at java.net.Inet6Address.deriveNumericScope(Inet6Address.java:
    > 358)
    >         at java.net.Inet6Address.initif(Inet6Address.java:321)
    >         at java.net.Inet6Address.initstr(Inet6Address.java:306)
    >         at java.net.Inet6Address.<init>(Inet6Address.java:232)
    >         at java.net.InetAddress.getAllByName(InetAddress.java:1062)
    >         at java.net.InetAddress.getAllByName(InetAddress.java:1009)
    >         at java.net.InetAddress.getByName(InetAddress.java:959)
    >
    > What could be the possible reasons for it ?  Is it specific to JDK
    > version ?
    >


    The error message is quite clear - the DNS does not recognize the host
    name. What you passed to the call really doesn't look like a host
    name, so that seems unsurprising.

    --
    Lew
    Lewis Bloch, Jun 17, 2011
    #2
    1. Advertising

  3. saggar

    lewbloch Guest

    On Jun 17, 6:27 am, Lewis Bloch <> wrote:
    > On Jun 14, 11:15 pm, saggar <> wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > I used the following code to create a InetAddress from lilnklocal
    > > address ( returned by getifaddrs function).
    > >    try{
    > >         InetAddress add =
    > > InetAddress.getByName("fe80::216:3eff:fe38:74e8%eth0");
    > >      }
    > >      catch(UnknownHostException uhe){
    > >         System.out.println("Caught unknownhost exception ");
    > >         System.out.println("Message: "+uhe.getMessage());
    > >         uhe.printStackTrace();
    > >     }

    >
    > > But it fails with the following message.

    >
    > > java.net.UnknownHostException: no scope_id found
    > >         at java.net.Inet6Address.deriveNumericScope(Inet6Address.java:
    > > 358)
    > >         at java.net.Inet6Address.initif(Inet6Address.java:321)
    > >         at java.net.Inet6Address.initstr(Inet6Address.java:306)
    > >         at java.net.Inet6Address.<init>(Inet6Address.java:232)
    > >         at java.net.InetAddress.getAllByName(InetAddress.java:1062)
    > >         at java.net.InetAddress.getAllByName(InetAddress.java:1009)
    > >         at java.net.InetAddress.getByName(InetAddress.java:959)

    >
    > > What could be the possible reasons for it ?  Is it specific to JDK
    > > version ?

    >
    > The error message is quite clear - the DNS does not recognize the host
    > name.  What you passed to the call really doesn't look like a host
    > name, so that seems unsurprising.
    >


    Oops. I should follow my own advice and check Javadocs first. Sorry.

    It doesn't look specific to the JDK - the error says that the scope ID
    was not found. The scope ID is "eth0", which implies that that
    interface was not available on the target system at run time.

    --
    Lew
    lewbloch, Jun 17, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. noone
    Replies:
    3
    Views:
    7,820
    noone
    Nov 11, 2003
  2. Dave Raskin
    Replies:
    0
    Views:
    384
    Dave Raskin
    Apr 26, 2004
  3. FB
    Replies:
    3
    Views:
    358
  4. -
    Replies:
    2
    Views:
    613
  5. Jack Dowson

    Query about method getByName()?

    Jack Dowson, May 16, 2007, in forum: Java
    Replies:
    1
    Views:
    249
    Eric Sosman
    May 16, 2007
Loading...

Share This Page