summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-10-16 02:11:39 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-10-16 02:12:32 (GMT)
commit9c1aa029c088d6d52c7978198136731925c5f385 (patch)
treeb57f583fe710cc7a88116cf40b3e83b62081bf4f /plugins-root
parentc2d9c59dc9dd4ee1627627569ab4b0d45c60f103 (diff)
downloadmonitoring-plugins-9c1aa029c088d6d52c7978198136731925c5f385.tar.gz
Set proper network byte order for icmp_id and icmp_seq in icmp packets
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_icmp.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 1dde447..2a1b813 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -306,7 +306,7 @@ handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr)
306 struct rta_host *host = NULL; 306 struct rta_host *host = NULL;
307 307
308 memcpy(&p, packet, sizeof(p)); 308 memcpy(&p, packet, sizeof(p));
309 if(p.icmp_type == ICMP_ECHO && p.icmp_id == pid) { 309 if(p.icmp_type == ICMP_ECHO && ntohs(p.icmp_id) == pid) {
310 /* echo request from us to us (pinging localhost) */ 310 /* echo request from us to us (pinging localhost) */
311 return 0; 311 return 0;
312 } 312 }
@@ -332,15 +332,15 @@ handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr)
332 /* might be for us. At least it holds the original package (according 332 /* might be for us. At least it holds the original package (according
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 || ntohs(sent_icmp.icmp_id) != pid ||
336 sent_icmp.icmp_seq >= targets*packets) 336 ntohs(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/packets]; 343 host = table[ntohs(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),
@@ -763,7 +763,8 @@ 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 || icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets*packets) { 766 if(ntohs(icp.icmp_id) != pid || icp.icmp_type != ICMP_ECHOREPLY ||
767 ntohs(icp.icmp_seq) >= targets*packets) {
767 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n"); 768 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n");
768 handle_random_icmp(buf + hlen, &resp_addr); 769 handle_random_icmp(buf + hlen, &resp_addr);
769 continue; 770 continue;
@@ -773,9 +774,9 @@ wait_for_reply(int sock, u_int t)
773 memcpy(&data, icp.icmp_data, sizeof(data)); 774 memcpy(&data, icp.icmp_data, sizeof(data));
774 if (debug > 2) 775 if (debug > 2)
775 printf("ICMP echo-reply of len %u, id %u, seq %u, cksum 0x%X\n", 776 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); 777 sizeof(data), ntohs(icp.icmp_id), ntohs(icp.icmp_seq), icp.icmp_cksum);
777 778
778 host = table[icp.icmp_seq/packets]; 779 host = table[ntohs(icp.icmp_seq)/packets];
779 gettimeofday(&now, &tz); 780 gettimeofday(&now, &tz);
780 tdiff = get_timevaldiff(&data.stime, &now); 781 tdiff = get_timevaldiff(&data.stime, &now);
781 782
@@ -845,13 +846,13 @@ send_icmp_ping(int sock, struct rta_host *host)
845 packet.icp->icmp_type = ICMP_ECHO; 846 packet.icp->icmp_type = ICMP_ECHO;
846 packet.icp->icmp_code = 0; 847 packet.icp->icmp_code = 0;
847 packet.icp->icmp_cksum = 0; 848 packet.icp->icmp_cksum = 0;
848 packet.icp->icmp_id = pid; 849 packet.icp->icmp_id = htons(pid);
849 packet.icp->icmp_seq = host->id++; 850 packet.icp->icmp_seq = htons(host->id++);
850 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size); 851 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size);
851 852
852 if (debug > 2) 853 if (debug > 2)
853 printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n", 854 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 sizeof(data), ntohs(packet.icp->icmp_id), ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum, host->name);
855 856
856 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr, 857 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr,
857 sizeof(struct sockaddr)); 858 sizeof(struct sockaddr));