Fwd: InetAddress.getAllByName()/getByName() fails to resolve IPv6 via ssh
Kurchi Hazra
kurchi.subhra.hazra at oracle.com
Tue Dec 18 11:09:48 PST 2012
Forwarding to net-dev
Hi Charis,
I tried to recreate this, I ran your code remotely (from both
Linux and Windows onto a Linux machine) but could not
get an UnkownHostException if the code works without an exception when
run locally on a machine.
Can you be more specific about the operating systems running on both
systems?
Thanks,
Kurchi
-------- Original Message --------
Subject: InetAddress.getAllByName()/getByName() fails to resolve IPv6
via ssh
Date: Mon, 17 Dec 2012 21:55:40 -0800 (PST)
From: charis <charis.charitsis at oracle.com>
To: nio-dev at openjdk.java.net
I am facing the following issue:
Say there is a simple standlone code Test.java which just calls
InetAddress.getAllByName() :
*
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class TestNameResolution {
public static void main(String args[]) {
String name = args[0];
System.out.println("Trying to resolve name \"" + name + "\" to IP
addresses");
try {
InetAddress[] addresses = InetAddress.getAllByName(name);
for (int i = 0; i< addresses.length; i++) {
if (addresses[i] instanceof Inet4Address) {
System.out.println("IPv4 address -->" +
addresses[i].getHostAddress());
}
else if (addresses[i] instanceof Inet6Address) {
System.out.println("IPv6 address -->" +
addresses[i].getHostAddress());
}
}
}
catch (UnknownHostException uhe) {
System.out.println("Cannot resolve name \"" + name + "\"");
}
}
}
*
I run this via a simple single-line script 'run':
*
java -classpath<absolute path of TestNameResolution.class>
TestNameResolution<ipv6-name-to-resolve>
*
When try this locally it resolves the name to its IPv6 address as expected.
However, when from a different machine to execute this via ssh (i.e., ssh
<my machine name> <path to 'run' script>) I often get the following output:
/
Trying to resolve name "<ipv6-name-to-resolve>" to IP addresses
Cannot resolve name "<ipv6-name-to-resolve>"
java.net.UnknownHostException:<ipv6-name-to-resolve>
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at
java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at TestNameResolution.main(TestNameResolution.java:14
/
Note:
- I tried the java command that invokes the standalone also with i)
'-Djava.net.preferIPv6Stack=true' , ii) and
'-Djava.net.preferIPv6Addresses=true' and iii) with both of them at the same
time.
Still, the output is the same
- The same standalone succeeds in resolving a name which maps to IPv4 giving
the same (correct) output on the local and the remote node (where the ssh is
initiated)
Java environment details:
$ java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Is there any known issue with IPv6 name resolution via ssh? Any ideas what
may be causing this?
--
View this message in context: http://nio-dev.3157472.n2.nabble.com/InetAddress-getAllByName-getByName-fails-to-resolve-IPv6-via-ssh-tp7574957.html
Sent from the nio-dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20121218/6d331e72/attachment.html
More information about the net-dev
mailing list