BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

InetAddress puzzle: Windows and Linux

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE
View previous topic :: View next topic  
Author Message
Arun Bommannavar
Guest





PostPosted: Thu May 17, 2007 6:31 pm    Post subject: InetAddress puzzle: Windows and Linux Reply with 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?
Back to top
Shankar Unni
Guest





PostPosted: Fri May 18, 2007 12:18 am    Post subject: Re: InetAddress puzzle: Windows and Linux Reply with quote



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





PostPosted: Fri May 18, 2007 12:49 am    Post subject: Re: InetAddress puzzle: Windows and Linux Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.