summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a8f7c2)
raw | patch | inline | side by side (parent: 7a8f7c2)
author | octo <octo> | |
Sun, 5 Feb 2006 21:46:20 +0000 (21:46 +0000) | ||
committer | octo <octo> | |
Sun, 5 Feb 2006 21:46:20 +0000 (21:46 +0000) |
src/liboping/liboping.c | patch | blob | history |
index bd733f192f5d74d18c127b7e0857f8dced1c0a8a..915de7bdcde357d2608caa55a46f3d5532ac0654 100644 (file)
--- a/src/liboping/liboping.c
+++ b/src/liboping/liboping.c
@@ -248,12 +248,11 @@ static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffe
return (ptr);
}
-static int ping_receive_one (int fd, pinghost_t *ph)
+static int ping_receive_one (int fd, pinghost_t *ph, struct timeval *now)
{
char buffer[4096];
size_t buffer_len;
- struct timeval now;
struct timeval diff;
pinghost_t *host = NULL;
return (-1);
}
- if (gettimeofday (&now, NULL) == -1)
- {
- dprintf ("gettimeofday: %s\n", strerror (errno));
- timerclear (host->timer);
- return (-1);
- }
-
+ dprintf ("rcvd: %12i.%06i\n",
+ (int) now->tv_sec,
+ (int) now->tv_usec);
dprintf ("sent: %12i.%06i\n",
(int) host->timer->tv_sec,
(int) host->timer->tv_usec);
- dprintf ("rcvd: %12i.%06i\n",
- (int) now.tv_sec,
- (int) now.tv_usec);
- if (ping_timeval_sub (&now, host->timer, &diff) < 0)
+ if (ping_timeval_sub (now, host->timer, &diff) < 0)
{
timerclear (host->timer);
return (-1);
ret = 0;
+ for (ptr = ph; ptr != NULL; ptr = ptr->next)
+ ptr->latency = -1.0;
+
if (gettimeofday (&endtime, NULL) == -1)
return (-1);
endtime.tv_sec += 1;
- for (ptr = ph; ptr != NULL; ptr = ptr->next)
- ptr->latency = -1.0;
-
while (1)
{
FD_ZERO (&readfds);
num_readfds = 0;
max_readfds = -1;
- if (gettimeofday (&nowtime, NULL) == -1)
- return (-1);
-
- if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
- return (0);
-
for (ptr = ph; ptr != NULL; ptr = ptr->next)
{
if (!timerisset (ptr->timer))
if (num_readfds == 0)
break;
+ if (gettimeofday (&nowtime, NULL) == -1)
+ return (-1);
+
+ if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
+ break;
+
dprintf ("Waiting on %i sockets for %i.%06i seconds\n", num_readfds,
(int) timeout.tv_sec,
(int) timeout.tv_usec);
status = select (max_readfds + 1, &readfds, NULL, NULL, &timeout);
+
+ if (gettimeofday (&nowtime, NULL) == -1)
+ return (-1);
if ((status == -1) && (errno == EINTR))
{
for (ptr = ph; ptr != NULL; ptr = ptr->next)
{
if (FD_ISSET (ptr->fd, &readfds))
- if (ping_receive_one (ptr->fd, ph) == 0)
+ if (ping_receive_one (ptr->fd, ph, &nowtime) == 0)
ret++;
}
- }
+ } /* while (1) */
return (ret);
}
* +-> ping_send_one_ipv4 *
* `-> ping_send_one_ipv6 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen)
+{
+ ssize_t ret;
+
+ if (gettimeofday (ph->timer, NULL) == -1)
+ {
+ timerclear (ph->timer);
+ return (-1);
+ }
+
+ ret = sendto (ph->fd, buf, buflen, 0,
+ (struct sockaddr *) ph->addr, ph->addrlen);
+
+ return (ret);
+}
+
static int ping_send_one_ipv4 (pinghost_t *ph)
{
struct icmphdr *icmp4;
dprintf ("Sending ICMPv4 package with ID 0x%04x\n", ph->ident);
- status = sendto (ph->fd, buf, buflen, 0,
- (struct sockaddr *) ph->addr, ph->addrlen);
+ status = ping_sendto (ph, buf, buflen);
if (status < 0)
{
- perror ("sendto");
+ perror ("ping_sendto");
return (-1);
}
dprintf ("Sending ICMPv6 package with ID 0x%04x\n", ph->ident);
- status = sendto (ph->fd, buf, buflen, 0,
- (struct sockaddr *) ph->addr, ph->addrlen);
+ status = ping_sendto (ph, buf, buflen);
if (status < 0)
{
- perror ("sendto");
+ perror ("ping_sendto");
return (-1);
}