From fcf597bc93e1aa48d0a3997d3501f32939acbb6e Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Wed, 26 May 2004 09:42:51 +0000 Subject: (netdevices) introduce it in order to list network interfaces --- perl-install/c/stuff.xs.pl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'perl-install/c') diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index dfa8732eb..2097f0efc 100644 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -441,6 +441,43 @@ isNetDeviceWirelessAware(device) RETVAL +void +get_netdevices() + PPCODE: + struct ifconf ifc; + struct ifreq *ifr; + int i; + int numreqs = 10; + + int s = socket(AF_INET, SOCK_DGRAM, 0); + + ifc.ifc_buf = NULL; + for (;;) { + ifc.ifc_len = sizeof(struct ifreq) * numreqs; + ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len); + + if (ioctl(s, SIOCGIFCONF, &ifc) < 0) { + perror("SIOCGIFCONF"); + return; + } + if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { + /* assume it overflowed and try again */ + numreqs += 10; + continue; + } + break; + } + if (ifc.ifc_len) { + ifr = ifc.ifc_req; + EXTEND(sp, ifc.ifc_len); + for (i=0; i < ifc.ifc_len; i+= sizeof(struct ifreq)) { + PUSHs(sv_2mortal(newSVpv(ifr->ifr_name, 0))); + ifr++; + } + } + + close(s); + char* getNetDriver(char* device) -- cgit v1.2.1