Re: InetAddress.getLocalHost() returns different values in different threads
On Oct 25, 1:06 pm, Mark Space <marksp...@sbc.global.net> wrote:
ociardhp wrote:
The output I see in my logs is as follows:
INFO: 17:41:39 com.cominded.diag.UpstreamProxy@6131844: Thread started
in init running on MSIE6/10.0.1.185
INFO: 17:41:47 com.cominded.diag.UpstreamProxy@6131844: New thread
running on localhost/127.0.0.1
INFO: 17:41:49 com.cominded.diag.UpstreamProxy@6131844: Thread started
in init running on MSIE6/10.0.1.185
There are all legal values for a local IP address. It seems to me that
getLocalHost() is return *all* values in sequence each time it is
called, although I haven't checked the docs. Is there some way to get
all IP addresses or a count of how many IP addresses your localhost has?
If not you just might have to read values until they start to repeat,
then manage the list yourself.
I'm not sure I agree. The documentation says:
" If the operation is not allowed, an InetAddress representing the
loopback address is returned."
In networking circles, "the loopback address" is a specific technical
term; without going into too much detail, it seems to me that that
should always return an InetAddress representing an address in
127.0.0.0/8 somewhere, and not 10.0.0.0/8 (even if the machine has
interfaces in that network).
That said, I don't see any reason not to use InetAddress.getByName
("127.0.0.1") [0] if you want to connect to 127.0.0.1 specifically.
The IP specification demands that that be a loopback address.
[0] "The host name can either be a machine name, such as
"java.sun.com", or a textual representation of its IP address.". Yes,
even for getByName. Surprise!