/* Even though Posix requires "strerror_r" to return an "int",
* some systems (e.g. the GNU libc) return a "char *" _and_
* ignore the second argument ... -tokkee */
-char *sstrerror (int errnum, char *buf, size_t buflen)
+static char *sstrerror (int errnum, char *buf, size_t buflen)
{
buf[0] = 0;
ident, seq);
}
+ if (ptr != NULL)
+ ptr->recv_ttl = ip_hdr->ip_ttl;
+
return (ptr);
}
{
struct timeval diff;
pinghost_t *host = NULL;
- int family;
int recv_ttl;
/*
dprintf ("Read %zi bytes from fd = %i\n", payload_buffer_len, fd);
/* Iterate over all auxiliary data in msghdr */
- family = -1;
recv_ttl = -1;
+ ph->recv_ttl = -1;
for (cmsg = CMSG_FIRSTHDR (&msghdr); /* {{{ */
cmsg != NULL;
cmsg = CMSG_NXTHDR (&msghdr, cmsg))
{
- if (cmsg->cmsg_level == IPPROTO_IP) /* {{{ */
+ if (ph->addrfamily == AF_INET) /* {{{ */
{
- family = AF_INET;
+ if (cmsg->cmsg_level != IPPROTO_IP)
+ continue;
+
if (cmsg->cmsg_type == IP_TTL)
{
memcpy (&recv_ttl, CMSG_DATA (cmsg),
cmsg->cmsg_type);
}
} /* }}} */
- else if (cmsg->cmsg_level == IPPROTO_IPV6) /* {{{ */
+ else if (ph->addrfamily == AF_INET6) /* {{{ */
{
- family = AF_INET6;
+ if (cmsg->cmsg_level != IPPROTO_IPV6)
+ continue;
+
if (cmsg->cmsg_type == IPV6_HOPLIMIT)
{
memcpy (&recv_ttl, CMSG_DATA (cmsg),
}
} /* }}} for (cmsg) */
- if (family == AF_INET)
+ if (ph->addrfamily == AF_INET)
{
host = ping_receive_ipv4 (ph, payload_buffer, payload_buffer_len);
if (host == NULL)
return (-1);
}
- else if (family == AF_INET6)
+ else if (ph->addrfamily == AF_INET6)
{
host = ping_receive_ipv6 (ph, payload_buffer, payload_buffer_len);
if (host == NULL)
else
{
dprintf ("ping_receive_one: Unknown address family %i.\n",
- family);
+ ph->addrfamily);
return (-1);
}
(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);
setsockopt (ph->fd, IPPROTO_IP, IP_RECVTTL,
&opt, sizeof (opt));
}
+#if defined(IPPROTO_IPV6) && defined(IPV6_RECVHOPLIMIT)
else if (ph->addrfamily == AF_INET6)
{
int opt = 1;
setsockopt (ph->fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
&opt, sizeof (opt));
}
+#endif
break;
}