From 7db099c14da7fde27be0cd6dbe0bf79183420a4f Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Fri, 28 May 2004 08:21:15 +0000 Subject: merge fixes from HEAD --- perl-install/c/stuff.xs.pl | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'perl-install/c') diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index d30aff57f..07249d66b 100644 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -400,7 +400,7 @@ hasNetDevice(device) int s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) { RETVAL = 0; return; } - strcpy(req.ifr_name, device); + strncpy(req.ifr_name, device, IFNAMSIZ); RETVAL = ioctl(s, SIOCGIFFLAGS, &req) == 0; close(s); @@ -424,6 +424,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) @@ -435,7 +472,7 @@ getNetDriver(char* device) int s = socket(AF_INET, SOCK_DGRAM, 0); memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)-1); + strncpy(ifr.ifr_name, device, IFNAMSIZ); drvinfo.cmd = ETHTOOL_GDRVINFO; ifr.ifr_data = (caddr_t) &drvinfo; -- cgit v1.2.1