Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Localhost isn't localhost

Reply
Thread Tools

Localhost isn't localhost

 
 
EdwardH
Guest
Posts: n/a
 
      09-29-2005
> I dunno..I will ask my professor tomorrow as the first thing in the
> morning. can you wait?


Sure. Doubt he'll be able to explain it.

 
Reply With Quote
 
 
 
 
EdwardH
Guest
Posts: n/a
 
      09-29-2005
> Your local host may have many aliases.

Except "localhost" is universally known to resolve to 127.0.0.1 ...
except in Java, for some reason.
 
Reply With Quote
 
 
 
 
Darryl L. Pierce
Guest
Posts: n/a
 
      09-29-2005
EdwardH wrote:
> Why does...
>
> InetAddress inetAddress = InetAddress.getLocalHost();
>
> return 192.168.0.2? It should return 127.0.0.1, shouldn't it?


If it were going to return a constant value like the lo interface, then
it would be a constant and not a method. getLocalHost() returns the true
address for the machine. Otherwise, "if the operation is not allowed, an
InetAddress representing the loopback address is returned."

--
Darryl L. Pierce <(E-Mail Removed)>
Homepage: http://mcpierce.multiply.com/
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant
 
Reply With Quote
 
Darryl L. Pierce
Guest
Posts: n/a
 
      09-29-2005
Jeff Schwab wrote:
> Probably not the "true" IP address. That looks like a NAT address,
> probably from a machine connected to a small router. The router is
> probably at 192.168.0.1.


If it's assigned to the machine, then it's a true address. It may not be
the *public* address (i.e., what's visible from the 'net itself) but
it's a true address.

--
Darryl L. Pierce <(E-Mail Removed)>
Homepage: http://mcpierce.multiply.com/
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant
 
Reply With Quote
 
Darryl L. Pierce
Guest
Posts: n/a
 
      09-29-2005
EdwardH wrote:
>> Your local host may have many aliases.

>
>
> Except "localhost" is universally known to resolve to 127.0.0.1 ...
> except in Java, for some reason.


But, you didn't use the API InetAddress.getByName("localhost"), which
would resolve to 127.0.0.1. You used InetAddress.getLocalHost() which
returns the IP address for your machine. There's a very clear difference
there.

--
Darryl L. Pierce <(E-Mail Removed)>
Homepage: http://mcpierce.multiply.com/
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant
 
Reply With Quote
 
Jeff Schwab
Guest
Posts: n/a
 
      09-29-2005
John C. Bollinger wrote:
> Jeff Schwab wrote:
>
>> Hal Rosser wrote:
>>
>>> "EdwardH" <edwardh@N:O:S:A:M:edward.dyndns.org> wrote in message
>>> news:wdH_e.147288$(E-Mail Removed)...
>>>
>>>> Why does...
>>>>
>>>> InetAddress inetAddress = InetAddress.getLocalHost();
>>>>
>>>> return 192.168.0.2? It should return 127.0.0.1, shouldn't it?
>>>
>>>
>>>
>>>
>>> The true IP address is returned.
>>> 127.0.0.1 ius just the ring-back address for 'any' machine.
>>> It would be useless to get 127.0.0.1 every time. That could be
>>> hard-coded.

>>
>>
>>
>> Probably not the "true" IP address. That looks like a NAT address,
>> probably from a machine connected to a small router. The router is
>> probably at 192.168.0.1.

>
>
> You choose an odd definition of "true".


Routable from outside the LAN.

> The address is one that is
> configured on a local network interface; from the machine's own point of
> view you can't get any more true than that. You are correct that the
> address is non-routable, which may (or may not) signal that the machine
> is behind a NAT service, but that is outside the scope of the inquiry.
> It important to recognize that the address obtained this way is not
> guaranteed to be useful in any particular broader scope, yes, but there
> are many reasons why that might be true of any network address.


Fair enough!
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-29-2005
On Thu, 29 Sep 2005 09:41:29 GMT, EdwardH
<edwardh@N:O:S:A:M:edward.dyndns.org> wrote or quoted :

>> Your local host may have many aliases.

>
>Except "localhost" is universally known to resolve to 127.0.0.1 ...
>except in Java, for some reason


localhost does resolve to 127.0.0.1. see
http://mindprod.com/jgloss/ip.html
and look at the code for WhoIs.

However, getLocalHost gives you the actual IP on the LAN of the local
host. Perhaps that method is misnamed. There is no need for a method
that always returns 127.0.0.1

There is no method to get you the face ip. That requires co-operation
from some outside server.

This is admittedly a lawyerly response.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
HalcyonWild
Guest
Posts: n/a
 
      09-30-2005

Roedy Green wrote:
> 192.168.0.2 would the IP address of that machine on the LAN, the one
> it responds to when the router forwards stuff to it.. To the outside
> world, all the machines on the LAN look like the same machine coming
> from the "face IP" -- the external IP of the router. To find the face
> IP see http://mindprod.com/jgloss/ip.html


On the windows command prompt, when I type ping localhost it gives me
127.0.0.1, when I say ping myMachineName.domain.com it gives me the IP
in the 192.168 series.
Is there anything special about 192.168 series. I saw the mindprod web
page mentioned, but did not find anything mentioned in particular,
except, for use in private Lans.
Is it true, that,
1. to my machine, my machine is 127.0.0.1
2. to other machines in my LAN, my machine is 192.168.x.x
3. to machines in the outside world of my LAN, my machine is something
else in the public domain.

 
Reply With Quote
 
John English
Guest
Posts: n/a
 
      09-30-2005
HalcyonWild wrote:

> Is there anything special about 192.168 series. I saw the mindprod web
> page mentioned, but did not find anything mentioned in particular,


The short answer is yes. For the long answer, ask Google to find you a
copy of RFC1597 & RFC1918.

----------------------------------------------------------------------
John English | (E-Mail Removed)
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
School of Computing & MIS | "Those who don't know their history
University of Brighton | are condemned to relive it" (Santayana)
----------------------------------------------------------------------
 
Reply With Quote
 
Darryl L. Pierce
Guest
Posts: n/a
 
      09-30-2005
HalcyonWild wrote:
> Is there anything special about 192.168 series.


Check out this page: http://www.faqs.org/rfcs/rfc1918.html

Your router is also your DHCP server, and it's handing out non-routable
IP addresses; i.e., they will not be broadcast over the Internet. The
router is then acting as a NAT and translating those addresses into
something that can be broadcast over the 'net. When the response is
received, the router then translates that response and sends it to the
right machine on the private network.

--
Darryl L. Pierce <(E-Mail Removed)>
Homepage: http://mcpierce.multiply.com/
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit Ring server to localhost only. RingFinger.new('localhost')apparently doesn't work koicat Ruby 0 07-02-2010 08:01 PM
change from "//localhost:numbers/" to just "//localhost/"? =?Utf-8?B?S2VuTGVl?= ASP .Net 5 02-12-2006 05:14 AM
How do you set up http://localhost? M Skabialka ASP .Net 10 04-27-2005 02:58 PM
Can I Reset the Root from localhost/myproject/ to localhost/ Alex ASP .Net 4 02-08-2005 01:45 PM
HttpModule -- how to intercept urls like http://localhost/abc/def or http://localhost/abc/def/ where abc, def are non virtual dir Jiong Feng ASP .Net 0 11-19-2003 05:29 AM



Advertisments