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

svn at pcbsd.org svn at pcbsd.org
Mon Jun 9 07:48:43 PDT 2008


Author: tim
Date: 2008-06-09 07:48:43 -0700 (Mon, 09 Jun 2008)
New Revision: 2061

Modified:
   pcbsd/trunk/libpcbsd/netif.cpp
   pcbsd/trunk/libpcbsd/netif.h
Log:
Added method to retrieve media status of interface

Modified: pcbsd/trunk/libpcbsd/netif.cpp
===================================================================
--- pcbsd/trunk/libpcbsd/netif.cpp	2008-06-09 13:51:43 UTC (rev 2060)
+++ pcbsd/trunk/libpcbsd/netif.cpp	2008-06-09 14:48:43 UTC (rev 2061)
@@ -29,6 +29,7 @@
 
 #include <net/if.h>
 #include <net/if_dl.h>
+#include <net/if_media.h>
 
 #include <ifaddrs.h>
 #include <netinet/in.h>
@@ -117,3 +118,32 @@
    
    return mac;
 }
+
+QString NetworkInterface::mediaStatusAsString()
+{
+   struct ifmediareq ifm;
+   memset(&ifm, 0, sizeof(struct ifmediareq));
+
+   strncpy(ifm.ifm_name, name, IFNAMSIZ);
+   int s = socket(AF_INET, SOCK_DGRAM, 0);
+
+   ioctl(s, SIOCGIFMEDIA, &ifm);
+   QString status;
+
+   switch (IFM_TYPE(ifm.ifm_active))
+   {
+      case IFM_FDDI:
+      case IFM_TOKEN:
+         if (ifm.ifm_status & IFM_ACTIVE) status = "inserted";
+         else status = "no ring";
+         break;
+      case IFM_IEEE80211:
+         if (ifm.ifm_status & IFM_ACTIVE) status = "associated";
+         else status = "no carrier";
+         break;
+      default:
+         if (ifm.ifm_status & IFM_ACTIVE) status = "active";
+         else status = "no carrier";
+   }
+   return status;
+}

Modified: pcbsd/trunk/libpcbsd/netif.h
===================================================================
--- pcbsd/trunk/libpcbsd/netif.h	2008-06-09 13:51:43 UTC (rev 2060)
+++ pcbsd/trunk/libpcbsd/netif.h	2008-06-09 14:48:43 UTC (rev 2061)
@@ -37,6 +37,7 @@
    QString getDesc();
    QString macAsString();
    QString mediaTypeAsString();
+   QString mediaStatusAsString();
    bool isWireless();
    bool usesDHCP();
    bool isUp();



More information about the Commits mailing list