 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Arun Bommannavar Guest
|
Posted: Thu May 17, 2007 6:31 pm Post subject: InetAddress puzzle: Windows and Linux |
|
|
InetAddress addr = InetAddress.getLocalHost();
gives correct Ip Address on my Windows machine but gives local loop back
adress (127.0.0.1) for a Linux machine. Why? Is the Linux machine not
configured right? |
|
| Back to top |
|
 |
Shankar Unni Guest
|
Posted: Fri May 18, 2007 12:18 am Post subject: Re: InetAddress puzzle: Windows and Linux |
|
|
Arun Bommannavar wrote:
| Quote: | InetAddress addr = InetAddress.getLocalHost();
gives correct Ip Address on my Windows machine but gives local loop back
adress (127.0.0.1) for a Linux machine. Why? Is the Linux machine not
configured right?
|
You can thank Red Hat for that.
They have this stupid misfeature where they try to "optimize" your local
network access by making /etc/hosts read:
127.0.0.1 localhost <yourmachinename>
and they don't put your real IP address in /etc/hosts at all (even for
static IP configurations).
So any tool that tries to resolve the name <yourmachinename> while on
your machine will always get back 127.0.0.1.
There's only one way to fix that:
* Fix your /etc/hosts to say
127.0.0.1 localhost
##.##.##.## yourmachinename # use the real IP address
# here, of course..
Because Java doesn't (until Java5, anyway) expose any APIs to enumerate
your physical network interfaces, that's all you have upto and including
Java5.
For Java6, there are other workarounds, like enumerating your network
interfaces and picking out a likely non-127 address. |
|
| Back to top |
|
 |
Kevin Dean [TeamB] Guest
|
Posted: Fri May 18, 2007 12:49 am Post subject: Re: InetAddress puzzle: Windows and Linux |
|
|
Arun Bommannavar wrote:
| Quote: | InetAddress addr = InetAddress.getLocalHost();
gives correct Ip Address on my Windows machine but gives local loop back adress (127.0.0.1) for a Linux machine. Why? Is the Linux machine not configured right?
|
According to the documentation:
If there is a security manager, its checkConnect method is called with the local host name and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, an InetAddress representing the loopback address is returned.
Also, see this link:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/
Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|