From 1fd349b8c2967c28033a08a71368a0b383be5203 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 9 Feb 2021 22:35:00 +0100 Subject: [PATCH] Userland: Use INET_ADDRSTRLEN for inet_ntop() buffers There's no point in using different, seemingly randomly sized buffers as the required size for storing an IPv4 address representation is well known (16 bytes). --- Userland/Utilities/host.cpp | 2 +- Userland/Utilities/nc.cpp | 4 ++-- Userland/Utilities/ping.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/host.cpp b/Userland/Utilities/host.cpp index e3908472b4..7c557780d8 100644 --- a/Userland/Utilities/host.cpp +++ b/Userland/Utilities/host.cpp @@ -68,7 +68,7 @@ int main(int argc, char** argv) return 1; } - char buffer[32]; + char buffer[INET_ADDRSTRLEN]; const char* ip_str = inet_ntop(AF_INET, hostent->h_addr_list[0], buffer, sizeof(buffer)); printf("%s is %s\n", name_or_ip, ip_str); diff --git a/Userland/Utilities/nc.cpp b/Userland/Utilities/nc.cpp index 8d4f0a7613..40c406c377 100644 --- a/Userland/Utilities/nc.cpp +++ b/Userland/Utilities/nc.cpp @@ -85,7 +85,7 @@ int main(int argc, char** argv) return 1; } - char addr_str[100]; + char addr_str[INET_ADDRSTRLEN]; struct sockaddr_in sin; socklen_t len; @@ -131,7 +131,7 @@ int main(int argc, char** argv) return 1; } - char addr_str[100]; + char addr_str[INET_ADDRSTRLEN]; struct sockaddr_in dst_addr; memset(&dst_addr, 0, sizeof(dst_addr)); diff --git a/Userland/Utilities/ping.cpp b/Userland/Utilities/ping.cpp index cec2b88fbb..78bf70ddfa 100644 --- a/Userland/Utilities/ping.cpp +++ b/Userland/Utilities/ping.cpp @@ -221,7 +221,7 @@ int main(int argc, char** argv) else if (ms > max_ms) max_ms = ms; - char addr_buf[64]; + char addr_buf[INET_ADDRSTRLEN]; printf("Pong from %s: id=%u, seq=%u%s, time=%dms\n", inet_ntop(AF_INET, &peer_address.sin_addr, addr_buf, sizeof(addr_buf)), ntohs(pong_packet.header.un.echo.id),