Code

ping plugin: Updated the ping plugin to work with liboping 0.2.2.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 9 Jul 2006 10:16:02 +0000 (12:16 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 9 Jul 2006 10:16:02 +0000 (12:16 +0200)
src/ping.c

index 91e0dbcc01072fd7601695349f08684adcd53523..8e2c50b43b73880fff4bae121135bb4489e8681a 100644 (file)
@@ -29,7 +29,7 @@
 #define MODULE_NAME "ping"
 
 #include <netinet/in.h>
-#include "liboping/liboping.h"
+#include "liboping/oping.h"
 
 static pingobj_t *pingobj = NULL;
 
@@ -123,8 +123,9 @@ static void ping_read (void)
 {
        pingobj_iter_t *iter;
 
-       char   *host;
-       double  latency;
+       char   host[512];
+       double latency;
+       size_t buf_len;
 
        if (pingobj == NULL)
                return;
@@ -136,21 +137,22 @@ static void ping_read (void)
                return;
        }
 
-       for (iter = ping_iterator_get (pingobj); iter != NULL; iter = ping_iterator_next (iter))
+       for (iter = ping_iterator_get (pingobj);
+                       iter != NULL;
+                       iter = ping_iterator_next (iter))
        {
-               const char *tmp;
-
-               if ((tmp = ping_iterator_get_host (iter)) == NULL)
-                       continue;
-               if ((host = strdup (tmp)) == NULL)
+               buf_len = sizeof (host);
+               if (ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
+                                       host, &buf_len))
                        continue;
 
-               latency = ping_iterator_get_latency (iter);
+               buf_len = sizeof (latency);
+               if (ping_iterator_get_info (iter, PING_INFO_LATENCY,
+                                       &latency, &buf_len))
+                       continue;
 
                DBG ("host = %s, latency = %f", host, latency);
                ping_submit (host, latency);
-
-               free (host); host = NULL;
        }
 }