[PC-BSD Commits] r2056 - pcbsd/trunk/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Mon Jun 9 03:59:07 PDT 2008


Author: tim
Date: 2008-06-09 03:59:06 -0700 (Mon, 09 Jun 2008)
New Revision: 2056

Modified:
   pcbsd/trunk/libpcbsd/netif.cpp
Log:
Add functionality to NetworkInterface

Modified: pcbsd/trunk/libpcbsd/netif.cpp
===================================================================
--- pcbsd/trunk/libpcbsd/netif.cpp	2008-06-08 21:16:18 UTC (rev 2055)
+++ pcbsd/trunk/libpcbsd/netif.cpp	2008-06-09 10:59:06 UTC (rev 2056)
@@ -24,8 +24,12 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
+
 #include <net/if.h>
 #include <ifaddrs.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include "netif.h"
 
@@ -51,3 +55,29 @@
 {
    name = devName;
 }
+
+QString NetworkInterface::ipAsString()
+{
+   struct ifreq ifr;
+
+   strncpy(ifr.ifr_name, name, IFNAMSIZ);
+   int s = socket(PF_INET, SOCK_DGRAM, 0);
+   
+   ioctl(s, SIOCGIFADDR, &ifr);
+   struct in_addr in = ((sockaddr_in *) &ifr.ifr_addr)->sin_addr;
+
+   return QString(inet_ntoa(in));
+}
+
+QString NetworkInterface::netmaskAsString()
+{
+   struct ifreq ifr;
+
+   strncpy(ifr.ifr_name, name, IFNAMSIZ);
+   int s = socket(PF_INET, SOCK_DGRAM, 0);
+   
+   ioctl(s, SIOCGIFNETMASK, &ifr);
+   struct in_addr in = ((sockaddr_in *) &ifr.ifr_addr)->sin_addr;
+
+   return QString(inet_ntoa(in));
+}



More information about the Commits mailing list