[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2257] nagiosplug/trunk/plugins-root/check_icmp.c
dermoth at users.sourceforge.net
dermoth at users.sourceforge.net
Fri Oct 16 04:15:16 CEST 2009
Revision: 2257
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2257&view=rev
Author: dermoth
Date: 2009-10-16 02:15:16 +0000 (Fri, 16 Oct 2009)
Log Message:
-----------
Set proper network byte order for icmp_id and icmp_seq in icmp packets
From: Thomas Guyot-Sionnest <dermoth at aei.ca>
Modified Paths:
--------------
nagiosplug/trunk/plugins-root/check_icmp.c
Modified: nagiosplug/trunk/plugins-root/check_icmp.c
===================================================================
--- nagiosplug/trunk/plugins-root/check_icmp.c 2009-10-16 02:15:12 UTC (rev 2256)
+++ nagiosplug/trunk/plugins-root/check_icmp.c 2009-10-16 02:15:16 UTC (rev 2257)
@@ -306,7 +306,7 @@
struct rta_host *host = NULL;
memcpy(&p, packet, sizeof(p));
- if(p.icmp_type == ICMP_ECHO && p.icmp_id == pid) {
+ if(p.icmp_type == ICMP_ECHO && ntohs(p.icmp_id) == pid) {
/* echo request from us to us (pinging localhost) */
return 0;
}
@@ -332,15 +332,15 @@
/* might be for us. At least it holds the original package (according
* 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*packets)
+ if(sent_icmp.icmp_type != ICMP_ECHO || ntohs(sent_icmp.icmp_id) != pid ||
+ ntohs(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/packets];
+ host = table[ntohs(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),
@@ -763,7 +763,8 @@
/* check the response */
memcpy(&icp, buf + hlen, sizeof(icp));
- if(icp.icmp_id != pid || icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets*packets) {
+ if(ntohs(icp.icmp_id) != pid || icp.icmp_type != ICMP_ECHOREPLY ||
+ ntohs(icp.icmp_seq) >= targets*packets) {
if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n");
handle_random_icmp(buf + hlen, &resp_addr);
continue;
@@ -773,9 +774,9 @@
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);
+ sizeof(data), ntohs(icp.icmp_id), ntohs(icp.icmp_seq), icp.icmp_cksum);
- host = table[icp.icmp_seq/packets];
+ host = table[ntohs(icp.icmp_seq)/packets];
gettimeofday(&now, &tz);
tdiff = get_timevaldiff(&data.stime, &now);
@@ -845,13 +846,13 @@
packet.icp->icmp_type = ICMP_ECHO;
packet.icp->icmp_code = 0;
packet.icp->icmp_cksum = 0;
- packet.icp->icmp_id = pid;
- packet.icp->icmp_seq = host->id++;
+ packet.icp->icmp_id = htons(pid);
+ packet.icp->icmp_seq = htons(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);
+ sizeof(data), ntohs(packet.icp->icmp_id), ntohs(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));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list