1 /**
2 * Object oriented C module to send ICMP and ICMPv6 `echo's.
3 * Copyright (C) 2006 Florian octo Forster <octo at verplant.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <errno.h>
24 #include <string.h>
26 #include <assert.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
32 #include <sys/socket.h>
33 #include <netdb.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/in.h>
37 #include <netinet/ip.h>
38 #include <netinet/ip_icmp.h>
39 #ifdef HAVE_NETINET_IP_VAR_H
40 # include <netinet/ip_var.h>
41 #endif
43 #include <netinet/ip6.h>
44 #include <netinet/icmp6.h>
46 #include <sys/time.h>
47 #include <time.h>
49 #include "liboping.h"
51 #if DEBUG
52 # define dprintf(...) printf ("%s[%4i]: %-20s: ", __FILE__, __LINE__, __FUNCTION__); printf (__VA_ARGS__)
53 #else
54 # define dprintf(...) /**/
55 #endif
57 #define PING_DATA "Florian Forster <octo@verplant.org> http://verplant.org/"
59 /*
60 * private (static) functions
61 */
62 static int ping_timeval_sub (struct timeval *tv1, struct timeval *tv2,
63 struct timeval *res)
64 {
66 if ((tv1->tv_sec < tv2->tv_sec)
67 || ((tv1->tv_sec == tv2->tv_sec)
68 && (tv1->tv_usec < tv2->tv_usec)))
69 return (-1);
71 res->tv_sec = tv1->tv_sec - tv2->tv_sec;
72 res->tv_usec = tv1->tv_usec - tv2->tv_usec;
74 assert ((res->tv_sec > 0) || ((res->tv_sec == 0) && (res->tv_usec > 0)));
76 while (res->tv_usec < 0)
77 {
78 res->tv_usec += 1000000;
79 res->tv_sec--;
80 }
82 return (0);
83 }
85 static uint16_t ping_icmp4_checksum (char *buf, size_t len)
86 {
87 uint32_t sum = 0;
88 uint16_t ret = 0;
90 uint16_t *ptr;
92 for (ptr = (uint16_t *) buf; len > 1; ptr++, len -= 2)
93 sum += *ptr;
95 if (len == 1)
96 {
97 *(char *) &ret = *(char *) ptr;
98 sum += ret;
99 }
101 /* Do this twice to get all possible carries.. */
102 sum = (sum >> 16) + (sum & 0xFFFF);
103 sum = (sum >> 16) + (sum & 0xFFFF);
105 ret = ~sum;
107 return (ret);
108 }
110 static pinghost_t *ping_receive_ipv4 (pinghost_t *ph, char *buffer, size_t buffer_len)
111 {
112 struct ip *ip_hdr;
113 struct icmp *icmp_hdr;
115 size_t ip_hdr_len;
117 uint16_t recv_checksum;
118 uint16_t calc_checksum;
120 uint16_t ident;
121 uint16_t seq;
123 pinghost_t *ptr;
125 if (buffer_len < sizeof (struct ip))
126 return (NULL);
128 ip_hdr = (struct ip *) buffer;
129 ip_hdr_len = ip_hdr->ip_hl << 2;
131 if (buffer_len < ip_hdr_len)
132 return (NULL);
134 buffer += ip_hdr_len;
135 buffer_len -= ip_hdr_len;
137 if (buffer_len < sizeof (struct icmp))
138 return (NULL);
140 icmp_hdr = (struct icmp *) buffer;
141 buffer += sizeof (struct icmp);
142 buffer_len -= sizeof (struct icmp);
144 if (icmp_hdr->icmp_type != ICMP_ECHOREPLY)
145 {
146 dprintf ("Unexpected ICMP type: %i\n", icmp_hdr->icmp_type);
147 return (NULL);
148 }
150 recv_checksum = icmp_hdr->icmp_cksum;
151 icmp_hdr->icmp_cksum = 0;
152 calc_checksum = ping_icmp4_checksum ((char *) icmp_hdr,
153 sizeof (struct icmp) + buffer_len);
155 if (recv_checksum != calc_checksum)
156 {
157 dprintf ("Checksum missmatch: Got 0x%04x, calculated 0x%04x\n",
158 recv_checksum, calc_checksum);
159 return (NULL);
160 }
162 ident = ntohs (icmp_hdr->icmp_id);
163 seq = ntohs (icmp_hdr->icmp_seq);
165 for (ptr = ph; ptr != NULL; ptr = ptr->next)
166 {
167 dprintf ("hostname = %s, ident = 0x%04x, seq = %i\n",
168 ptr->hostname, ptr->ident, ptr->sequence - 1);
170 if (ptr->addrfamily != AF_INET)
171 continue;
173 if (!timerisset (ptr->timer))
174 continue;
176 if (ptr->ident != ident)
177 continue;
179 if ((ptr->sequence - 1) != seq)
180 continue;
182 dprintf ("Match found: hostname = %s, ident = 0x%04x, seq = %i\n",
183 ptr->hostname, ident, seq);
185 break;
186 }
188 if (ptr == NULL)
189 {
190 dprintf ("No match found for ident = 0x%04x, seq = %i\n",
191 ident, seq);
192 }
194 return (ptr);
195 }
197 static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffer_len)
198 {
199 struct icmp6_hdr *icmp_hdr;
201 uint16_t ident;
202 uint16_t seq;
204 pinghost_t *ptr;
206 if (buffer_len < sizeof (struct icmp6_hdr))
207 return (NULL);
209 icmp_hdr = (struct icmp6_hdr *) buffer;
210 buffer += sizeof (struct icmp);
211 buffer_len -= sizeof (struct icmp);
213 if (icmp_hdr->icmp6_type != ICMP6_ECHO_REPLY)
214 {
215 dprintf ("Unexpected ICMP type: %02x\n", icmp_hdr->icmp6_type);
216 return (NULL);
217 }
219 if (icmp_hdr->icmp6_code != 0)
220 {
221 dprintf ("Unexpected ICMP code: %02x\n", icmp_hdr->icmp6_code);
222 return (NULL);
223 }
225 ident = ntohs (icmp_hdr->icmp6_id);
226 seq = ntohs (icmp_hdr->icmp6_seq);
228 for (ptr = ph; ptr != NULL; ptr = ptr->next)
229 {
230 dprintf ("hostname = %s, ident = 0x%04x, seq = %i\n",
231 ptr->hostname, ptr->ident, ptr->sequence - 1);
233 if (ptr->addrfamily != AF_INET6)
234 continue;
236 if (!timerisset (ptr->timer))
237 continue;
239 if (ptr->ident != ident)
240 continue;
242 if ((ptr->sequence - 1) != seq)
243 continue;
245 dprintf ("Match found: hostname = %s, ident = 0x%04x, seq = %i\n",
246 ptr->hostname, ident, seq);
248 break;
249 }
251 if (ptr == NULL)
252 {
253 dprintf ("No match found for ident = 0x%04x, seq = %i\n",
254 ident, seq);
255 }
257 return (ptr);
258 }
260 static int ping_receive_one (int fd, pinghost_t *ph, struct timeval *now)
261 {
262 char buffer[4096];
263 size_t buffer_len;
265 struct timeval diff;
267 pinghost_t *host = NULL;
269 struct sockaddr_storage sa;
270 socklen_t sa_len;
272 sa_len = sizeof (sa);
274 buffer_len = recvfrom (fd, buffer, sizeof (buffer), 0,
275 (struct sockaddr *) &sa, &sa_len);
276 if (buffer_len == -1)
277 {
278 dprintf ("recvfrom: %s\n", strerror (errno));
279 return (-1);
280 }
282 dprintf ("Read %i bytes from fd = %i\n", buffer_len, fd);
284 if (sa.ss_family == AF_INET)
285 {
286 if ((host = ping_receive_ipv4 (ph, buffer, buffer_len)) == NULL)
287 return (-1);
288 }
289 else if (sa.ss_family == AF_INET6)
290 {
291 if ((host = ping_receive_ipv6 (ph, buffer, buffer_len)) == NULL)
292 return (-1);
293 }
295 dprintf ("rcvd: %12i.%06i\n",
296 (int) now->tv_sec,
297 (int) now->tv_usec);
298 dprintf ("sent: %12i.%06i\n",
299 (int) host->timer->tv_sec,
300 (int) host->timer->tv_usec);
302 if (ping_timeval_sub (now, host->timer, &diff) < 0)
303 {
304 timerclear (host->timer);
305 return (-1);
306 }
308 dprintf ("diff: %12i.%06i\n",
309 (int) diff.tv_sec,
310 (int) diff.tv_usec);
312 host->latency = ((double) diff.tv_usec) / 1000.0;
313 host->latency += ((double) diff.tv_sec) * 1000.0;
315 timerclear (host->timer);
317 return (0);
318 }
320 static int ping_receive_all (pinghost_t *ph)
321 {
322 fd_set readfds;
323 int num_readfds;
324 int max_readfds;
326 pinghost_t *ptr;
328 struct timeval endtime;
329 struct timeval nowtime;
330 struct timeval timeout;
331 int status;
333 int ret;
335 ret = 0;
337 for (ptr = ph; ptr != NULL; ptr = ptr->next)
338 ptr->latency = -1.0;
340 if (gettimeofday (&endtime, NULL) == -1)
341 return (-1);
342 endtime.tv_sec += 1;
344 while (1)
345 {
346 FD_ZERO (&readfds);
347 num_readfds = 0;
348 max_readfds = -1;
350 for (ptr = ph; ptr != NULL; ptr = ptr->next)
351 {
352 if (!timerisset (ptr->timer))
353 continue;
355 FD_SET (ptr->fd, &readfds);
356 num_readfds++;
358 if (max_readfds < ptr->fd)
359 max_readfds = ptr->fd;
360 }
362 if (num_readfds == 0)
363 break;
365 if (gettimeofday (&nowtime, NULL) == -1)
366 return (-1);
368 if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
369 break;
371 dprintf ("Waiting on %i sockets for %i.%06i seconds\n", num_readfds,
372 (int) timeout.tv_sec,
373 (int) timeout.tv_usec);
375 status = select (max_readfds + 1, &readfds, NULL, NULL, &timeout);
377 if (gettimeofday (&nowtime, NULL) == -1)
378 return (-1);
380 if ((status == -1) && (errno == EINTR))
381 {
382 dprintf ("select was interrupted by signal..\n");
383 continue;
384 }
385 else if (status < 0)
386 {
387 dprintf ("select: %s\n", strerror (errno));
388 break;
389 }
390 else if (status == 0)
391 {
392 dprintf ("select timed out\n");
393 break;
394 }
396 for (ptr = ph; ptr != NULL; ptr = ptr->next)
397 {
398 if (FD_ISSET (ptr->fd, &readfds))
399 if (ping_receive_one (ptr->fd, ph, &nowtime) == 0)
400 ret++;
401 }
402 } /* while (1) */
404 return (ret);
405 }
407 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
408 * Sending functions: *
409 * *
410 * ping_send_all *
411 * +-> ping_send_one_ipv4 *
412 * `-> ping_send_one_ipv6 *
413 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
414 ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen)
415 {
416 ssize_t ret;
418 if (gettimeofday (ph->timer, NULL) == -1)
419 {
420 timerclear (ph->timer);
421 return (-1);
422 }
424 ret = sendto (ph->fd, buf, buflen, 0,
425 (struct sockaddr *) ph->addr, ph->addrlen);
427 return (ret);
428 }
430 static int ping_send_one_ipv4 (pinghost_t *ph)
431 {
432 struct icmp *icmp4;
433 int status;
435 char buf[4096];
436 int buflen;
438 char *data;
439 int datalen;
441 dprintf ("ph->hostname = %s\n", ph->hostname);
443 memset (buf, '\0', sizeof (buf));
444 icmp4 = (struct icmp *) buf;
445 data = (char *) (icmp4 + 1);
447 icmp4->icmp_type = ICMP_ECHO;
448 icmp4->icmp_code = 0;
449 icmp4->icmp_cksum = 0;
450 icmp4->icmp_id = htons (ph->ident);
451 icmp4->icmp_seq = htons (ph->sequence);
453 strcpy (data, PING_DATA);
454 datalen = strlen (data);
456 buflen = datalen + sizeof (struct icmp);
458 icmp4->icmp_cksum = ping_icmp4_checksum (buf, buflen);
460 dprintf ("Sending ICMPv4 package with ID 0x%04x\n", ph->ident);
462 status = ping_sendto (ph, buf, buflen);
463 if (status < 0)
464 {
465 perror ("ping_sendto");
466 return (-1);
467 }
469 dprintf ("sendto: status = %i\n", status);
471 return (0);
472 }
474 static int ping_send_one_ipv6 (pinghost_t *ph)
475 {
476 struct icmp6_hdr *icmp6;
477 int status;
479 char buf[4096];
480 int buflen;
482 char *data;
483 int datalen;
485 dprintf ("ph->hostname = %s\n", ph->hostname);
487 memset (buf, '\0', sizeof (buf));
488 icmp6 = (struct icmp6_hdr *) buf;
489 data = (char *) (icmp6 + 1);
491 icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
492 icmp6->icmp6_code = 0;
493 /* The checksum will be calculated by the TCP/IP stack. */
494 icmp6->icmp6_cksum = 0;
495 icmp6->icmp6_id = htons (ph->ident);
496 icmp6->icmp6_seq = htons (ph->sequence);
498 strcpy (data, PING_DATA);
499 datalen = strlen (data);
501 buflen = datalen + sizeof (struct icmp6_hdr);
503 dprintf ("Sending ICMPv6 package with ID 0x%04x\n", ph->ident);
505 status = ping_sendto (ph, buf, buflen);
506 if (status < 0)
507 {
508 perror ("ping_sendto");
509 return (-1);
510 }
512 dprintf ("sendto: status = %i\n", status);
514 return (0);
515 }
517 static int ping_send_all (pinghost_t *ph)
518 {
519 pinghost_t *ptr;
521 for (ptr = ph; ptr != NULL; ptr = ptr->next)
522 {
523 /* start timer.. The GNU `ping6' starts the timer before
524 * sending the packet, so I will do that too */
525 if (gettimeofday (ptr->timer, NULL) == -1)
526 {
527 dprintf ("gettimeofday: %s\n", strerror (errno));
528 timerclear (ptr->timer);
529 continue;
530 }
531 else
532 {
533 dprintf ("timer set for hostname = %s\n", ptr->hostname);
534 }
536 if (ptr->addrfamily == AF_INET6)
537 {
538 dprintf ("Sending ICMPv6 echo request to `%s'\n", ptr->hostname);
539 if (ping_send_one_ipv6 (ptr) != 0)
540 {
541 timerclear (ptr->timer);
542 continue;
543 }
544 }
545 else if (ptr->addrfamily == AF_INET)
546 {
547 dprintf ("Sending ICMPv4 echo request to `%s'\n", ptr->hostname);
548 if (ping_send_one_ipv4 (ptr) != 0)
549 {
550 timerclear (ptr->timer);
551 continue;
552 }
553 }
554 else /* this should not happen */
555 {
556 dprintf ("Unknown address family: %i\n", ptr->addrfamily);
557 timerclear (ptr->timer);
558 continue;
559 }
561 ptr->sequence++;
562 }
564 /* FIXME */
565 return (0);
566 }
568 static int ping_get_ident (void)
569 {
570 int fd;
571 static int did_seed = 0;
573 int retval;
575 if (did_seed == 0)
576 {
577 if ((fd = open ("/dev/urandom", O_RDONLY)) != -1)
578 {
579 unsigned int seed;
581 if (read (fd, &seed, sizeof (seed)) != -1)
582 {
583 did_seed = 1;
584 dprintf ("Random seed: %i\n", seed);
585 srandom (seed);
586 }
588 close (fd);
589 }
590 else
591 {
592 dprintf ("open (/dev/urandom): %s\n", strerror (errno));
593 }
594 }
596 retval = (int) random ();
598 dprintf ("Random number: %i\n", retval);
600 return (retval);
601 }
603 static pinghost_t *ping_alloc (void)
604 {
605 pinghost_t *ph;
606 size_t ph_size;
608 ph_size = sizeof (pinghost_t)
609 + sizeof (struct sockaddr_storage)
610 + sizeof (struct timeval);
612 ph = (pinghost_t *) malloc (ph_size);
613 if (ph == NULL)
614 return (NULL);
616 memset (ph, '\0', ph_size);
618 ph->timer = (struct timeval *) (ph + 1);
619 ph->addr = (struct sockaddr_storage *) (ph->timer + 1);
621 ph->addrlen = sizeof (struct sockaddr_storage);
622 ph->latency = -1.0;
623 ph->ident = ping_get_ident () & 0xFFFF;
625 return (ph);
626 }
628 static void ping_free (pinghost_t *ph)
629 {
630 if (ph->hostname != NULL)
631 free (ph->hostname);
633 free (ph);
634 }
636 /*
637 * public methods
638 */
639 pingobj_t *ping_construct (void)
640 {
641 pingobj_t *obj;
643 if ((obj = (pingobj_t *) malloc (sizeof (pingobj_t))) == NULL)
644 return (NULL);
646 obj->head = NULL;
648 return (obj);
649 }
651 void ping_destroy (pingobj_t *obj)
652 {
653 pinghost_t *current;
654 pinghost_t *next;
656 current = obj->head;
657 next = NULL;
659 while (current != NULL)
660 {
661 next = current->next;
662 ping_free (current);
663 current = next;
664 }
666 free (obj);
668 return;
669 }
671 int ping_setopt (pingobj_t *obj, int option, void *value)
672 {
673 int ret = 0;
675 switch (option)
676 {
677 case PING_OPT_TIMEOUT:
678 obj->timeout = *((double *) value);
679 if (obj->timeout < 0.0)
680 {
681 obj->timeout = PING_DEF_TIMEOUT;
682 ret = -1;
683 }
684 break;
686 case PING_OPT_TTL:
687 obj->ttl = *((int *) value);
688 if ((obj->ttl < 1) || (obj->ttl > 255))
689 {
690 obj->ttl = PING_DEF_TTL;
691 ret = -1;
692 }
693 break;
695 case PING_OPT_AF:
696 obj->addrfamily = *((int *) value);
697 if ((obj->addrfamily != AF_UNSPEC)
698 && (obj->addrfamily != AF_INET)
699 && (obj->addrfamily != AF_INET6))
700 {
701 obj->addrfamily = PING_DEF_AF;
702 ret = -1;
703 }
704 break;
706 default:
707 ret = -2;
708 } /* switch (option) */
710 return (ret);
711 } /* int ping_setopt */
714 int ping_send (pingobj_t *obj)
715 {
716 int ret;
718 if (ping_send_all (obj->head) < 0)
719 return (-1);
721 if ((ret = ping_receive_all (obj->head)) < 0)
722 return (-2);
724 return (ret);
725 }
727 static pinghost_t *ping_host_search (pinghost_t *ph, const char *host)
728 {
729 while (ph != NULL)
730 {
731 if (strcasecmp (ph->hostname, host) == 0)
732 break;
734 ph = ph->next;
735 }
737 return (ph);
738 }
740 int ping_host_add (pingobj_t *obj, const char *host)
741 {
742 pinghost_t *ph;
744 struct sockaddr_storage sockaddr;
745 socklen_t sockaddr_len;
747 struct addrinfo ai_hints;
748 struct addrinfo *ai_list, *ai_ptr;
749 int ai_return;
751 dprintf ("host = %s\n", host);
753 if (ping_host_search (obj->head, host) != NULL)
754 return (0);
756 memset (&ai_hints, '\0', sizeof (ai_hints));
757 ai_hints.ai_flags = 0;
758 #ifdef AI_ADDRCONFIG
759 ai_hints.ai_flags |= AI_ADDRCONFIG;
760 #endif
761 ai_hints.ai_family = PF_UNSPEC;
762 ai_hints.ai_socktype = SOCK_RAW;
764 if ((ph = ping_alloc ()) == NULL)
765 {
766 dprintf ("Out of memory!\n");
767 return (-1);
768 }
770 if ((ph->hostname = strdup (host)) == NULL)
771 {
772 dprintf ("Out of memory!\n");
773 ping_free (ph);
774 return (-1);
775 }
777 if ((ai_return = getaddrinfo (host, NULL, &ai_hints, &ai_list)) != 0)
778 {
779 dprintf ("getaddrinfo failed\n");
780 ping_free (ph);
781 return (-1);
782 }
784 for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
785 {
786 ph->fd = -1;
788 sockaddr_len = sizeof (sockaddr);
789 memset (&sockaddr, '\0', sockaddr_len);
791 if (ai_ptr->ai_family == AF_INET)
792 {
793 struct sockaddr_in *si;
795 si = (struct sockaddr_in *) &sockaddr;
796 si->sin_family = AF_INET;
797 si->sin_port = htons (ph->ident);
798 si->sin_addr.s_addr = htonl (INADDR_ANY);
800 ai_ptr->ai_protocol = IPPROTO_ICMP;
801 }
802 else if (ai_ptr->ai_family == AF_INET6)
803 {
804 struct sockaddr_in6 *si;
806 si = (struct sockaddr_in6 *) &sockaddr;
807 si->sin6_family = AF_INET6;
808 si->sin6_port = htons (ph->ident);
809 si->sin6_addr = in6addr_any;
811 ai_ptr->ai_protocol = IPPROTO_ICMPV6;
812 }
813 else
814 {
815 dprintf ("Unknown `ai_family': %i\n", ai_ptr->ai_family);
816 continue;
817 }
819 ph->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
820 if (ph->fd == -1)
821 {
822 dprintf ("socket: %s\n", strerror (errno));
823 continue;
824 }
826 if (bind (ph->fd, (struct sockaddr *) &sockaddr, sockaddr_len) == -1)
827 {
828 dprintf ("bind: %s\n", strerror (errno));
829 close (ph->fd);
830 ph->fd = -1;
831 continue;
832 }
834 assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen);
835 memset (ph->addr, '\0', sizeof (struct sockaddr_storage));
836 memcpy (ph->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
837 ph->addrlen = ai_ptr->ai_addrlen;
838 ph->addrfamily = ai_ptr->ai_family;
840 break;
841 }
843 freeaddrinfo (ai_list);
845 if (ph->fd < 0)
846 {
847 free (ph->hostname);
848 free (ph);
849 return (-1);
850 }
852 ph->next = obj->head;
853 obj->head = ph;
855 return (0);
856 }
858 int ping_host_remove (pingobj_t *obj, const char *host)
859 {
860 pinghost_t *pre, *cur;
862 pre = NULL;
863 cur = obj->head;
865 while (cur != NULL)
866 {
867 if (strcasecmp (host, cur->hostname))
868 break;
870 pre = cur;
871 cur = cur->next;
872 }
874 if (cur == NULL)
875 return (-1);
877 if (pre == NULL)
878 obj->head = cur->next;
879 else
880 pre->next = cur->next;
882 if (cur->fd >= 0)
883 close (cur->fd);
885 ping_free (cur);
887 return (0);
888 }
890 pingobj_iter_t *ping_iterator_get (pingobj_t *obj)
891 {
892 return ((pingobj_iter_t *) obj->head);
893 }
895 pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter)
896 {
897 return ((pingobj_iter_t *) iter->next);
898 }
900 const char *ping_iterator_get_host (pingobj_iter_t *iter)
901 {
902 return (iter->hostname);
903 }
905 double ping_iterator_get_latency (pingobj_iter_t *iter)
906 {
907 return (iter->latency);
908 }