[Xfce4-commits] [panel-plugins/xfce4-wavelan-plugin] 04/04: Use getifaddrs() instead of popen ("/sbin/ifconfig -a") (bug #10822)

noreply at xfce.org noreply at xfce.org
Sun Apr 20 10:45:57 CEST 2014


This is an automated email from the git hooks/post-receive script.

landry pushed a commit to branch master
in repository panel-plugins/xfce4-wavelan-plugin.

commit 9d36f449f2b6f363d24ccef78edf6c414809a140
Author: Landry Breuil <landry at xfce.org>
Date:   Sun Apr 20 10:45:13 2014 +0200

    Use getifaddrs() instead of popen ("/sbin/ifconfig -a") (bug #10822)
---
 panel-plugin/wavelan.c |   40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/panel-plugin/wavelan.c b/panel-plugin/wavelan.c
index 2b952df..dc73b38 100644
--- a/panel-plugin/wavelan.c
+++ b/panel-plugin/wavelan.c
@@ -38,6 +38,9 @@
 
 #include <string.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <ifaddrs.h>
 
 #ifdef LIBXFCE4PANEL_CHECK_VERSION
 #if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
@@ -216,29 +219,26 @@ static GList*
 wavelan_query_interfaces (void)
 {
   GList *interfaces = NULL;
-  gchar  line[1024];
-  FILE  *fp;
-  gint   n;
+  struct ifaddrs *ifaddr, *ifa;
 
   TRACE ("Entered wavelan_query_interface");
-  
-  fp = popen ("/sbin/ifconfig -a", "r");
-  if (fp != NULL)
-    {
-      while (fgets (line, 1024, fp) != NULL)
-        {
-          if (!isalpha (*line))
-            continue;
-
-          for (n = 0; isalnum (line[n]); ++n);
-          line[n] = '\0';
-
-          interfaces = g_list_append (interfaces, g_strdup (line));
-        }
-
-      pclose (fp);
-    }
 
+  if (getifaddrs(&ifaddr) == -1) {
+    return NULL;
+  }
+  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+    if (ifa->ifa_addr == NULL)
+      continue;
+#if defined(AF_LINK) /* BSD */
+    if (ifa->ifa_addr->sa_family == AF_LINK)
+#elif defined(AF_PACKET) /* linux */
+    if (ifa->ifa_addr->sa_family == AF_PACKET)
+#else
+#error "couldnt find a way to get address family on your system"
+#endif
+      interfaces = g_list_append (interfaces, g_strdup (ifa->ifa_name));
+  }
+  freeifaddrs(ifaddr);
   return interfaces;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list