From 69b39c9a3c9bd5107b5147f68c30fa7c96606178 Mon Sep 17 00:00:00 2001 From: Christopher Michael Date: Mon, 26 Mar 2007 01:25:10 +0000 Subject: [PATCH] Ravenlock's Bsd patch for allowing net module to work on *Bsd SVN revision: 29165 --- src/e_mod_config.c | 18 ++++++++++++ src/e_mod_net.c | 68 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/e_mod_config.c b/src/e_mod_config.c index 0c85ec2..da59317 100644 --- a/src/e_mod_config.c +++ b/src/e_mod_config.c @@ -30,6 +30,7 @@ EAPI Ecore_List * _config_devices_get(void) { Ecore_List *devs = NULL; +#ifndef __FreeBSD__ FILE *f; char buf[256]; char dev[64]; @@ -55,6 +56,23 @@ _config_devices_get(void) ecore_list_append(devs, strdup(dev)); } fclose(f); +#else + DIR *d = NULL; + struct dirent *dentry = NULL; + + d = opendir("/dev/net"); + if (!d) return NULL; + + devs = ecore_list_new(); + ecore_list_set_free_cb(devs, free); + while ((dentry = readdir(d)) != NULL) + { + if (strstr(dentry->d_name,".") == NULL) + ecore_list_append(devs, strdup(dentry->d_name)); + } + closedir(d); +#endif + if (devs) ecore_list_goto_first(devs); return devs; } diff --git a/src/e_mod_net.c b/src/e_mod_net.c index c8e0a2c..ad0c407 100644 --- a/src/e_mod_net.c +++ b/src/e_mod_net.c @@ -1,28 +1,63 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ #include #include "e_mod_main.h" #include "e_mod_net.h" #include "e_mod_config.h" #include "e_mod_configure.h" +#ifdef __FreeBSD__ +#include +#include +#include +#include +#endif typedef unsigned long bytes_t; static void _bytes_to_string(bytes_t bytes, char *string, int size); static void _cb_post(void *data, E_Menu *m); static void _cb_configure(void *data, E_Menu *m, E_Menu_Item *mi); +#ifdef __FreeBSD__ +static int get_ifmib_general(int row, struct ifmibdata *ifmd); + +static int +get_ifmib_general(int row, struct ifmibdata *ifmd) +{ + int name[6]; + size_t len; + + name[0] = CTL_NET; + name[1] = PF_LINK; + name[2] = NETLINK_GENERIC; + name[3] = IFMIB_IFDATA; + name[4] = row; + name[5] = IFDATA_GENERAL; + + len = sizeof(*ifmd); + + return sysctl(name, 6, ifmd, &len, (void *)0, 0); +} +#endif + EAPI int _cb_poll(void *data) { Instance *inst; Config_Item *ci; - FILE *f; - char buf[256], popbuf[256], dev[64], tmp[100]; - int found = 0; + char buf[256], popbuf[256], tmp[100]; long bin, bout; - bytes_t in, out, dummy = 0; - + bytes_t in, out = 0; + inst = data; ci = _config_item_get(inst->gcc->id); - + +#ifndef __FreeBSD__ + FILE *f; + char dev[64]; + bytes_t dummy = 0; + int found = 0; + f = fopen("/proc/net/dev", "r"); if (!f) return 1; @@ -44,14 +79,33 @@ _cb_poll(void *data) } fclose(f); if (!found) return 1; +#else + struct ifmibdata *ifmd; + int i, count, len; + len = sizeof(count); + sysctlbyname("net.link.generic.system.ifcount", &count, &len, (void *)0, 0); + + ifmd = malloc(sizeof(struct ifmibdata)); + for(i=1; i <= count; ++i) + { + get_ifmib_general(i, ifmd); + if (!strcmp(ifmd->ifmd_name, ci->device)) break; + } + + in = ifmd->ifmd_data.ifi_ibytes; + out = ifmd->ifmd_data.ifi_obytes; + + free(ifmd); +#endif + bin = in - inst->in; bout = out - inst->out; bin = bin / 0.5; bout = bout / 0.5; inst->in = in; inst->out = out; - + if (bin <= ci->limit) edje_object_signal_emit(inst->o_net, "e,state,receive,idle", "e"); else