From b6dcb5e7ae28327c5151f0b2c4c88bc6dadb9b31 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Jul 2019 11:40:12 +0200 Subject: [PATCH] LibC: Use IPv4Address::from_string() in gethostbyname(). --- Libraries/LibC/netdb.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Libraries/LibC/netdb.cpp b/Libraries/LibC/netdb.cpp index 697627a11c1..7843fec4d73 100644 --- a/Libraries/LibC/netdb.cpp +++ b/Libraries/LibC/netdb.cpp @@ -51,17 +51,13 @@ static int connect_to_lookup_server() hostent* gethostbyname(const char* name) { - unsigned a; - unsigned b; - unsigned c; - unsigned d; - int count = sscanf(name, "%u.%u.%u.%u", &a, &b, &c, &d); - if (count == 4 && a < 256 && b < 256 && c < 256 && d < 256) { - sprintf(__gethostbyname_name_buffer, "%u.%u.%u.%u", a, b, c, d); + auto ipv4_address = IPv4Address::from_string(name); + if (ipv4_address.has_value()) { + sprintf(__gethostbyname_name_buffer, "%s", ipv4_address.value().to_string().characters()); __gethostbyname_buffer.h_name = __gethostbyname_name_buffer; __gethostbyname_buffer.h_aliases = nullptr; __gethostbyname_buffer.h_addrtype = AF_INET; - new (&__gethostbyname_address) IPv4Address(a, b, c, d); + new (&__gethostbyname_address) IPv4Address(ipv4_address.value()); __gethostbyname_address_list_buffer[0] = &__gethostbyname_address; __gethostbyname_address_list_buffer[1] = nullptr; __gethostbyname_buffer.h_addr_list = (char**)__gethostbyname_address_list_buffer;