3 * Copyright (C) 2007 Olivier Fredj
4 * Copyright (C) 2008,2009 Florian octo Forster
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
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.
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
21 * Olivier Fredj <ofredj at proxad.net>
22 * Florian octo Forster <octo at verplant.org>
35 #include <netdb.h> /* NI_MAXHOST */
38 MODULE = Net::Oping PACKAGE = Net::Oping
45 RETVAL = ping_construct ();
56 _ping_setopt_timeout (obj, timeout)
60 RETVAL = ping_setopt (obj, PING_OPT_TIMEOUT, &timeout);
65 _ping_setopt_source (obj, addr)
69 RETVAL = ping_setopt (obj, PING_OPT_SOURCE, addr);
74 _ping_host_add (obj, host);
78 RETVAL = ping_host_add (obj, host);
83 _ping_host_remove (obj, host)
87 RETVAL = ping_host_remove (obj, host);
95 RETVAL=ping_send (obj);
100 _ping_iterator_get (obj)
103 RETVAL = ping_iterator_get (obj);
108 _ping_iterator_next (iter)
111 RETVAL = ping_iterator_next (iter);
116 _ping_iterator_get_latency (iter)
125 tmp_size = sizeof (tmp);
126 status = ping_iterator_get_info (iter, PING_INFO_LATENCY,
127 (void *) &tmp, &tmp_size);
134 _ping_iterator_get_hostname (iter)
144 status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
145 (void *) buffer, &buffer_size);
146 if (status != ENOMEM)
148 #if !defined(OPING_VERSION) || (OPING_VERSION <= 3005)
149 /* This is a workaround for a bug in 0.3.5. */
153 buffer = (char *) malloc (buffer_size);
157 status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
158 (void *) buffer, &buffer_size);
165 XPUSHs (sv_2mortal (newSVpvn(buffer,buffer_size)));
170 _ping_iterator_get_dropped (iter)
173 #if defined(PING_INFO_DROPPED)
180 tmp_size = sizeof (tmp);
181 status = ping_iterator_get_info (iter, PING_INFO_DROPPED,
182 (void *) &tmp, &tmp_size);
192 _ping_iterator_get_recv_ttl (iter)
195 #if defined(PING_INFO_RECV_TTL)
202 tmp_size = sizeof (tmp);
203 status = ping_iterator_get_info (iter, PING_INFO_RECV_TTL,
204 (void *) &tmp, &tmp_size);
214 _ping_get_error (obj)
217 RETVAL = ping_get_error(obj);