X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fperl%2FOping.xs;h=5d8fa40992cf07292eb83a8dfbaaacef75d21e2b;hb=e67d7327869b9e7e91cdf1971670d29c8bd22e64;hp=0cebf3d921ba6df3ba4470b3fc28a97d5dfb0ca2;hpb=e195217e2f501521019316d609df7fed4c62131d;p=liboping.git diff --git a/bindings/perl/Oping.xs b/bindings/perl/Oping.xs index 0cebf3d..5d8fa40 100644 --- a/bindings/perl/Oping.xs +++ b/bindings/perl/Oping.xs @@ -1,3 +1,26 @@ +/** + * Net-Oping - Oping.xs + * Copyright (C) 2007 Olivier Fredj + * Copyright (C) 2008,2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; only version 2 of the License is + * applicable. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Olivier Fredj + * Florian octo Forster + */ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" @@ -5,6 +28,8 @@ #include #include #include +#include +#include #include #include #include /* NI_MAXHOST */ @@ -37,6 +62,15 @@ _ping_setopt_timeout (obj, timeout) RETVAL int +_ping_setopt_ttl (obj, ttl) + pingobj_t *obj + int ttl + CODE: + RETVAL = ping_setopt (obj, PING_OPT_TTL, &ttl); + OUTPUT: + RETVAL + +int _ping_setopt_source (obj, addr) pingobj_t *obj char *addr @@ -45,6 +79,19 @@ _ping_setopt_source (obj, addr) OUTPUT: RETVAL +int +_ping_setopt_device (obj, dev) + pingobj_t *obj + char *dev + CODE: +#if OPING_VERSION >= 1003000 + RETVAL = ping_setopt (obj, PING_OPT_DEVICE, dev); +#else + RETVAL = -95; +#endif + OUTPUT: + RETVAL + int _ping_host_add (obj, host); pingobj_t *obj @@ -87,6 +134,14 @@ _ping_iterator_next (iter) OUTPUT: RETVAL +int +_ping_iterator_count (obj) + pingobj_t *obj + CODE: + RETVAL = ping_iterator_count (obj); + OUTPUT: + RETVAL + double _ping_iterator_get_latency (iter) pingobj_iter_t *iter @@ -105,16 +160,14 @@ _ping_iterator_get_latency (iter) OUTPUT: RETVAL -char * +void _ping_iterator_get_hostname (iter) pingobj_iter_t *iter - CODE: + PPCODE: char *buffer; size_t buffer_size; int status; - RETVAL = NULL; - do { buffer = NULL; buffer_size = 0; @@ -122,9 +175,10 @@ _ping_iterator_get_hostname (iter) (void *) buffer, &buffer_size); if (status != ENOMEM) break; - - /* FIXME: This is a workaround for a bug in 0.3.5. */ +#if !defined(OPING_VERSION) || (OPING_VERSION <= 3005) + /* This is a workaround for a bug in 0.3.5. */ buffer_size++; +#endif buffer = (char *) malloc (buffer_size); if (buffer == NULL) @@ -133,10 +187,57 @@ _ping_iterator_get_hostname (iter) status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME, (void *) buffer, &buffer_size); if (status != 0) + { + free (buffer); break; + } + buffer[buffer_size - 1] = 0; - RETVAL = buffer; + XPUSHs (sv_2mortal (newSVpvn(buffer, strlen (buffer)))); + 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 + +int +_ping_iterator_get_recv_ttl (iter) + pingobj_iter_t *iter + CODE: +#if defined(PING_INFO_RECV_TTL) + int tmp; + size_t tmp_size; + int status; + + RETVAL = -1; + + tmp_size = sizeof (tmp); + status = ping_iterator_get_info (iter, PING_INFO_RECV_TTL, + (void *) &tmp, &tmp_size); + if (status == 0) + RETVAL = tmp; +#else + RETVAL = -1; +#endif OUTPUT: RETVAL