diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2023-03-17 21:56:00 +0800 |
---|---|---|
committer | FranklinDM <mrmineshafter17@gmail.com> | 2023-04-07 22:20:38 +0800 |
commit | 4cc241fb63131f12c099d9311ab83fcd89b74818 (patch) | |
tree | 34f9da5287bc1bab2d098d47a3cbafff53af9584 | |
parent | 8e2788496d325b4b50b86d98125376b5dbdf7554 (diff) | |
download | uxp-4cc241fb63131f12c099d9311ab83fcd89b74818.tar.gz |
No issue - Use inet_ntop() for converting IPv4 network addresses instead of the deprecated inet_ntoa()
The original implementation opted to silence the warnings instead and use the deprecated inet_ntoa() as a Windows XP consideration (bug 1240932). Since we've removed support for that platform, it makes sense to use the modern inet_ntop() API instead.
-rw-r--r-- | netwerk/system/win32/nsNotifyAddrListener.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/netwerk/system/win32/nsNotifyAddrListener.cpp b/netwerk/system/win32/nsNotifyAddrListener.cpp index 3216a24909..7b15cfd4c1 100644 --- a/netwerk/system/win32/nsNotifyAddrListener.cpp +++ b/netwerk/system/win32/nsNotifyAddrListener.cpp @@ -13,6 +13,7 @@ #include <objbase.h> #include <winsock2.h> #include <ws2ipdef.h> +#include <ws2tcpip.h> #include <tcpmib.h> #include <iphlpapi.h> #include <netioapi.h> @@ -191,10 +192,11 @@ bool nsNotifyAddrListener::findMac(char *gateway) continue; } - struct in_addr addr; - addr.s_addr = pIpNetTable->table[i].dwAddr; + void *addr = &(pIpNetTable->table[i].dwAddr); + char ipStr[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, addr, (PSTR)ipStr, sizeof(ipStr)); - if (!strcmp(gateway, inet_ntoa(addr))) { + if (!strcmp(gateway, ipStr)) { LOG(("networkid: MAC %s\n", hw)); nsAutoCString mac(hw); // This 'addition' could potentially be a @@ -246,15 +248,13 @@ static bool defaultgw(char *aGateway, size_t aGatewayLen) if (retVal == NO_ERROR) { for (unsigned int i = 0; i < pIpForwardTable->dwNumEntries; ++i) { // Convert IPv4 addresses to strings - struct in_addr IpAddr; - IpAddr.S_un.S_addr = static_cast<u_long> - (pIpForwardTable->table[i].dwForwardDest); - char *ipStr = inet_ntoa(IpAddr); + void *ipAddr = &(pIpForwardTable->table[i].dwForwardDest); + char ipStr[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, ipAddr, (PSTR)ipStr, sizeof(ipStr)); if (ipStr && !strcmp("0.0.0.0", ipStr)) { // Default gateway! - IpAddr.S_un.S_addr = static_cast<u_long> - (pIpForwardTable->table[i].dwForwardNextHop); - ipStr = inet_ntoa(IpAddr); + ipAddr = &(pIpForwardTable->table[i].dwForwardNextHop); + inet_ntop(AF_INET, ipAddr, (PSTR)ipStr, sizeof(ipStr)); if (ipStr) { strcpy_s(aGateway, aGatewayLen, ipStr); return true; |