I'm running a linuxfromscratch distribution. I compiled and installed the wavelan plugin (0.5.11) but it was crashing every time I tried to add it to the panel. I've realised the problem was the use of popen("/sbin/ifconfig -a", "r") in the wavelan_query_interfaces function. By default, linuxfromscratch does not install ifconfig. I propose that the function reads from /proc/net/dev instead, to find the list of interfaces, like this. static GList* wavelan_query_interfaces (void) { GList *interfaces = NULL; gchar line[1024]; FILE *fp; gint m,n; TRACE ("Entered wavelan_query_interface"); fp = fopen ("/proc/net/dev", "r"); if (fp != NULL) { fgets (line, 1024, fp); //Ignore the first 2 lines fgets (line, 1024, fp); while (fgets (line, 1024, fp) != NULL) { for (m = 0; !isalnum(line[m]); ++m); for (n = m; isalnum (line[n]); ++n); line[n] = '\0'; interfaces = g_list_append (interfaces, g_strdup (&line[m])); } pclose (fp); } return interfaces; }
Thing is, ifconfig -a is used on all systems and is somewhat portable, while using /proc is linux-only. Boooo.
I didn't know that -- what do the BSDs use, Landry?
Given that this codepath in wavelan.c isnt within and #ifdef maze, i suppose *BSDs also use ifconfig -a, and we're lucky the output is vaguely similar to the one on linux, because afaict it correctly lists the interfaces for me on OpenBSD.
Maybe getifaddrs(3)? It's portable on most *nixes.
(In reply to Azamat H. Hackimov from comment #4) > Maybe getifaddrs(3)? It's portable on most *nixes. Hmmm.. if you provide a patch for this, i'll happily test it on OpenBSD :)
How about like this? It seems to work well in linux. Can you test in bsd? static GList* wavelan_query_interfaces (void) { GList *interfaces = NULL; struct ifaddrs *ifaddr, *ifa; TRACE ("Entered wavelan_query_interface"); if (getifaddrs(&ifaddr) == -1) { return interfaces; } for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) continue; if (ifa->ifa_addr->sa_family == AF_PACKET) interfaces = g_list_append (interfaces, g_strdup (ifa->ifa_name)); } freeifaddrs(ifaddr); return interfaces; }
t.c:16: error: 'AF_PACKET' undeclared (first use in this function) Seems AF_PACKET is linux only, and on bsd AF_LINK should be used instead. At least on OpenBSD here it works. http://stackoverflow.com/questions/9148425/freebsd-network-interface-information renton:/tmp/ $cat t.c #include <sys/types.h> #include <sys/socket.h> #include <ifaddrs.h> #include <stdio.h> int main() { struct ifaddrs *ifaddr, *ifa; if (getifaddrs(&ifaddr) == -1) { return 1; } for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) continue; if (ifa->ifa_addr->sa_family == AF_LINK) printf ("iface:%s\n",ifa->ifa_name); } return 0; } renton:/tmp/ $make t cc -O2 -pipe -o t t.c renton:/tmp/ $./t iface:lo0 iface:em0 iface:fxp0 iface:enc0 iface:pflog0
http://git.xfce.org/panel-plugins/xfce4-wavelan-plugin/commit/?id=9d36f449f2b6f363d24ccef78edf6c414809a140 - if anyone on linux could test git master and confirm the interfaces are properly listed...
I can confirm that the git master version worked fine for me on linuxfromscratch (v7.4). Cannot comment on other distributions.