From 7a66f373fcf522ebeb1849539ea40a42bf12d1c4 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 17 Oct 2020 15:19:58 +0200 Subject: [PATCH] inet_pton() instead of inet_addr() --- miniupnpc/addr_is_reserved.c | 9 ++++++--- miniupnpc/minissdpc.c | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/miniupnpc/addr_is_reserved.c b/miniupnpc/addr_is_reserved.c index 7adee9a..8fc9f0b 100644 --- a/miniupnpc/addr_is_reserved.c +++ b/miniupnpc/addr_is_reserved.c @@ -52,11 +52,14 @@ static const struct { uint32_t address; uint32_t rmask; } reserved[] = { */ int addr_is_reserved(const char * addr_str) { - unsigned long addr_n; - uint32_t address; + uint32_t addr_n, address; size_t i; - addr_n = inet_addr(addr_str); + /* was : addr_n = inet_addr(addr_str); */ + if (inet_pton(AF_INET, addr_str, &addr_n) < 0) { + /* error */ + return 0; + } if (addr_n == INADDR_NONE) return 1; diff --git a/miniupnpc/minissdpc.c b/miniupnpc/minissdpc.c index dc10f96..db8f4b3 100644 --- a/miniupnpc/minissdpc.c +++ b/miniupnpc/minissdpc.c @@ -720,7 +720,10 @@ ssdpDiscoverDevices(const char * const deviceTypes[], #if defined(_WIN32) && (_WIN32_WINNT >= _WIN32_WINNT_VISTA) InetPtonA(AF_INET, multicastif, &mc_if); #else - mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */ + /* was : mc_if.s_addr = inet_addr(multicastif); */ /* ex: 192.168.x.x */ + if (inet_pton(AF_INET, multicastif, &mc_if.s_addr) < 0) { + mc_if.s_addr = INADDR_NONE; + } #endif if(mc_if.s_addr != INADDR_NONE) {