Skip to content

Commit 4c3c2b3

Browse files
committed
8354576: InetAddress.getLocalHost() on macos may return address of an interface which is not UP - leading to "Network is down" error
Reviewed-by: alanb, dfuchs, vyazici
1 parent 18d605f commit 4c3c2b3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/java.base/unix/native/libnet/Inet6AddressImpl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -126,7 +126,7 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6, int cha
126126
while (iter) {
127127
if (iter->ifa_addr != NULL) {
128128
int family = iter->ifa_addr->sa_family;
129-
if (iter->ifa_name[0] != '\0') {
129+
if (iter->ifa_name[0] != '\0' && (iter->ifa_flags & IFF_UP) == IFF_UP) {
130130
jboolean isLoopback = iter->ifa_flags & IFF_LOOPBACK;
131131
if (family == AF_INET) {
132132
addrs4++;
@@ -163,7 +163,7 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6, int cha
163163
// Now loop around the ifaddrs
164164
iter = ifa;
165165
while (iter != NULL) {
166-
if (iter->ifa_addr != NULL) {
166+
if (iter->ifa_addr != NULL && (iter->ifa_flags & IFF_UP) == IFF_UP) {
167167
jboolean isLoopback = iter->ifa_flags & IFF_LOOPBACK;
168168
int family = iter->ifa_addr->sa_family;
169169

0 commit comments

Comments
 (0)