1 #include <stdlib.h>
2 #include <stdio.h>
4 #include "liboping.h"
6 int main (int argc, char **argv)
7 {
8 pingobj_t *ping;
9 pingobj_iter_t *iter;
11 int i;
13 if (argc < 2)
14 {
15 printf ("Usage: %s <host> [host [host [...]]]\n", argv[0]);
16 return (1);
17 }
19 if ((ping = ping_construct ()) == NULL)
20 {
21 fprintf (stderr, "ping_construct failed\n");
22 return (-1);
23 }
25 for (i = 1; i < argc; i++)
26 {
27 printf ("Adding host `%s'..\n", argv[i]);
29 if (ping_host_add (ping, argv[i]) > 0)
30 {
31 fprintf (stderr, "ping_host_add (verplant.org) failed\n");
32 return (-1);
33 }
34 }
36 while (1)
37 {
38 if (ping_send (ping) < 0)
39 {
40 fprintf (stderr, "ping_send failed\n");
41 return (-1);
42 }
44 for (iter = ping_iterator_get (ping); iter != NULL; iter = ping_iterator_next (iter))
45 {
46 const char *host;
47 double latency;
49 host = ping_iterator_get_host (iter);
50 latency = ping_iterator_get_latency (iter);
52 printf ("host = %s, latency = %f\n", host, latency);
53 }
55 sleep (5);
56 }
58 return (0);
59 }