From: aafbsd <45147422+aafbsd@users.noreply.github.com> Date: Sat, 7 Aug 2021 09:51:04 +0000 (+0200) Subject: Update fping.c X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbe847a5d9ae20b5e27689cd485e62649fb32491;p=fping.git Update fping.c getnameinfo() was not called properly for IPv4 (didn't check v6). Additionally, one might also want to check the result code, call gai_strerror() and inform the user if s.th. goes wrong --- diff --git a/src/fping.c b/src/fping.c index c6209c1..b889193 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2102,7 +2102,7 @@ int decode_icmp_ipv4( /* too short */ if (verbose_flag) { char buf[INET6_ADDRSTRLEN]; - getnameinfo((struct sockaddr*)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); + getnameinfo( response_addr, sizeof( struct sockaddr_in ), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); printf("received packet too short for ICMP (%d bytes from %s)\n", (int)reply_buf_len, buf); } return -1; @@ -2135,7 +2135,7 @@ int decode_icmp_ipv4( return -1; } - getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); + getnameinfo(response_addr, sizeof( struct sockaddr_in ), addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); switch (icp->icmp_type) { case ICMP_UNREACH: