1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:18:12 +00:00

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).
This commit is contained in:
Linus Groh 2021-02-09 22:35:00 +01:00 committed by Andreas Kling
parent f24b674d7a
commit 1fd349b8c2
3 changed files with 4 additions and 4 deletions

View file

@ -68,7 +68,7 @@ int main(int argc, char** argv)
return 1; 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)); 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); printf("%s is %s\n", name_or_ip, ip_str);

View file

@ -85,7 +85,7 @@ int main(int argc, char** argv)
return 1; return 1;
} }
char addr_str[100]; char addr_str[INET_ADDRSTRLEN];
struct sockaddr_in sin; struct sockaddr_in sin;
socklen_t len; socklen_t len;
@ -131,7 +131,7 @@ int main(int argc, char** argv)
return 1; return 1;
} }
char addr_str[100]; char addr_str[INET_ADDRSTRLEN];
struct sockaddr_in dst_addr; struct sockaddr_in dst_addr;
memset(&dst_addr, 0, sizeof(dst_addr)); memset(&dst_addr, 0, sizeof(dst_addr));

View file

@ -221,7 +221,7 @@ int main(int argc, char** argv)
else if (ms > max_ms) else if (ms > max_ms)
max_ms = 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", 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)), inet_ntop(AF_INET, &peer_address.sin_addr, addr_buf, sizeof(addr_buf)),
ntohs(pong_packet.header.un.echo.id), ntohs(pong_packet.header.un.echo.id),