[liboping] Re: liboping Perl wrapper

Florian Forster octo<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>verplant.org
Sat Dec 16 12:31:20 CET 2006


On Fri, Dec 15, 2006 at 04:05:24PM +0100, Michele Bergonzoni wrote:
> construct, add_host and send work. tcpdump says that this program
> actually pings:

oh, good news :) I've had it that far, but didn't test with `tcpdump'

> Now I'm entangled with ping_iterator_get_info, which is not so
> entirely trivial.

I think the best bet is to change the Perl-interface somewhat. I think
the easiest way is to export the C-API to Perl and then write a wrapper
around it to give it a more Perly feeling.

The (Perl-)interface could behave somewhat like this:

-- 8< --
  use Net::Oping;

  # if %opts is not empty, `new' will call `set' with this hash
  my $obj = Net::Oping->new (%opts);
  $obj->add ("example.com") or die ($obj->error ());
  $obj->remove ("sample.org") or die ($obj->error ());

    timeout => 10,
    ttl => 100,
    af => AF_INET,
    data => 'foobar',
    source => ''

  # $iter if of type Net::Oping::Iterator
  my $iter;
  for ($iter = $obj->iterator (); $iter; $iter = $iter->next ())
    my $host  = $iter->hostname ();
    my $addr  = $iter->address ();
    my $addrf = $iter->address_family ();
    my $delay = $iter->delay ();
    my $seq   = $iter->sequence ();
    my $ident = $iter->ident ();

  # `destroy' is the same as `DESTROY'; *destroy = *DESTROY
  $obj->destroy ();
-- >8 --

The `prefix' of the XS-Functions could be changed from `ping_' to
`ping', so that these ``backend functions'' all start with an
underscore. This would make is easy to distinguish between `_destroy'
(the XS-function) and `destoy' (the Perl-method).

> As time permits, I'm starting to read "man perlguts" and "man perlxs"
> in order to have it return an hash or array of all the possible info
> that it can retrieve.

I guess it's easier to write wrappers around the `ping_setopt' and
`ping_iterator_get_info' functions, e.g.:
-- 8< --
  int _setopt_timeout (pingobj_t *obj, double t)
    return ping_setopt (obj, PING_OPT_TIMEOUT, (void *) &t);

  /* TODO: Can Perl handle dynamically allocated memory? */
  const char *_get_info_hostname (pingobj_iter_t *iter)
    static char buffer[NI_MAXHOST];
    ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
        buffer, NI_MAXHOST);
    return (buffer);
-- >8 --

I'll look into the C-wrappers. Do you have experience with `git'? I'd
push a branch to the repository so you can simply send in patches for
that branch..

Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/liboping/attachments/20061216/f79147da/attachment.pgp

More information about the liboping mailing list