aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-03-03 16:48:13 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2020-03-03 16:48:13 +0200
commite80868b1650e14ae167a15e08ff9083e9e7462b3 (patch)
treed4b6788b5c6c5a212bea2a72db29635b87a7d273 /src
parent7532baa6300ab78c08d99647a49265402cb41c7e (diff)
downloadping903-e80868b1650e14ae167a15e08ff9083e9e7462b3.tar.gz
ping903-e80868b1650e14ae167a15e08ff9083e9e7462b3.tar.bz2
Bugfixes.
* pinger.c (icmp_generic_decode): Convert seq and id to hostorder prior to return. (send_echo): Keep hostping structure locked between sendto and update of the xmit_count. This fixes race condition: if a reply arrived in a time window between sendto and hostping_lock, the statistics would be committed prior to increasing xmit_count, producing inaccurate results (number of packets transmitted less that the number of packets received in the absense of duplicates).
Diffstat (limited to 'src')
-rw-r--r--src/pinger.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/pinger.c b/src/pinger.c
index 80d4dc0..4ab54f3 100644
--- a/src/pinger.c
+++ b/src/pinger.c
@@ -1085,10 +1085,11 @@ icmp_generic_decode(unsigned char * buffer, size_t bufsize,
cksum = icmp->icmp_cksum;
icmp->icmp_cksum = 0;
icmp->icmp_cksum = icmp_cksum((unsigned char *) icmp, bufsize - hlen);
- if (icmp->icmp_cksum != cksum)
- return 1;
icmp->icmp_seq = ntohs(icmp->icmp_seq);
icmp->icmp_id = ntohs(icmp->icmp_id);
+
+ if (icmp->icmp_cksum != cksum)
+ return 1;
return 0;
}
@@ -1123,21 +1124,21 @@ send_echo(HOSTPING *host, unsigned char *ping_buffer)
seqno);
icmp_generic_encode(ping_buffer, buflen, ICMP_ECHO, ping_ident, seqno);
+ hostping_lock(host);
n = sendto(ping_fd, (char *) ping_buffer, buflen, 0,
host->addr, host->addrlen);
if (n < 0) {
error("%s: sendto: %s", host->name, strerror(errno));
} else {
- hostping_lock(host);
if (host->xmit_count == 0)
host->start_tv = host->xmit_tv;
host->xmit_count++;
- hostping_unlock(host);
xmit_total++;
if (n != buflen)
error("ping: wrote %s %zu chars, ret=%ld\n",
host->name, buflen, n);
}
+ hostping_unlock(host);
}
static void hostping_commit(HOSTPING *host);

Return to:

Send suggestions and report system problems to the System administrator.