-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.4.2_07
-
generic
-
generic
According to the java.net.InetAddress.getAllByName(String) API, the host name can either be a machine name or a textual representation of its IP address.
If you specify a textual representation of an IP address, the java.net.InetAddress.toString() method ignores the hostname since J2SE 1.4.2. The output produced by the following application will demonstrate this regression.
% cat Addr.java
import java.net.*;
public class Addr {
public static void main(String args[]) {
InetAddress addrs[] = null;
try {
addrs = InetAddress.getAllByName(args[0]);
} catch (Exception e) {
e.printStackTrace();
return;
}
for (int i = 0; i < addrs.length; i++) {
System.out.println(addrs[i]);
}
}
}
See the comments section for an output of the program.
With J2SE 1.2.2 and J2SE 1.3.1 the addrs[i].toString() returns both hostname and IP-address. Since J2SE 1.4.2 we only get the IP-address, the hostname is not present.
If you change
System.out.println(addrs[i]);
to
System.out.println(addrs[i].getHostName()+"/"+addrs[i].getHostAddress());
in the snippet above, it also works with 1.4.2_x and 1.5.0_y.
###@###.### 2005-2-01 09:32:15 GMT
If you specify a textual representation of an IP address, the java.net.InetAddress.toString() method ignores the hostname since J2SE 1.4.2. The output produced by the following application will demonstrate this regression.
% cat Addr.java
import java.net.*;
public class Addr {
public static void main(String args[]) {
InetAddress addrs[] = null;
try {
addrs = InetAddress.getAllByName(args[0]);
} catch (Exception e) {
e.printStackTrace();
return;
}
for (int i = 0; i < addrs.length; i++) {
System.out.println(addrs[i]);
}
}
}
See the comments section for an output of the program.
With J2SE 1.2.2 and J2SE 1.3.1 the addrs[i].toString() returns both hostname and IP-address. Since J2SE 1.4.2 we only get the IP-address, the hostname is not present.
If you change
System.out.println(addrs[i]);
to
System.out.println(addrs[i].getHostName()+"/"+addrs[i].getHostAddress());
in the snippet above, it also works with 1.4.2_x and 1.5.0_y.
###@###.### 2005-2-01 09:32:15 GMT