From 578ac00444a46b2159bace62c74e2b493ffdd9ed Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 17 Feb 2009 13:14:58 +0100 Subject: [PATCH] bindings/perl: Add support for the number of dropped packets. Signed-off-by: Florian Forster --- bindings/perl/Oping.xs | 24 ++++++++++++++++ bindings/perl/lib/Net/Oping.pm | 51 +++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/bindings/perl/Oping.xs b/bindings/perl/Oping.xs index 19da01c..c42374f 100644 --- a/bindings/perl/Oping.xs +++ b/bindings/perl/Oping.xs @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include /* NI_MAXHOST */ @@ -164,6 +166,28 @@ _ping_iterator_get_hostname (iter) free(buffer); } while (0); +int +_ping_iterator_get_dropped (iter) + pingobj_iter_t *iter + CODE: +#if defined(PING_INFO_DROPPED) + uint32_t tmp; + size_t tmp_size; + int status; + + RETVAL = -1; + + tmp_size = sizeof (tmp); + status = ping_iterator_get_info (iter, PING_INFO_DROPPED, + (void *) &tmp, &tmp_size); + if (status == 0) + RETVAL = (int) tmp; +#else + RETVAL = -1; +#endif + OUTPUT: + RETVAL + const char * _ping_get_error (obj) pingobj_t *obj diff --git a/bindings/perl/lib/Net/Oping.pm b/bindings/perl/lib/Net/Oping.pm index 838fb58..b14cc52 100644 --- a/bindings/perl/lib/Net/Oping.pm +++ b/bindings/perl/lib/Net/Oping.pm @@ -263,7 +263,56 @@ sub ping } return ($data); -} +} # ping + +=item my I<$dropped> = I<$obj>-EB () + +Returns a hash reference holding the number of "drops" (echo requests which +were not answered in time) for each host. An example return +values would be: + + $droprate = { host1 => 0, host2 => 3, host3 => undef, ... }; + +Hosts to which no data has been sent yet will return C ("host3" in thie +example). + +=cut + +sub get_dropped +{ + my $obj = shift; + my $iter; + my $data = {}; + + $iter = _ping_iterator_get ($obj->{'c_obj'}); + if (!$iter) + { + $obj->{'err_msg'} = "" . _ping_get_error ($obj->{'c_obj'}); + return; + } + + while ($iter) + { + my $host = _ping_iterator_get_hostname ($iter); + if (!$host) + { + $iter = _ping_iterator_next ($iter); + next; + } + + my $dropped = _ping_iterator_get_dropped ($iter); + if ($dropped < 0) + { + $dropped = undef; + } + + $data->{$host} = $dropped; + + $iter = _ping_iterator_next ($iter); + } + + return ($data); +} # get_dropped =item my I<$errmsg> = I<$obj>-EB (); -- 2.30.2