"Fossies" - the Fresh Open Source Software Archive

Member "liboping-1.10.0/bindings/perl/Oping.xs" (11 May 2017, 4660 Bytes) of package /linux/privat/liboping-1.10.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "Oping.xs": 1.9.0_vs_1.10.0.

    1 /**
    2  * Net-Oping - Oping.xs
    3  * Copyright (C) 2007       Olivier Fredj
    4  * Copyright (C) 2008,2009  Florian octo Forster
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; only version 2 of the License is
    9  * applicable.
   10  *
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
   19  *
   20  * Authors:
   21  *   Olivier Fredj <ofredj at proxad.net>
   22  *   Florian octo Forster <ff at octo.it>
   23  */
   24 #include "EXTERN.h"
   25 #include "perl.h"
   26 #include "XSUB.h"
   27 
   28 #include <stdlib.h>
   29 #include <stdio.h>
   30 #include <string.h>
   31 #include <stdint.h>
   32 #include <inttypes.h>
   33 #include <errno.h>
   34 #include <assert.h>
   35 #include <netdb.h> /* NI_MAXHOST */
   36 #include <oping.h>
   37 
   38 MODULE = Net::Oping     PACKAGE = Net::Oping        
   39 
   40 PROTOTYPES: DISABLE
   41 
   42 pingobj_t *
   43 _ping_construct ()
   44     CODE:
   45         RETVAL = ping_construct ();
   46     OUTPUT:
   47         RETVAL
   48 
   49 void 
   50 _ping_destroy (obj);
   51     pingobj_t *obj
   52     CODE:
   53         ping_destroy(obj);
   54 
   55 int
   56 _ping_setopt_timeout (obj, timeout)
   57     pingobj_t *obj
   58     double timeout
   59     CODE:
   60         RETVAL = ping_setopt (obj, PING_OPT_TIMEOUT, &timeout);
   61     OUTPUT:
   62         RETVAL
   63 
   64 int
   65 _ping_setopt_ttl (obj, ttl)
   66     pingobj_t *obj
   67     int ttl
   68     CODE:
   69         RETVAL = ping_setopt (obj, PING_OPT_TTL, &ttl);
   70     OUTPUT:
   71         RETVAL
   72 
   73 int
   74 _ping_setopt_source (obj, addr)
   75     pingobj_t *obj
   76     char *addr
   77     CODE:
   78         RETVAL = ping_setopt (obj, PING_OPT_SOURCE, addr);
   79     OUTPUT:
   80         RETVAL
   81 
   82 int
   83 _ping_setopt_device (obj, dev)
   84     pingobj_t *obj
   85     char *dev
   86     CODE:
   87 #if OPING_VERSION >= 1003000
   88         RETVAL = ping_setopt (obj, PING_OPT_DEVICE, dev);
   89 #else
   90         RETVAL = -95;
   91 #endif
   92     OUTPUT:
   93         RETVAL
   94 
   95 int 
   96 _ping_host_add (obj, host);
   97     pingobj_t *obj
   98     const char *host
   99     CODE:
  100         RETVAL = ping_host_add (obj, host);
  101     OUTPUT:
  102         RETVAL
  103 
  104 int 
  105 _ping_host_remove (obj, host)
  106     pingobj_t *obj
  107     const char *host
  108     CODE:
  109         RETVAL = ping_host_remove (obj, host);
  110     OUTPUT:
  111         RETVAL
  112 
  113 int 
  114 _ping_send (obj)
  115     pingobj_t *obj
  116     CODE:
  117         RETVAL=ping_send (obj);
  118     OUTPUT:
  119         RETVAL
  120 
  121 pingobj_iter_t *
  122 _ping_iterator_get (obj)
  123     pingobj_t *obj
  124     CODE:
  125         RETVAL = ping_iterator_get (obj);
  126     OUTPUT:
  127         RETVAL
  128 
  129 pingobj_iter_t *
  130 _ping_iterator_next (iter)
  131     pingobj_iter_t *iter
  132     CODE:
  133         RETVAL = ping_iterator_next (iter);
  134     OUTPUT:
  135         RETVAL
  136 
  137 int
  138 _ping_iterator_count (obj)
  139     pingobj_t *obj
  140     CODE:
  141         RETVAL = ping_iterator_count (obj);
  142     OUTPUT:
  143         RETVAL
  144 
  145 double
  146 _ping_iterator_get_latency (iter)
  147     pingobj_iter_t *iter
  148     CODE:
  149         double tmp;
  150         size_t tmp_size;
  151         int status;
  152 
  153         RETVAL = -1.0;
  154 
  155         tmp_size = sizeof (tmp);
  156         status = ping_iterator_get_info (iter, PING_INFO_LATENCY,
  157             (void *) &tmp, &tmp_size);
  158         if (status == 0)
  159             RETVAL = tmp;
  160     OUTPUT:
  161         RETVAL
  162 
  163 void
  164 _ping_iterator_get_hostname (iter)
  165     pingobj_iter_t *iter
  166     PPCODE:
  167         char *buffer;
  168         size_t buffer_size;
  169         int status;
  170 
  171     do {
  172         buffer = NULL;
  173         buffer_size = 0;
  174         status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
  175                 (void *) buffer, &buffer_size);
  176         if (status != ENOMEM)
  177             break;
  178 #if !defined(OPING_VERSION) || (OPING_VERSION <= 3005)
  179         /* This is a workaround for a bug in 0.3.5. */
  180         buffer_size++;
  181 #endif
  182 
  183         buffer = (char *) malloc (buffer_size);
  184         if (buffer == NULL)
  185             break;
  186 
  187         status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
  188                 (void *) buffer, &buffer_size);
  189         if (status != 0)
  190         {
  191             free (buffer);
  192             break;
  193         }
  194         buffer[buffer_size - 1] = 0;
  195 
  196         XPUSHs (sv_2mortal (newSVpvn(buffer, strlen (buffer))));
  197         free(buffer);
  198     } while (0);
  199 
  200 int
  201 _ping_iterator_get_dropped (iter)
  202     pingobj_iter_t *iter
  203     CODE:
  204 #if defined(PING_INFO_DROPPED)
  205         uint32_t tmp;
  206         size_t tmp_size;
  207         int status;
  208 
  209         RETVAL = -1;
  210 
  211         tmp_size = sizeof (tmp);
  212         status = ping_iterator_get_info (iter, PING_INFO_DROPPED,
  213             (void *) &tmp, &tmp_size);
  214         if (status == 0)
  215             RETVAL = (int) tmp;
  216 #else
  217         RETVAL = -1;
  218 #endif
  219     OUTPUT:
  220         RETVAL
  221 
  222 int
  223 _ping_iterator_get_recv_ttl (iter)
  224     pingobj_iter_t *iter
  225     CODE:
  226 #if defined(PING_INFO_RECV_TTL)
  227         int tmp;
  228         size_t tmp_size;
  229         int status;
  230 
  231         RETVAL = -1;
  232 
  233         tmp_size = sizeof (tmp);
  234         status = ping_iterator_get_info (iter, PING_INFO_RECV_TTL,
  235             (void *) &tmp, &tmp_size);
  236         if (status == 0)
  237             RETVAL = tmp;
  238 #else
  239         RETVAL = -1;
  240 #endif
  241     OUTPUT:
  242         RETVAL
  243 
  244 const char *
  245 _ping_get_error (obj)
  246     pingobj_t *obj
  247     CODE:
  248         RETVAL = ping_get_error(obj);
  249     OUTPUT:
  250         RETVAL