Code

Moved text_liboping.c to src/oping.c
authorocto <octo>
Fri, 28 Apr 2006 21:28:37 +0000 (21:28 +0000)
committerocto <octo>
Fri, 28 Apr 2006 21:28:37 +0000 (21:28 +0000)
src/oping.c [new file with mode: 0644]

diff --git a/src/oping.c b/src/oping.c
new file mode 100644 (file)
index 0000000..cd7a781
--- /dev/null
@@ -0,0 +1,59 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "liboping.h"
+
+int main (int argc, char **argv)
+{
+       pingobj_t      *ping;
+       pingobj_iter_t *iter;
+
+       int i;
+
+       if (argc < 2)
+       {
+               printf ("Usage: %s <host> [host [host [...]]]\n", argv[0]);
+               return (1);
+       }
+
+       if ((ping = ping_construct ()) == NULL)
+       {
+               fprintf (stderr, "ping_construct failed\n");
+               return (-1);
+       }
+
+       for (i = 1; i < argc; i++)
+       {
+               printf ("Adding host `%s'..\n", argv[i]);
+
+               if (ping_host_add (ping, argv[i]) > 0)
+               {
+                       fprintf (stderr, "ping_host_add (verplant.org) failed\n");
+                       return (-1);
+               }
+       }
+
+       while (1)
+       {
+               if (ping_send (ping) < 0)
+               {
+                       fprintf (stderr, "ping_send failed\n");
+                       return (-1);
+               }
+
+               for (iter = ping_iterator_get (ping); iter != NULL; iter = ping_iterator_next (iter))
+               {
+                       const char *host;
+                       double      latency;
+
+                       host    = ping_iterator_get_host (iter);
+                       latency = ping_iterator_get_latency (iter);
+
+                       printf ("host = %s, latency = %f\n", host, latency);
+               }
+
+               sleep (5);
+       }
+
+       return (0);
+}