On Tue, 15 Apr 2025 08:58:21 GMT, Jaikiran Pai <j...@openjdk.org> wrote:
> Can I please get a review of this change which proposes to address the issue > noted in https://bugs.openjdk.org/browse/JDK-8354576? > > As noted in that issue, the current code in the `lookupAllHostAddr()` > function of `Inet4AddressImpl.c` and `Inet6AddressImpl.c` has a macos > specific implementation, where we call `getifaddrs()` and iterate over the > returned addresses. In its current form this code doesn't check to see if the > interface is UP or not. This can result in returing an address belonging to > an interface which is not UP. That can cause subsequent usage of the address > for networking operations to result in a "Network is down" error. > > The commit in this PR skips interfaces that are not UP. The change only > impacts the result of `getLocalHost()` call and that too only on macos. Given > the nature of this change no new regression test has been introduced. > Existing tests in tier1, tier2 and tier3 continue to pass with this change. Hello Volkan, > We don't need this IFF_UP check for the below methods in NetworkInterface.c, > right? > enumIPv4Interfaces > enumIPv6Interfaces > getMacAddress These functions on `NetworkInterface.c` provide support for various APIs in the `java.net.NetworkInterface` class. The `enumIPv4Interfaces` and `enumIPv6Interfaces` are there primarily to list all available network interfaces and return the corresponding `NetworkInterface` instances. So unlike the `InetAddress.getLocalHost()` implementation, these APIs and the underlying functions merely pass along the available interfaces to the application. The `NetworkInterface` class has a `isUp()` API which the application can then use to do additional checks on that `NetworkInterface` instance. The `getMacAddress()` function, which supports the `NetworkInterface.getHardwareAddress()` API, too doesn't need to bother about whether the interface is UP or not. So that one too doesn't require this change. The reason `InetAddress.getLocalHost()` requires this special treatment is because that API is meant to return back an `InetAddress` of local host. It just so happens that on macos we have some special logic which iterates over interfaces to find the "right" address. Application code has no control over these network interfaces and this iteration thus needs to do these additional checks to make sure that it doesn't return back an `InetAddress` which is unusable. ------------- PR Comment: https://git.openjdk.org/jdk/pull/24653#issuecomment-2808763449