summaryrefslogtreecommitdiffstats
path: root/perl-install/c/stuff.xs.pl
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/c/stuff.xs.pl')
-rw-r--r--perl-install/c/stuff.xs.pl61
1 files changed, 59 insertions, 2 deletions
diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl
index 26e6ce413..07249d66b 100644
--- a/perl-install/c/stuff.xs.pl
+++ b/perl-install/c/stuff.xs.pl
@@ -23,6 +23,8 @@ print '
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/mount.h>
+#undef __USE_MISC
+#include <linux/wireless.h>
#include <linux/keyboard.h>
#include <linux/kd.h>
#include <linux/hdreg.h>
@@ -398,13 +400,68 @@ 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);
OUTPUT:
RETVAL
+
+int
+isNetDeviceWirelessAware(device)
+ char * device
+ CODE:
+ struct iwreq ifr;
+
+ int s = socket(AF_INET, SOCK_DGRAM, 0);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, device, IFNAMSIZ);
+ RETVAL = ioctl(s, SIOCGIWNAME, &ifr) != -1;
+ close(s);
+ OUTPUT:
+ 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)
ALIAS:
@@ -415,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;