This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: InetAddress - is it broken??
- From: Erik Poupaert <erik dot poupaert at chello dot be>
- To: java at gcc dot gnu dot org
- Date: Thu, 12 Jun 2003 23:34:28 +0000
- Subject: Re: InetAddress - is it broken??
- References: <1055447814.24841.585.camel@zetar>
> 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.