aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-02-19 17:43:41 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2020-02-19 17:43:41 +0200
commit5cb836e1646ee7d8b1f3ab7b36ca6dba6f29776a (patch)
treeb7a5ebc4ea7063da284fbb0387176f0e2b3fa072
parent998bea5d31b60f39c54f716063b44a5713fbc1c0 (diff)
downloadping903-5cb836e1646ee7d8b1f3ab7b36ca6dba6f29776a.tar.gz
ping903-5cb836e1646ee7d8b1f3ab7b36ca6dba6f29776a.tar.bz2
Bugfixes.
* src/pinger.c (xmit_total,recv_total): New variables. (PING_DATALEN): Fix calculation. (struct seqidx): New member "replied" (seqno_alloc): Initialize replied. (hostaddr_from_seqno): Warn about duplicate packets. (send_echo): Fix filling of icmp_data. (p903_sender): Fix timeout value. (p903_receiver): Initialize addrlen (p903_scheduler): Additional informative output.
-rw-r--r--src/pinger.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/pinger.c b/src/pinger.c
index 2aff036..956f091 100644
--- a/src/pinger.c
+++ b/src/pinger.c
@@ -51,9 +51,11 @@ static pthread_mutex_t sendq_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t sendq_cond = PTHREAD_COND_INITIALIZER;
static int send_p;
+static unsigned xmit_total;
+static unsigned recv_total;
+
#define ICMP_HEADER_LEN (offsetof(struct icmp, icmp_data))
-#define PING_HEADER_LEN (ICMP_HEADER_LEN+sizeof(struct timeval))
-#define PING_DATALEN (64 - PING_HEADER_LEN)
+#define PING_DATALEN (64 - ICMP_HEADER_LEN)
size_t data_length = PING_DATALEN;
static unsigned char *data_buffer;
@@ -69,6 +71,7 @@ enum {
struct seqidx {
HOSTADDR *host;
struct timeval tv;
+ int replied;
};
static struct seqidx *seqidx;
@@ -82,6 +85,7 @@ seqno_alloc(HOSTADDR *addr, 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 = addr;
+ seqidx[n].replied = 0;
next_seqno = (n + 1) % MOD_SEQNO;
return n;
}
@@ -95,7 +99,9 @@ static HOSTADDR *
hostaddr_from_seqno(int seq)
{
HOSTADDR *host = seqidx[seq].host;
- memset(&seqidx[seq], 0, sizeof(seqidx[seq]));
+ if (seqidx[seq].replied)
+ info("%s:%d: DUP!", host->name, seq);
+ seqidx[seq].replied++;
return host;
}
@@ -218,10 +224,8 @@ send_echo(HOSTADDR *host, unsigned char *ping_buffer)
gettimeofday(&host->xmit_tv, NULL);
memcpy(icmp->icmp_data, &host->xmit_tv, sizeof(host->xmit_tv));
if (data_buffer)
- memcpy(icmp->icmp_data + PING_HEADER_LEN, data_buffer,
- data_length > PING_HEADER_LEN
- ? data_length - PING_HEADER_LEN
- : data_length);
+ memcpy(icmp->icmp_data + sizeof(host->xmit_tv), data_buffer,
+ data_length - sizeof(host->xmit_tv));
buflen = ICMP_HEADER_LEN + data_length;
@@ -241,6 +245,7 @@ send_echo(HOSTADDR *host, unsigned char *ping_buffer)
if (host->xmit_count == 0)
host->start_tv = host->xmit_tv;
host->xmit_count++;
+ xmit_total++;
if (n != buflen)
error("ping: wrote %s %d chars, ret=%d\n",
host->name, buflen, n);
@@ -280,7 +285,7 @@ p903_sender(void *p)
send_count = 0;
}
for (i = 0; i < hostaddr_count; i++) {
- n = poll(&pfd, 1, 0);
+ n = poll(&pfd, 1, -1);
if (n == 1) {
send_echo(&hostaddr[i], ping_buffer);
} else if (n == -1) {
@@ -643,7 +648,7 @@ p903_receiver(void *p)
while (1) {
struct sockaddr_storage addr;
- socklen_t addrlen;
+ socklen_t addrlen = sizeof(addr);
ssize_t n;
int rc;
struct icmp *icmp;
@@ -656,6 +661,7 @@ p903_receiver(void *p)
error("recvfrom: %s", strerror(errno));
continue;
}
+
rc = icmp_generic_decode(ping_buffer, n, &ip, &icmp);
if (rc < 0) {
char hbuf[NI_MAXHOST];
@@ -675,6 +681,8 @@ p903_receiver(void *p)
|| icmp->icmp_id != ping_ident)
continue;
+ recv_total++;
+
if (rc) {
char hbuf[NI_MAXHOST];
if (getnameinfo((struct sockaddr *) &addr,
@@ -693,7 +701,7 @@ p903_receiver(void *p)
struct timeval tv_orig, tv_diff, *tp;
double rtt;
- gettimeofday (&host->recv_tv, NULL);
+ gettimeofday(&host->recv_tv, NULL);
tp = (struct timeval *) icmp->icmp_data;
@@ -715,21 +723,25 @@ p903_receiver(void *p)
log_echo((struct sockaddr *)&addr, addrlen, icmp, ip, n, rtt);
if (host->recv_count == ping_count)
host_stat_commit(host);
- }
+ } else
+ fatal("no host found for sequence number %d",
+ icmp->icmp_seq);
}
}
-#define UPDATE_MAX 5
-
void *
p903_scheduler(void *p)
{
while (1) {
size_t i;
+
/* Reset all statistics */
for (i = 0; i < hostaddr_count; i++)
host_reset(hostaddr + i);
start_probe();
sleep(probe_interval);
+ info("total sent=%u, received=%u",
+ xmit_total, recv_total);
+ xmit_total = recv_total = 0;
}
}

Return to:

Send suggestions and report system problems to the System administrator.