On Thu, 12 Nov 1998, Mark Hofmann wrote:
> Hi all,
>
> I've posted that question a few days ago to java.lang.programmer
> but got no response :-(
> But, since this problem is really bugging me, and there might be some
> people in this list that run there progs under NT and Linux, just as me,
> I hope to find a solution here.
> Anyway, here is the problem, easy and simple ....
>
> when I use
> String localhostname=(InetAddress.getLocalHost()).getHostName();
> under Linux I get the fully qualified hostname, under NT just the local
> hostname, eg. host instead of host.my.domain.com
>
I've seen divergent behaviours too and never been quite sure. I suggest
that, having got your host name you then get its IP address and then do a
reverse lookup to get the fully-qualified name associated with that IP
address.
Of course, this might not always give the desired result: if an IP address
is associated with more than one hostname (a valid confguration) you'll
need to decide for yourself how important that is. Here's what might happen
here:
[summer@emu JAVA]$ nslookup proxy
Server: localhost
Address: 127.0.0.1
Name: emu.os2.ami.com.au
Addresses: 192.168.1.2, 192.168.0.2
Aliases: proxy.os2.ami.com.au
[summer@emu JAVA]$ nslookup 192.168.1.2
Server: localhost
Address: 127.0.0.1
Name: emu.os2.ami.com.au
Address: 192.168.1.2
Well, actually that machine's "hostname" command returns
emu.os2.ami.com.au, but it illustrates the point.
Be aware the domain names might not match either: I could configure a
domain charlie.ibm.com and map it to the same IP addresses I use for
os2.ami.com.au. I imagine I can provide both reverse mappings too: that could
really confuse things.
Cheers
John Summerfield
http://os2.ami.com.au/os2/ for OS/2 support.
Configuration, networking, combined IBM ftpsites index.