Quoth
(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)
*
*