InetAddress - is it broken??
Erik Poupaert
erik.poupaert@chello.be
Thu Jun 12 21:36:00 GMT 2003
> I have discovered the following apparently malignant behavior in
> InetAddress.getLocalHost() on linux. Given the following brainless
> test program:
I have a similar problem with InetAddress.getLocalHost(). I don't
think, however, that the GCJ implementation is bugged. It's simply one
of these very confused APIs in the JDK (just as java.util.Date is
"confused")
I've solved it temporarily in the following way:
InetSocketAddress inetAddress=
(InetSocketAddress)socket.getRemoteSocketAddress();
String hostName=inetAddress.getAddress().getCanonicalHostName();
String remoteMachine=null;
if(hostName.equals("localhost"))
try
{
remoteMachine=InetAddress.getLocalHost().getHostName();
}
catch(UnknownHostException e)
{
inetAddress.getHostName();
}
else remoteMachine=inetAddress.getHostName();
I'm trying to create a utility that will do message queueing with
org.apache.xmlrpc invokations; and I need to keep track of the address
of the client machine, in order to send back results to the sender.
More information about the Java
mailing list