Code

ping_iterator_get_info: Provide the number of timed out packets.
authorFlorian Forster <octo@verplant.org>
Fri, 22 Aug 2008 07:00:24 +0000 (09:00 +0200)
committerFlorian Forster <octo@verplant.org>
Fri, 22 Aug 2008 07:00:24 +0000 (09:00 +0200)
src/liboping.c
src/mans/ping_iterator_get_info.pod
src/oping.h

index 22ab3a8672167b4d53248c4b92b9646ab82c05ee..c93633c8ea7c6cfba58336f394a4d4c9b1c7019e 100644 (file)
@@ -25,6 +25,8 @@
 # include <stdlib.h>
 # include <stdio.h>
 # include <string.h>
+# include <stdint.h>
+# include <inttypes.h>
 # include <errno.h>
 # include <assert.h>
 #else
@@ -109,6 +111,7 @@ struct pinghost
        int                      sequence;
        struct timeval          *timer;
        double                   latency;
+       uint32_t                 dropped;
        char                    *data;
 
        void                    *context;
@@ -523,6 +526,9 @@ static int ping_receive_all (pingobj_t *obj)
                else if (status == 0)
                {
                        dprintf ("select timed out\n");
+                       for (ptr = ph; ptr != NULL; ptr = ptr->next)
+                               if (ptr->latency < 0.0)
+                                       ptr->dropped++;
                        break;
                }
 
@@ -799,6 +805,7 @@ static pinghost_t *ping_alloc (void)
        ph->addrlen = sizeof (struct sockaddr_storage);
        ph->fd      = -1;
        ph->latency = -1.0;
+       ph->dropped = 0;
        ph->ident   = ping_get_ident () & 0xFFFF;
 
        return (ph);
@@ -1337,6 +1344,15 @@ int ping_iterator_get_info (pingobj_iter_t *iter, int info,
                        ret = 0;
                        break;
 
+               case PING_INFO_DROPPED:
+                       ret = ENOMEM;
+                       *buffer_len = sizeof (uint32_t);
+                       if (orig_buffer_len < sizeof (uint32_t))
+                               break;
+                       *((uint32_t *) buffer) = iter->dropped;
+                       ret = 0;
+                       break;
+
                case PING_INFO_SEQUENCE:
                        ret = ENOMEM;
                        *buffer_len = sizeof (unsigned int);
@@ -1366,7 +1382,7 @@ int ping_iterator_get_info (pingobj_iter_t *iter, int info,
        }
 
        return (ret);
-}
+} /* ping_iterator_get_info */
 
 void *ping_iterator_get_context (pingobj_iter_t *iter)
 {
index 57322bbfa525446621cc84afc275ca178228f2e5..55c9ec9cbcf286528cb696bc58c4c21ccb1b863f 100644 (file)
@@ -58,6 +58,13 @@ Return the last measured latency or less than zero if the timeout occured
 before a echo response was received. The buffer should be big enough to hold a
 double value.
 
+=item B<PING_INFO_DROPPED>
+
+Return the number of times that no response was received within the timeout.
+This value is only increased but may wrap around at the 32E<nbsp>bit boundary.
+The buffer should be big enough to hold a 32E<nbsp>bit integer, e.E<nbsp>g. an
+C<uint32_t>.
+
 =item B<PING_INFO_SEQUENCE>
 
 Return the last sequence number sent. This number is increased regardless of
index d450d6cbe212d8b1c790883bbd8a947b576f3d14..4655d3987c2a5636c4a7a5fa3db3911e777ae289 100644 (file)
@@ -41,6 +41,8 @@
 extern "C" {
 #endif
 
+#define OPING_VERSION 3005
+
 /*
  * Type definitions
  */
@@ -79,7 +81,6 @@ int ping_host_remove (pingobj_t *obj, const char *host);
 pingobj_iter_t *ping_iterator_get (pingobj_t *obj);
 pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter);
 
-#define PING_INFO_USERNAME 8
 #define PING_INFO_HOSTNAME 1
 #define PING_INFO_ADDRESS  2
 #define PING_INFO_FAMILY   3
@@ -87,6 +88,8 @@ pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter);
 #define PING_INFO_SEQUENCE 5
 #define PING_INFO_IDENT    6
 #define PING_INFO_DATA     7
+#define PING_INFO_USERNAME 8
+#define PING_INFO_DROPPED  9
 int ping_iterator_get_info (pingobj_iter_t *iter, int info,
                void *buffer, size_t *buffer_len);