From 603e206f36a99eb8aaf13b6fefd4f84e6991eb31 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 19 May 2018 21:29:07 -0700 Subject: [PATCH] fix netmask of routes on Windows The build_netmask function was incorrectly dividing the size of the bytes_type by 8. Also use b.size() instead of sizeof for consistency. I'm not 100% certain what the difference between DestinationPrefix.PrefixLength and SitePrefixLength is. It looks like SitePrefixLength is something specific to site-local addresses. Emperically I found DestinationPrefix.PrefixLength contains reasonable values while SitePrefixLength is always zero. --- src/enum_net.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 206cecb20..34739c99a 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -517,7 +517,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl using bytes_t = boost::asio::ip::address_v4::bytes_type; bytes_t b; std::memset(&b[0], 0xff, b.size()); - for (int i = int(sizeof(bytes_t)) / 8 - 1; i > 0; --i) + for (int i = int(b.size()) - 1; i > 0; --i) { if (bits < 8) { @@ -535,7 +535,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl using bytes_t = boost::asio::ip::address_v6::bytes_type; bytes_t b; std::memset(&b[0], 0xff, b.size()); - for (int i = int(sizeof(bytes_t)) / 8 - 1; i > 0; --i) + for (int i = int(b.size()) - 1; i > 0; --i) { if (bits < 8) { @@ -1116,7 +1116,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl r.gateway = sockaddr_to_address((const sockaddr*)&routes->Table[i].NextHop); r.destination = sockaddr_to_address( (const sockaddr*)&routes->Table[i].DestinationPrefix.Prefix); - r.netmask = build_netmask(routes->Table[i].SitePrefixLength + r.netmask = build_netmask(routes->Table[i].DestinationPrefix.PrefixLength , routes->Table[i].DestinationPrefix.Prefix.si_family); MIB_IFROW ifentry; ifentry.dwIndex = routes->Table[i].InterfaceIndex;