Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Missing functions in h2ph converted headers

Reply
Thread Tools

Missing functions in h2ph converted headers

 
 
Chris Snell
Guest
Posts: n/a
 
      10-24-2004
Hi,

I need to access the getifaddrs() function, as defined in ifaddrs.h on
FreeBSD/OpenBSD/Mac OS X. I'm trying to read the kernel's traffic
counters for the machine's network interfaces. I ran h2ph on
/usr/include/ifaddrs.h but it did not make the getifaddrs() function
available to me. How can I make this system call from Perl?

Also, getifaddrs provides its data in a struct which contains other
structs. It's a pretty gnarly data structure. Supposing that I can
access this from Perl's syscall, how can I quickly determine the total
size of the idaddrs struct that getifaddrs returns so that I can
allocate space in my scalar for this data?

thanks,

Chris

PS- If anyone knows of a better way to access network interface
statistics (but doesn't involve calling netstat(1)), I'd love to hear
about it.
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      10-24-2004

Quoth http://www.velocityreviews.com/forums/(E-Mail Removed) (Chris Snell):
>
> I need to access the getifaddrs() function, as defined in ifaddrs.h on
> FreeBSD/OpenBSD/Mac OS X. I'm trying to read the kernel's traffic
> counters for the machine's network interfaces.


It's possible you may be able to get the info you need with Net:cap: I
don't know what getifaddrs(2) does, so I can't tell.

> I ran h2ph on /usr/include/ifaddrs.h but it did not make the
> getifaddrs() function available to me. How can I make this system
> call from Perl?


Don't use h2ph or syscall: they're a perl4 mechanism. Instead, write (or
check CPAN to see if someone else has written) an XS module that calls
the C function and returns the values you need in a perlish form. If you
are not happy with learning XS, you could try Inline::C instead, which
hides most of the XS for you and lets you get away with only knowing
Perl and C.

> Also, getifaddrs provides its data in a struct which contains other
> structs. It's a pretty gnarly data structure. Supposing that I can
> access this from Perl's syscall, how can I quickly determine the total
> size of the idaddrs struct that getifaddrs returns so that I can
> allocate space in my scalar for this data?


Errr.... you can't.

Using XS or Inline::C, you can allocate a buffer with
NEWSV(1, sizeof(struct ifaddr)) (or whatever). To get at its members,
you use unpack: either unpack it yourself into a sensible Perl data
structure to return, or use Inline::Struct to wrap an object around it
(in which case you will probably need to copy the appropriate struct
defns from the header, and possibly provide typemaps for the members).

Good luck!

Ben

--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* (E-Mail Removed) *
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with wsgiref.headers.Headers Phil Python 4 01-17-2010 04:47 PM
Why header fields are converted to lower case when usingMailMessage.Headers.Add(...)? Afshar ASP .Net 0 10-08-2008 12:47 PM
Server cannot clear headers after HTTP headers have been sent Ian ASP .Net Security 2 03-20-2007 09:00 AM
Reading 'received' headers: Email Headers Parsing dont bother Python 0 03-03-2004 08:18 PM
Converted to Mozilla but one thing missing - key macro/substitution no-spam Firefox 5 07-29-2003 08:07 PM



Advertisments