[PATCH 3/4] iphlpapi: Use the dst sa_family for the netmask too.

Stefan Dösinger stefan at codeweavers.com
Sun Apr 12 07:24:56 CDT 2020


Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>

---

See the definition of p_sockaddr in https://opensource.apple.com/source/network_cmds/network_cmds-596/netstat.tproj/route.c
and what it does with the mask parameter.
---
 dlls/iphlpapi/ipstats.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index fe4d3f4588..38f5927cc0 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -1508,6 +1508,7 @@ DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForw
        for (next = buf; next < lim; next += rtm->rtm_msglen)
        {
           int i;
+          sa_family_t dst_family = AF_UNSPEC;
 
           rtm = (struct rt_msghdr *)next;
 
@@ -1551,7 +1552,10 @@ DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForw
              if (sa->sa_len == 0) {
                 addr = 0;
              }else {
-                 switch(sa->sa_family) {
+                 /* Apple's netstat prints the netmask together with the destination
+                  * and only looks at the destination's address family. The netmask's
+                  * sa_family sometimes contains the non-existent value 0xff. */
+                 switch(i == RTA_NETMASK ? dst_family : sa->sa_family) {
                  case AF_INET: {
                      struct sockaddr_in *sin = (struct sockaddr_in *)sa;
                      addr = sin->sin_addr.s_addr;
@@ -1575,7 +1579,10 @@ DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForw
 
              switch (i)
              {
-                case RTA_DST:     row.dwForwardDest = addr; break;
+                case RTA_DST:
+                   row.dwForwardDest = addr;
+                   dst_family = sa->sa_family;
+                   break;
                 case RTA_GATEWAY: row.dwForwardNextHop = addr; break;
                 case RTA_NETMASK: row.dwForwardMask = addr; break;
                 default:
-- 
2.24.1 (Apple Git-126)




More information about the wine-devel mailing list