From 4bd4d2b2927c87b65de915d42ebd7c082ae13ff8 Mon Sep 17 00:00:00 2001 From: Yuri Sevatz Date: Thu, 17 Dec 2020 04:52:58 -0500 Subject: Fix gateway detection when gateway in routing table with all null's --- netifaces.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/netifaces.c b/netifaces.c index bf18c80..ffaf8c8 100644 --- a/netifaces.c +++ b/netifaces.c @@ -1894,8 +1894,14 @@ gateways (PyObject *self) attr = RTA_NEXT(attr, len); } + static const unsigned char ipv4_default[4] = {}; + static const unsigned char ipv6_default[16] = {}; + /* We're looking for gateways with no destination */ - if (!dst && gw && ifndx >= 0) { + if ((!dst + || (pmsg->rt.rtm_family == AF_INET && !memcmp(dst, ipv4_default, sizeof(ipv4_default))) + || (pmsg->rt.rtm_family == AF_INET6 && !memcmp(dst, ipv6_default, sizeof(ipv6_default))) + ) && gw && ifndx >= 0) { char buffer[256]; char ifnamebuf[IF_NAMESIZE]; char *ifname; -- cgit v1.2.1