index 43d5fd509eb0711e3c7c2d58c9354584b079db6d..46db24471be5dd8d84e93da91018d2b1033e47c1 100644 (file)
--- a/src/liboping/liboping.c
+++ b/src/liboping/liboping.c
/*
* private (static) functions
*/
-static int ping_timeval_add (struct timeval *tv1, struct timeval *tv2,
- struct timeval *res)
-{
- res->tv_sec = tv1->tv_sec + tv2->tv_sec;
- res->tv_usec = tv1->tv_usec + tv2->tv_usec;
-
- while (res->tv_usec > 1000000)
- {
- res->tv_usec -= 1000000;
- res->tv_sec++;
- }
-
- return (0);
-}
-
static int ping_timeval_sub (struct timeval *tv1, struct timeval *tv2,
struct timeval *res)
{
@@ -213,7 +198,7 @@ static pinghost_t *ping_receive_ipv4 (pinghost_t *ph, char *buffer, size_t buffe
for (ptr = ph; ptr != NULL; ptr = ptr->next)
{
dprintf ("hostname = %s, ident = 0x%04x, seq = %i\n",
- ptr->hostname, ptr->ident, ptr->sequence - 1);
+ ptr->hostname, ptr->ident, ((ptr->sequence - 1) & 0xFFFF));
if (ptr->addrfamily != AF_INET)
continue;
@@ -224,7 +209,7 @@ static pinghost_t *ping_receive_ipv4 (pinghost_t *ph, char *buffer, size_t buffe
if (ptr->ident != ident)
continue;
- if ((ptr->sequence - 1) != seq)
+ if (((ptr->sequence - 1) & 0xFFFF) != seq)
continue;
dprintf ("Match found: hostname = %s, ident = 0x%04x, seq = %i\n",
@@ -276,7 +261,7 @@ static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffe
for (ptr = ph; ptr != NULL; ptr = ptr->next)
{
dprintf ("hostname = %s, ident = 0x%04x, seq = %i\n",
- ptr->hostname, ptr->ident, ptr->sequence - 1);
+ ptr->hostname, ptr->ident, ((ptr->sequence - 1) & 0xFFFF));
if (ptr->addrfamily != AF_INET6)
continue;
@@ -287,7 +272,7 @@ static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffe
if (ptr->ident != ident)
continue;
- if ((ptr->sequence - 1) != seq)
+ if (((ptr->sequence - 1) & 0xFFFF) != seq)
continue;
dprintf ("Match found: hostname = %s, ident = 0x%04x, seq = %i\n",
return (0);
}
-static int ping_receive_all (pingobj_t *obj)
+static int ping_receive_all (pinghost_t *ph)
{
fd_set readfds;
int num_readfds;
int max_readfds;
- pinghost_t *ph;
pinghost_t *ptr;
struct timeval endtime;
int ret;
- ph = obj->head;
ret = 0;
for (ptr = ph; ptr != NULL; ptr = ptr->next)
ptr->latency = -1.0;
- if (gettimeofday (&nowtime, NULL) == -1)
+ if (gettimeofday (&endtime, NULL) == -1)
return (-1);
-
- /* Set up timeout */
- timeout.tv_sec = (time_t) obj->timeout;
- timeout.tv_usec = (suseconds_t) (1000000 * (obj->timeout - ((double) timeout.tv_sec)));
-
- dprintf ("Set timeout to %i.%06i seconds\n",
- (int) timeout.tv_sec,
- (int) timeout.tv_usec);
-
- ping_timeval_add (&nowtime, &timeout, &endtime);
+ endtime.tv_sec += 1;
while (1)
{
return (0);
}
-/*
- * Set the TTL of a socket protocol independently.
- */
-static int ping_set_ttl (pinghost_t *ph, int ttl)
-{
- int ret = -2;
-
- if (ph->addrfamily == AF_INET)
- {
- ret = setsockopt (ph->fd, IPPROTO_IP, IP_TTL, &ttl, sizeof (ttl));
- }
- else if (ph->addrfamily == AF_INET6)
- {
- ret = setsockopt (ph->fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof (ttl));
- }
-
- return (ret);
-}
-
static int ping_get_ident (void)
{
int fd;
if (ping_send_all (obj->head) < 0)
return (-1);
- if ((ret = ping_receive_all (obj)) < 0)
+ if ((ret = ping_receive_all (obj->head)) < 0)
return (-2);
return (ret);
#ifdef AI_ADDRCONFIG
ai_hints.ai_flags |= AI_ADDRCONFIG;
#endif
- ai_hints.ai_family = obj->addrfamily;
+ ai_hints.ai_family = PF_UNSPEC;
ai_hints.ai_socktype = SOCK_RAW;
if ((ph = ping_alloc ()) == NULL)
continue;
}
+#if 0
if (bind (ph->fd, (struct sockaddr *) &sockaddr, sockaddr_len) == -1)
{
dprintf ("bind: %s\n", strerror (errno));
ph->fd = -1;
continue;
}
+#endif
assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen);
memset (ph->addr, '\0', sizeof (struct sockaddr_storage));
ph->next = obj->head;
obj->head = ph;
- ping_set_ttl (ph, obj->ttl);
-
return (0);
}