Hello,

Attached is a patch that will enable the net module to run on FreeBSD (I hope). I am using it on 6.2-STABLE. I have no idea what other versions it will be compatible with.

I am hoping a few people (running 6.2 or otherwise) might step up and give it a whirl, and provide their feedback.

--
Regards,
Ravenlock
Index: e_modules/net/src/e_mod_config.c
===================================================================
RCS file: /var/cvs/e/e_modules/net/src/e_mod_config.c,v
retrieving revision 1.7
diff -u -r1.7 e_mod_config.c
--- e_modules/net/src/e_mod_config.c    21 Feb 2007 02:13:35 -0000      1.7
+++ e_modules/net/src/e_mod_config.c    23 Mar 2007 05:42:48 -0000
@@ -30,6 +30,7 @@
 _config_devices_get(void) 
 {
    Ecore_List *devs = NULL;
+#ifndef __FreeBSD__
    FILE *f;
    char buf[256];
    char dev[64];
@@ -55,6 +56,23 @@
        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;
 }
Index: e_modules/net/src/e_mod_net.c
===================================================================
RCS file: /var/cvs/e/e_modules/net/src/e_mod_net.c,v
retrieving revision 1.12
diff -u -r1.12 e_mod_net.c
--- e_modules/net/src/e_mod_net.c       15 Mar 2007 13:27:12 -0000      1.12
+++ e_modules/net/src/e_mod_net.c       23 Mar 2007 05:42:48 -0000
@@ -1,28 +1,63 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
 #include <e.h>
 #include "e_mod_main.h"
 #include "e_mod_net.h"
 #include "e_mod_config.h"
 #include "e_mod_configure.h"
+#ifdef __FreeBSD__
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+#include <net/if.h>
+#include <net/if_mib.h>
+#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 @@
      }
    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
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to