From 86f98ddf5fd9ac7bf4b39c1915d41ba286c4af90 Mon Sep 17 00:00:00 2001 From: Jacob Shin Date: Sat, 4 Jan 2020 01:34:10 -0500 Subject: [PATCH] Used the INET_ADDRSTRLEN constant for network functions (#1172) --- src/lib_ccx/networking.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib_ccx/networking.c b/src/lib_ccx/networking.c index 4b4c7083..cf37a5b2 100644 --- a/src/lib_ccx/networking.c +++ b/src/lib_ccx/networking.c @@ -335,7 +335,7 @@ int net_udp_read(int socket, void *buffer, size_t length, const char *src_str, c assert(length > 0); int i; - char ip[15]; + char ip[INET_ADDRSTRLEN]; struct sockaddr_in source_addr; socklen_t len = sizeof(source_addr); /* Get address of host to check for udp network mutlicasting */ @@ -354,7 +354,7 @@ int net_udp_read(int socket, void *buffer, size_t length, const char *src_str, c { do { i = recvfrom(socket, (char *) buffer, length, 0, (struct sockaddr*)&source_addr, &len); /* peek at the data*/ - memset(ip, 0, sizeof(char) * 15); + memset(ip, 0, sizeof(char) * INET_ADDRSTRLEN); memcpy(ip, inet_ntoa(source_addr.sin_addr), sizeof(ip)); } while (strcmp(ip, src_str)!=0); /* Loop till we find intended source */ } @@ -1093,13 +1093,13 @@ int start_upd_srv(const char *src_str, const char *addr_str, unsigned port) { struct in_addr source; struct in_addr group; - char src_ip[15]; - char addr_ip[15]; + char src_ip[INET_ADDRSTRLEN]; + char addr_ip[INET_ADDRSTRLEN]; source.s_addr = htonl(src); - memset(src_ip, 0, sizeof(char) * 15); + memset(src_ip, 0, sizeof(char) * INET_ADDRSTRLEN); memcpy(src_ip, inet_ntoa(source), sizeof(src_ip)); group.s_addr = htonl(addr); - memset(addr_ip, 0, sizeof(char) * 15); + memset(addr_ip, 0, sizeof(char) * INET_ADDRSTRLEN); memcpy(addr_ip, inet_ntoa(group), sizeof(addr_ip)); mprint("\rReading from UDP socket %s@%s:%u\n", src_ip, addr_ip, port);