suggest improvement for java doc for getting address of local host

Alan Bateman Alan.Bateman at oracle.com
Fri Aug 5 06:44:12 UTC 2022


On 04/08/2022 23:24, mark.yagnatinsky at barclays.com wrote:
>
> I suspect that this is the wrong list; please redirect me if so.
>
> The docs for this method:
>
> https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/net/InetAddress.html#getLocalHost()
>
> say that it “Returns the address of the local host. This is achieved 
> by retrieving the name of the host from the system, then resolving 
> that name into an InetAddress.”
>
> This is true enough in simple cases, but horribly misleading in 
> non-trivial cases.
>
> As far as I can tell it can’t return “the address” because the local 
> host may have multiple addresses.
>
> Instead it returns “an address” of the local host.  My laptop right 
> now has 3 addresses: IPv6 loopback, IPv4 from home WiFi, and IPv4 from 
> company network via VPN.
>
> As far as I can tell (please correct me if I’m wrong!!) if there are 
> multiple addresses, the current implementation makes no effort to pick 
> a more “useful” one.
>
> Instead, it takes whatever addresses it gets from the OS and returns 
> the first one.
>
>
You need to click through to the Networking Properties to read more 
about configuration. The long standing default has been to prefer IPv4 
over IPv6 addresses. The OpenJDK net-dev mailing list is the place to 
follow-up on this.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20220805/4ea49d6c/attachment.htm>


More information about the jdk-dev mailing list