-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.6
DatagramSocket.getLocalAddress() returns different values depending upon how it was constructed. Some of the fields will contains all 0's. If DatagramSocket was constructed with an explicit InetAddress then it returns the correct information from the DatagramSocket.getLocalAddress() method. If the InetAddress is not specified then it returns 0.0.0.0 in most of the InetAddress fields.
Also MulitcastSocket.getInterface() and MulticastSocket.getInterface() returns incorrect information in the InetAddress fields. See sample output at end. Notice that getHostName(), getAllByName[0], getByName(), and getHostAddress()
all contain 0.0.0.0. This is incorrect.
This problem happens using JDK1.1.4 and JDK1.2Beta3-D on a SOLARIS 2.6 ULTRA SPARC Workstation.
This bug is similar to 4065656.
The following test program illustrates the problem. Compile and run with no arguments:
import java.io.*;
import java.net.*;
import java.util.*;
/**************************************************************************
* atest class
**************************************************************************/
public final class atest {
private static boolean verboseflag = true;
private static final int port = 26000;
public static void main(String[] args) {
atest a = new atest();
}
// Constructor
public atest() {
DatagramSocket d = null;
InetAddress iaddr = null;
logverbose("TEST #1 calling DatagramSocket()");
try {
d = new DatagramSocket();
DumpDatagramSocketInfo(d);
iaddr = InetAddress.getByName("localhost");
//DumpInetAddressInfo(iaddr);
} catch(Exception e) {
logerr("atest.main(): exception occurred:\n" + e);
return;
}
d.close();
System.out.println();
logverbose("TEST #2 calling DatagramSocket(" + port + ")");
try {
d = new DatagramSocket(port);
DumpDatagramSocketInfo(d);
iaddr = InetAddress.getByName("localhost");
//DumpInetAddressInfo(iaddr);
} catch(Exception e) {
logerr("atest.main(): exception occurred:\n" + e);
return;
}
d.close();
System.out.println();
try {
iaddr = InetAddress.getByName("localhost");
logverbose(
"TEST #3 calling DatagramSocket(" + port + ", " + iaddr + ")");
d = new DatagramSocket(port, iaddr);
DumpDatagramSocketInfo(d);
iaddr = InetAddress.getByName("localhost");
//DumpInetAddressInfo(iaddr);
} catch(Exception e) {
logerr("atest.main(): exception occurred:\n" + e);
return;
}
d.close();
}
// logout Method
public static void logout(String s) {
System.out.println(s);
System.out.flush();
}
// logerr Method
public static void logerr(String s) {
System.err.println("ERROR: " + s);
System.err.flush();
}
// logverbose Method
public static void logverbose(String s) {
if(verboseflag) {
System.out.println("VERBOSE: " + s);
System.out.flush();
}
}
// DumpDatagramSocketInfo Method
public void DumpDatagramSocketInfo(DatagramSocket s) {
if(!verboseflag) return;
try {
logverbose("DATAGRAM SOCKET INFO");
logverbose("--------------------");
logverbose("getLocalPort() = " + s.getLocalPort());
logverbose("getSoTimeout() = " + s.getSoTimeout());
logverbose("Dump getLocalAddress()");
DumpInetAddressInfo(s.getLocalAddress());
} catch(Exception e) {
logerr("DumpDatagramSocketInfo(): caught exception\n" + e);
}
}
// DumpInetAddressInfo Method
public void DumpInetAddressInfo(InetAddress i) {
if(!verboseflag) return;
try {
String host = i.getHostName();
logverbose("INET ADDRESS INFO");
logverbose("-----------------");
logverbose("getHostName() = " + i.getHostName());
InetAddress iaddrs[] = i.getAllByName(host);
for(int j=0; j<iaddrs.length; j++)
logverbose("getAllByName[" + j + "] = " + iaddrs[j]);
logverbose("getByName() = " + i.getByName(host));
logverbose("getLocalHost() = " + i.getLocalHost());
logverbose("FIX: getAddress() = " + new String(i.getAddress()));
logverbose("getHostAddress() = " + i.getHostAddress());
logverbose("isMulticastAddress() = " + i.isMulticastAddress());
} catch(Exception e) {
logerr("DumpInetAddressInfo(): caught exception\n" + e);
}
}
}
VERBOSE: port number is = 26500
VERBOSE: buffer size is = 1K
VERBOSE: sleep delay between sending messages = 25
VERBOSE: real buffer size is = 1024
VERBOSE: multicast address is = 224.0.0.1
VERBOSE: number of messages = 50
VERBOSE: loop count is = 5
VERBOSE: random buffer sizes = false
DEBUG: creating multicast datagram socket
DEBUG: MULTICAST DATAGRAM SOCKET INFO
DEBUG: ------------------------------
DEBUG: getLocalPort() = 52431
DEBUG: getSoTimeout() = 0
DEBUG: getTTL() = 1
DEBUG: Dump getLocalAddress()
DEBUG: INET ADDRESS INFO
DEBUG: -----------------
DEBUG: getHostName() = 0.0.0.0
DEBUG: getAllByName[0] = 0.0.0.0/0.0.0.0
DEBUG: getByName() = 0.0.0.0/0.0.0.0
DEBUG: getLocalHost() = caffeine.East.Sun.COM/129.148.27.72
DEBUG: getHostAddress() = 0.0.0.0
DEBUG: isMulticastAddress() = false
DEBUG: Dump getInterface()
DEBUG: INET ADDRESS INFO
DEBUG: -----------------
DEBUG: getHostName() = 0.0.0.0
DEBUG: getAllByName[0] = 0.0.0.0/0.0.0.0
DEBUG: getByName() = 0.0.0.0/0.0.0.0
DEBUG: getLocalHost() = caffeine.East.Sun.COM/129.148.27.72
DEBUG: getHostAddress() = 0.0.0.0
DEBUG: isMulticastAddress() = false
Also MulitcastSocket.getInterface() and MulticastSocket.getInterface() returns incorrect information in the InetAddress fields. See sample output at end. Notice that getHostName(), getAllByName[0], getByName(), and getHostAddress()
all contain 0.0.0.0. This is incorrect.
This problem happens using JDK1.1.4 and JDK1.2Beta3-D on a SOLARIS 2.6 ULTRA SPARC Workstation.
This bug is similar to 4065656.
The following test program illustrates the problem. Compile and run with no arguments:
import java.io.*;
import java.net.*;
import java.util.*;
/**************************************************************************
* atest class
**************************************************************************/
public final class atest {
private static boolean verboseflag = true;
private static final int port = 26000;
public static void main(String[] args) {
atest a = new atest();
}
// Constructor
public atest() {
DatagramSocket d = null;
InetAddress iaddr = null;
logverbose("TEST #1 calling DatagramSocket()");
try {
d = new DatagramSocket();
DumpDatagramSocketInfo(d);
iaddr = InetAddress.getByName("localhost");
//DumpInetAddressInfo(iaddr);
} catch(Exception e) {
logerr("atest.main(): exception occurred:\n" + e);
return;
}
d.close();
System.out.println();
logverbose("TEST #2 calling DatagramSocket(" + port + ")");
try {
d = new DatagramSocket(port);
DumpDatagramSocketInfo(d);
iaddr = InetAddress.getByName("localhost");
//DumpInetAddressInfo(iaddr);
} catch(Exception e) {
logerr("atest.main(): exception occurred:\n" + e);
return;
}
d.close();
System.out.println();
try {
iaddr = InetAddress.getByName("localhost");
logverbose(
"TEST #3 calling DatagramSocket(" + port + ", " + iaddr + ")");
d = new DatagramSocket(port, iaddr);
DumpDatagramSocketInfo(d);
iaddr = InetAddress.getByName("localhost");
//DumpInetAddressInfo(iaddr);
} catch(Exception e) {
logerr("atest.main(): exception occurred:\n" + e);
return;
}
d.close();
}
// logout Method
public static void logout(String s) {
System.out.println(s);
System.out.flush();
}
// logerr Method
public static void logerr(String s) {
System.err.println("ERROR: " + s);
System.err.flush();
}
// logverbose Method
public static void logverbose(String s) {
if(verboseflag) {
System.out.println("VERBOSE: " + s);
System.out.flush();
}
}
// DumpDatagramSocketInfo Method
public void DumpDatagramSocketInfo(DatagramSocket s) {
if(!verboseflag) return;
try {
logverbose("DATAGRAM SOCKET INFO");
logverbose("--------------------");
logverbose("getLocalPort() = " + s.getLocalPort());
logverbose("getSoTimeout() = " + s.getSoTimeout());
logverbose("Dump getLocalAddress()");
DumpInetAddressInfo(s.getLocalAddress());
} catch(Exception e) {
logerr("DumpDatagramSocketInfo(): caught exception\n" + e);
}
}
// DumpInetAddressInfo Method
public void DumpInetAddressInfo(InetAddress i) {
if(!verboseflag) return;
try {
String host = i.getHostName();
logverbose("INET ADDRESS INFO");
logverbose("-----------------");
logverbose("getHostName() = " + i.getHostName());
InetAddress iaddrs[] = i.getAllByName(host);
for(int j=0; j<iaddrs.length; j++)
logverbose("getAllByName[" + j + "] = " + iaddrs[j]);
logverbose("getByName() = " + i.getByName(host));
logverbose("getLocalHost() = " + i.getLocalHost());
logverbose("FIX: getAddress() = " + new String(i.getAddress()));
logverbose("getHostAddress() = " + i.getHostAddress());
logverbose("isMulticastAddress() = " + i.isMulticastAddress());
} catch(Exception e) {
logerr("DumpInetAddressInfo(): caught exception\n" + e);
}
}
}
VERBOSE: port number is = 26500
VERBOSE: buffer size is = 1K
VERBOSE: sleep delay between sending messages = 25
VERBOSE: real buffer size is = 1024
VERBOSE: multicast address is = 224.0.0.1
VERBOSE: number of messages = 50
VERBOSE: loop count is = 5
VERBOSE: random buffer sizes = false
DEBUG: creating multicast datagram socket
DEBUG: MULTICAST DATAGRAM SOCKET INFO
DEBUG: ------------------------------
DEBUG: getLocalPort() = 52431
DEBUG: getSoTimeout() = 0
DEBUG: getTTL() = 1
DEBUG: Dump getLocalAddress()
DEBUG: INET ADDRESS INFO
DEBUG: -----------------
DEBUG: getHostName() = 0.0.0.0
DEBUG: getAllByName[0] = 0.0.0.0/0.0.0.0
DEBUG: getByName() = 0.0.0.0/0.0.0.0
DEBUG: getLocalHost() = caffeine.East.Sun.COM/129.148.27.72
DEBUG: getHostAddress() = 0.0.0.0
DEBUG: isMulticastAddress() = false
DEBUG: Dump getInterface()
DEBUG: INET ADDRESS INFO
DEBUG: -----------------
DEBUG: getHostName() = 0.0.0.0
DEBUG: getAllByName[0] = 0.0.0.0/0.0.0.0
DEBUG: getByName() = 0.0.0.0/0.0.0.0
DEBUG: getLocalHost() = caffeine.East.Sun.COM/129.148.27.72
DEBUG: getHostAddress() = 0.0.0.0
DEBUG: isMulticastAddress() = false
- relates to
-
JDK-4065656 ServerSocket.getInetAddress() returns incorrect IP address.
- Closed