summaryrefslogtreecommitdiffstats
path: root/plugins-root/check_icmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r--plugins-root/check_icmp.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index cba7c44..1dde447 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)
333 * to RFC 792). If it isn't, just ignore it */ 333 * to RFC 792). If it isn't, just ignore it */
334 memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp)); 334 memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp));
335 if(sent_icmp.icmp_type != ICMP_ECHO || sent_icmp.icmp_id != pid || 335 if(sent_icmp.icmp_type != ICMP_ECHO || sent_icmp.icmp_id != pid ||
336 sent_icmp.icmp_seq >= targets) 336 sent_icmp.icmp_seq >= targets*packets)
337 { 337 {
338 if(debug) printf("Packet is no response to a packet we sent\n"); 338 if(debug) printf("Packet is no response to a packet we sent\n");
339 return 0; 339 return 0;
340 } 340 }
341 341
342 /* it is indeed a response for us */ 342 /* it is indeed a response for us */
343 host = table[sent_icmp.icmp_seq]; 343 host = table[sent_icmp.icmp_seq/packets];
344 if(debug) { 344 if(debug) {
345 printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n", 345 printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n",
346 get_icmp_error_msg(p.icmp_type, p.icmp_code), 346 get_icmp_error_msg(p.icmp_type, p.icmp_code),
@@ -624,7 +624,7 @@ main(int argc, char **argv)
624 table = malloc(sizeof(struct rta_host **) * (argc - 1)); 624 table = malloc(sizeof(struct rta_host **) * (argc - 1));
625 i = 0; 625 i = 0;
626 while(host) { 626 while(host) {
627 host->id = i; 627 host->id = i*packets;
628 table[i] = host; 628 table[i] = host;
629 host = host->next; 629 host = host->next;
630 i++; 630 i++;
@@ -763,12 +763,7 @@ wait_for_reply(int sock, u_int t)
763 /* check the response */ 763 /* check the response */
764 memcpy(&icp, buf + hlen, sizeof(icp)); 764 memcpy(&icp, buf + hlen, sizeof(icp));
765 765
766 if(icp.icmp_id != pid) { 766 if(icp.icmp_id != pid || icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets*packets) {
767 handle_random_icmp(buf + hlen, &resp_addr);
768 continue;
769 }
770
771 if(icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets) {
772 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n"); 767 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n");
773 handle_random_icmp(buf + hlen, &resp_addr); 768 handle_random_icmp(buf + hlen, &resp_addr);
774 continue; 769 continue;
@@ -776,8 +771,11 @@ wait_for_reply(int sock, u_int t)
776 771
777 /* this is indeed a valid response */ 772 /* this is indeed a valid response */
778 memcpy(&data, icp.icmp_data, sizeof(data)); 773 memcpy(&data, icp.icmp_data, sizeof(data));
774 if (debug > 2)
775 printf("ICMP echo-reply of len %u, id %u, seq %u, cksum 0x%X\n",
776 sizeof(data), icp.icmp_id, icp.icmp_seq, icp.icmp_cksum);
779 777
780 host = table[icp.icmp_seq]; 778 host = table[icp.icmp_seq/packets];
781 gettimeofday(&now, &tz); 779 gettimeofday(&now, &tz);
782 tdiff = get_timevaldiff(&data.stime, &now); 780 tdiff = get_timevaldiff(&data.stime, &now);
783 781
@@ -848,9 +846,13 @@ send_icmp_ping(int sock, struct rta_host *host)
848 packet.icp->icmp_code = 0; 846 packet.icp->icmp_code = 0;
849 packet.icp->icmp_cksum = 0; 847 packet.icp->icmp_cksum = 0;
850 packet.icp->icmp_id = pid; 848 packet.icp->icmp_id = pid;
851 packet.icp->icmp_seq = host->id; 849 packet.icp->icmp_seq = host->id++;
852 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size); 850 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size);
853 851
852 if (debug > 2)
853 printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n",
854 sizeof(data), packet.icp->icmp_id, packet.icp->icmp_seq, packet.icp->icmp_cksum, host->name);
855
854 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr, 856 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr,
855 sizeof(struct sockaddr)); 857 sizeof(struct sockaddr));
856 858