diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-10-14 19:41:20 -0400 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-10-15 21:52:18 -0400 |
commit | c2d9c59dc9dd4ee1627627569ab4b0d45c60f103 (patch) | |
tree | 51a848aaf48deced00f798d5b7aaa3003532e236 /plugins-root/check_icmp.c | |
parent | c3150e6708509bb166b4c8fb5d1d2383eb020e88 (diff) | |
download | monitoring-plugins-c2d9c59dc9dd4ee1627627569ab4b0d45c60f103.tar.gz |
Increment per-host sequence in check_icmp
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r-- | plugins-root/check_icmp.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index cba7c440..1dde4478 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -333,14 +333,14 @@ handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr) * to RFC 792). If it isn't, just ignore it */ memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp)); if(sent_icmp.icmp_type != ICMP_ECHO || sent_icmp.icmp_id != pid || - sent_icmp.icmp_seq >= targets) + sent_icmp.icmp_seq >= targets*packets) { if(debug) printf("Packet is no response to a packet we sent\n"); return 0; } /* it is indeed a response for us */ - host = table[sent_icmp.icmp_seq]; + host = table[sent_icmp.icmp_seq/packets]; if(debug) { printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n", get_icmp_error_msg(p.icmp_type, p.icmp_code), @@ -624,7 +624,7 @@ main(int argc, char **argv) table = malloc(sizeof(struct rta_host **) * (argc - 1)); i = 0; while(host) { - host->id = i; + host->id = i*packets; table[i] = host; host = host->next; i++; @@ -763,12 +763,7 @@ wait_for_reply(int sock, u_int t) /* check the response */ memcpy(&icp, buf + hlen, sizeof(icp)); - if(icp.icmp_id != pid) { - handle_random_icmp(buf + hlen, &resp_addr); - continue; - } - - if(icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets) { + if(icp.icmp_id != pid || icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets*packets) { if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n"); handle_random_icmp(buf + hlen, &resp_addr); continue; @@ -776,8 +771,11 @@ wait_for_reply(int sock, u_int t) /* this is indeed a valid response */ memcpy(&data, icp.icmp_data, sizeof(data)); + if (debug > 2) + printf("ICMP echo-reply of len %u, id %u, seq %u, cksum 0x%X\n", + sizeof(data), icp.icmp_id, icp.icmp_seq, icp.icmp_cksum); - host = table[icp.icmp_seq]; + host = table[icp.icmp_seq/packets]; gettimeofday(&now, &tz); tdiff = get_timevaldiff(&data.stime, &now); @@ -848,9 +846,13 @@ send_icmp_ping(int sock, struct rta_host *host) packet.icp->icmp_code = 0; packet.icp->icmp_cksum = 0; packet.icp->icmp_id = pid; - packet.icp->icmp_seq = host->id; + packet.icp->icmp_seq = host->id++; packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size); + if (debug > 2) + printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n", + sizeof(data), packet.icp->icmp_id, packet.icp->icmp_seq, packet.icp->icmp_cksum, host->name); + len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr, sizeof(struct sockaddr)); |