The IsReachable API returns true for IPv6 addresses from an IPv4 solaris host.
Steps to reproduce the bug :
1. Copy the code below to a file.
2. Compile the code.
3. Execute the code by giving an IPv6 address on the command line.
4. An Exception should be thrown or a false value should be returned.
-----------------BEGIN CODE-----------------------------
import java.net.*;
import java.io.*;
public class IsHostReachableBug {
public static void main(String[] args) throws Exception{
String hostName = "yamlok.india";
BufferedReader in = null;
FileWriter fw = null;
String inString = " ";
if (args.length > 0)
hostName = args[0];
InetAddress addr = InetAddress.getByName(hostName);
System.out.println("InetAddress is : " + addr);
System.out.println("Is InetAddress instance of Inet6Address ? " + (addr instanceof Inet6Address));
if (!addr.isReachable(10000)){
System.out.println(hostName + " is not reachable");
}else {
System.out.println(hostName + " is reachable");
}
}
}
----------------END CODE----------------------------
---------------BEGIN OUTPUT-------------------------
sqindia: <150> $$JHOME/bin/java IsHostReachableBug fe80::a00:20ff:fefe:3440
InetAddress is : /fe80:0:0:0:a00:20ff:fefe:3440
Is InetAddress instance of Inet6Address ? true
fe80::a00:20ff:fefe:3440 is reachable
sqindia: <151> $
sqindia: <151> $
sqindia: <151> $ping fe80::a00:20ff:fefe:3440
ping: unknown host fe80::a00:20ff:fefe:3440
sqindia: <152> $
sqindia: <152> $
sqindia: <152> $ifconfig -a
lo0: flags=849<UP,LOOPBACK,RUNNING,MULTICAST> mtu 8232
inet 127.0.0.1 netmask ff000000
hme0: flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST> mtu 1500
inet 10.12.151.12 netmask ffffff00 broadcast 10.12.151.255
sqindia: <153> $
--------------------------END OUTPUT---------------
Steps to reproduce the bug :
1. Copy the code below to a file.
2. Compile the code.
3. Execute the code by giving an IPv6 address on the command line.
4. An Exception should be thrown or a false value should be returned.
-----------------BEGIN CODE-----------------------------
import java.net.*;
import java.io.*;
public class IsHostReachableBug {
public static void main(String[] args) throws Exception{
String hostName = "yamlok.india";
BufferedReader in = null;
FileWriter fw = null;
String inString = " ";
if (args.length > 0)
hostName = args[0];
InetAddress addr = InetAddress.getByName(hostName);
System.out.println("InetAddress is : " + addr);
System.out.println("Is InetAddress instance of Inet6Address ? " + (addr instanceof Inet6Address));
if (!addr.isReachable(10000)){
System.out.println(hostName + " is not reachable");
}else {
System.out.println(hostName + " is reachable");
}
}
}
----------------END CODE----------------------------
---------------BEGIN OUTPUT-------------------------
sqindia: <150> $$JHOME/bin/java IsHostReachableBug fe80::a00:20ff:fefe:3440
InetAddress is : /fe80:0:0:0:a00:20ff:fefe:3440
Is InetAddress instance of Inet6Address ? true
fe80::a00:20ff:fefe:3440 is reachable
sqindia: <151> $
sqindia: <151> $
sqindia: <151> $ping fe80::a00:20ff:fefe:3440
ping: unknown host fe80::a00:20ff:fefe:3440
sqindia: <152> $
sqindia: <152> $
sqindia: <152> $ifconfig -a
lo0: flags=849<UP,LOOPBACK,RUNNING,MULTICAST> mtu 8232
inet 127.0.0.1 netmask ff000000
hme0: flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST> mtu 1500
inet 10.12.151.12 netmask ffffff00 broadcast 10.12.151.255
sqindia: <153> $
--------------------------END OUTPUT---------------
- relates to
-
JDK-4921816 InetAddress.isReachable returns true for unreachable addresses
-
- Resolved
-