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_ttl (obj, ttl)
69 RETVAL = ping_setopt (obj, PING_OPT_TTL, &ttl);
74 _ping_setopt_source (obj, addr)
78 RETVAL = ping_setopt (obj, PING_OPT_SOURCE, addr);
83 _ping_setopt_device (obj, dev)
87 #if OPING_VERSION >= 1003000
88 RETVAL = ping_setopt (obj, PING_OPT_DEVICE, dev);
96 _ping_host_add (obj, host);
100 RETVAL = ping_host_add (obj, host);
105 _ping_host_remove (obj, host)
109 RETVAL = ping_host_remove (obj, host);
117 RETVAL=ping_send (obj);
122 _ping_iterator_get (obj)
125 RETVAL = ping_iterator_get (obj);
130 _ping_iterator_next (iter)
133 RETVAL = ping_iterator_next (iter);
138 _ping_iterator_get_latency (iter)
147 tmp_size = sizeof (tmp);
148 status = ping_iterator_get_info (iter, PING_INFO_LATENCY,
149 (void *) &tmp, &tmp_size);
156 _ping_iterator_get_hostname (iter)
166 status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
167 (void *) buffer, &buffer_size);
168 if (status != ENOMEM)
170 #if !defined(OPING_VERSION) || (OPING_VERSION <= 3005)
171 /* This is a workaround for a bug in 0.3.5. */
175 buffer = (char *) malloc (buffer_size);
179 status = ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
180 (void *) buffer, &buffer_size);
186 buffer[buffer_size - 1] = 0;
188 XPUSHs (sv_2mortal (newSVpvn(buffer, strlen (buffer))));
193 _ping_iterator_get_dropped (iter)
196 #if defined(PING_INFO_DROPPED)
203 tmp_size = sizeof (tmp);
204 status = ping_iterator_get_info (iter, PING_INFO_DROPPED,
205 (void *) &tmp, &tmp_size);
215 _ping_iterator_get_recv_ttl (iter)
218 #if defined(PING_INFO_RECV_TTL)
225 tmp_size = sizeof (tmp);
226 status = ping_iterator_get_info (iter, PING_INFO_RECV_TTL,
227 (void *) &tmp, &tmp_size);
237 _ping_get_error (obj)
240 RETVAL = ping_get_error(obj);