Skip to content

Commit 7766dd2

Browse files
committed
net: Replace ifname check with IFF_LOOPBACK in Discover
Checking the interface name is kind of brittle. In the age of network namespaces and containers, there is no reason a loopback interface can't be called differently. Check for the `IFF_LOOPBACK` flag to detect loopback interface instead.
1 parent 3aaf732 commit 7766dd2

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/net.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,8 +3077,7 @@ void Discover()
30773077
{
30783078
if (ifa->ifa_addr == nullptr) continue;
30793079
if ((ifa->ifa_flags & IFF_UP) == 0) continue;
3080-
if (strcmp(ifa->ifa_name, "lo") == 0) continue;
3081-
if (strcmp(ifa->ifa_name, "lo0") == 0) continue;
3080+
if ((ifa->ifa_flags & IFF_LOOPBACK) != 0) continue;
30823081
if (ifa->ifa_addr->sa_family == AF_INET)
30833082
{
30843083
struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);

0 commit comments

Comments
 (0)