]> git.gsnw.org Git - fping.git/commitdiff
stricter response type checking
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sat, 30 Nov 2024 18:12:28 +0000 (19:12 +0100)
committerErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sat, 7 Dec 2024 19:04:17 +0000 (20:04 +0100)
When sending an ICMP Echo message, accept only an Echo Reply
message as a normal response.  When sending an ICMP Timestamp
message, accept only an ICMP Timestamp message as a normal
response.

This could matter when multiple fping processes are running
in parallel, some using Echo, others Timestamp messages.

src/fping.c

index 029341fd444574d053517b6e3b5e7742c34ac702..1f57aa17770e26343875391fe8b5db354faacde5 100644 (file)
@@ -2218,7 +2218,8 @@ int decode_icmp_ipv4(
 
     icp = (struct icmp *)(reply_buf + hlen);
 
-    if (icp->icmp_type != ICMP_ECHOREPLY && icp->icmp_type != ICMP_TSTAMPREPLY) {
+    if ((icmp_request_typ == 0 && icp->icmp_type != ICMP_ECHOREPLY) ||
+        (icmp_request_typ == 13 && icp->icmp_type != ICMP_TSTAMPREPLY)) {
         /* Handle other ICMP packets */
         struct icmp *sent_icmp;
         SEQMAP_VALUE *seqmap_value;
@@ -2233,7 +2234,9 @@ int decode_icmp_ipv4(
 
         sent_icmp = (struct icmp *)(reply_buf + hlen + ICMP_MINLEN + sizeof(struct ip));
 
-        if ((sent_icmp->icmp_type != ICMP_ECHO && sent_icmp->icmp_type != ICMP_TSTAMP) || sent_icmp->icmp_id != ident4) {
+        if ((icmp_request_typ == 0 && sent_icmp->icmp_type != ICMP_ECHO) ||
+            (icmp_request_typ == 13 && sent_icmp->icmp_type != ICMP_TSTAMP) ||
+            sent_icmp->icmp_id != ident4) {
             /* not caused by us */
             return -1;
         }