diff -r 53f9c7b2c068 -r 5fc32e4b2a8c sources/network/ipaddress.cpp --- a/sources/network/ipaddress.cpp Wed Jan 27 18:55:14 2021 +0200 +++ b/sources/network/ipaddress.cpp Wed Jan 27 19:01:37 2021 +0200 @@ -120,19 +120,6 @@ } } -std::optional net::ip_scan_octets(const char* address_string) -{ - std::optional value; - net::octet_t parts[4]; - if (std::sscanf(address_string, "%hhu.%hhu.%hhu.%hhu", &parts[0], &parts[1], &parts[2], &parts[3])) - { - value = net::ip_address{}; - for (unsigned char i = 0; i < 4; i += 1) - ip_set_octet(&*value, i, parts[i]); - } - return value; -} - std::optional net::ip_resolve_hostname(const std::string& node, std::ostream& errorStream) { AddrInfo hints; @@ -160,8 +147,25 @@ std::string addressString = colonpos == -1 ? input_string : mid(input_string, 0, colonpos); std::optional value; // Try scanf the IPv4 host first - value = ip_scan_octets(addressString.data()); - if (not value.has_value()) + int parts[4]; + if (std::sscanf(addressString.data(), "%d.%d.%d.%d", &parts[0], &parts[1], &parts[2], &parts[3])) + { + value = net::ip_address{}; + for (unsigned char i = 0; i < 4; i += 1) + { + if (parts[i] >= 0 and parts[i] < 256) + { + ip_set_octet(&*value, i, parts[i]); + } + else + { + value.reset(); + errorStream << "IP address value out of range"; + break; + } + } + } + else { // Possibly a hostname, try resolve it value = ip_resolve_hostname(addressString, errorStream);