From: Vladimir V. Melnikov Date: Mon, 23 Mar 2009 08:30:26 +0000 (+0100) Subject: src/liboping.c: Be more fault-tolerant when checking for the TTL. X-Git-Tag: liboping-1.1.1~3 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=f5ff17460d82d64e4d4570f1c164ed7e4d21fd22;p=liboping.git src/liboping.c: Be more fault-tolerant when checking for the TTL. If it's not included in the auxiliary data, fall back to the value included in the IPv4 header which is provided via the raw socket. --- diff --git a/src/liboping.c b/src/liboping.c index f00e0b6..101c960 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -342,6 +342,8 @@ static pinghost_t *ping_receive_ipv4 (pinghost_t *ph, char *buffer, size_t buffe dprintf ("No match found for ident = 0x%04x, seq = %i\n", ident, seq); } + + ptr->recv_ttl = ip_hdr->ip_ttl; return (ptr); } @@ -475,7 +477,7 @@ static int ping_receive_one (int fd, pinghost_t *ph, struct timeval *now) dprintf ("Read %zi bytes from fd = %i\n", payload_buffer_len, fd); /* Iterate over all auxiliary data in msghdr */ - family = -1; + family = ph->addrfamily; recv_ttl = -1; for (cmsg = CMSG_FIRSTHDR (&msghdr); /* {{{ */ cmsg != NULL; @@ -555,11 +557,12 @@ static int ping_receive_one (int fd, pinghost_t *ph, struct timeval *now) (int) diff.tv_sec, (int) diff.tv_usec); + if (recv_ttl >= 0) + host->recv_ttl = recv_ttl; + host->latency = ((double) diff.tv_usec) / 1000.0; host->latency += ((double) diff.tv_sec) * 1000.0; - host->recv_ttl = recv_ttl; - timerclear (host->timer); return (0);