aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ping903.h1
-rw-r--r--src/pinger.c34
2 files changed, 27 insertions, 8 deletions
diff --git a/src/ping903.h b/src/ping903.h
index ccf62b7..3e88c17 100644
--- a/src/ping903.h
+++ b/src/ping903.h
@@ -142,6 +142,7 @@ typedef struct hostping {
struct host_stat stat_last;
struct hostping *prev, *next;
+ int nreply[1];
} HOSTPING;
extern int verbose;
diff --git a/src/pinger.c b/src/pinger.c
index 2291a48..65e8e6a 100644
--- a/src/pinger.c
+++ b/src/pinger.c
@@ -114,10 +114,14 @@ hostping_free(HOSTPING *hp)
static HOSTPING *
hostping_create(char const *name, struct sockaddr *addr, socklen_t addrlen)
{
- HOSTPING *hp = malloc(sizeof(*hp));
+ HOSTPING *hp;
+ size_t hostsize = sizeof(*hp) +
+ (ping_count - 1) * sizeof(hp->nreply[0]);
+
+ hp = malloc(hostsize);
if (hp) {
- memset(hp, 0, sizeof(*hp));
+ memset(hp, 0, hostsize);
hp->tmin = HOSTPING_TMIN_INIT;
hp->name = strdup(name);
if (!hp)
@@ -306,6 +310,7 @@ hostping_reset(HOSTPING *host)
host->tmax = 0;
host->tsum = 0;
host->tsumsq = 0;
+ memset(host->nreply, 0, ping_count * sizeof(host->nreply[0]));
switch (host->stat_last.status) {
case HOST_STAT_INIT:
break;
@@ -942,7 +947,7 @@ enum {
struct seqidx {
HOSTPING *host;
struct timeval tv;
- int replied;
+ int ping_num;
};
static struct seqidx *seqidx;
@@ -958,7 +963,7 @@ seqno_alloc(HOSTPING *host, struct timeval *tv)
if (tv->tv_sec - seqidx[n].tv.tv_sec > MAX_PING_TIMEOUT) {
memcpy(&seqidx[n].tv, tv, sizeof(*tv));
seqidx[n].host = host;
- seqidx[n].replied = 0;
+ seqidx[n].ping_num = host->xmit_count;
next_seqno = (n + 1) % MOD_SEQNO;
return n;
}
@@ -976,13 +981,26 @@ hostping_from_seqno(int seq)
pthread_mutex_lock(&seqno_mutex);
host = seqidx[seq].host;
if (host) {
+ int n;
+
hostping_lock(host);
- if (seqidx[seq].replied) {
- host->dup_count++;
- info("%s:%d: DUP!", host->name, seq);
+ n = seqidx[seq].ping_num;
+ if (n >= 0 && n < ping_count) {
+ if (++host->nreply[n] > 1) {
+ host->dup_count++;
+ info("%s: duplicate reply for echo #%d, seqno %d",
+ host->name, n, seq);
+ host = NULL;
+ } else if (host->recv_count == host->xmit_count) {
+ error("%s: unexpected reply #%d, seqno %d",
+ host->name, n, seq);
+ host = NULL;
+ }
+ } else {
+ error("%s: duplicate reply for unregistered echo #%d, seqno %d",
+ host->name, n, seq);
host = NULL;
}
- seqidx[seq].replied++;
} else
fatal("no host found for sequence number %d", seq);
pthread_mutex_unlock(&seqno_mutex);

Return to:

Send suggestions and report system problems to the System administrator.