Ravenlock's Bsd patch for allowing net module to work on *Bsd
SVN revision: 29165
This commit is contained in:
parent
bc67187f68
commit
69b39c9a3c
|
@ -30,6 +30,7 @@ EAPI Ecore_List *
|
||||||
_config_devices_get(void)
|
_config_devices_get(void)
|
||||||
{
|
{
|
||||||
Ecore_List *devs = NULL;
|
Ecore_List *devs = NULL;
|
||||||
|
#ifndef __FreeBSD__
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char dev[64];
|
char dev[64];
|
||||||
|
@ -55,6 +56,23 @@ _config_devices_get(void)
|
||||||
ecore_list_append(devs, strdup(dev));
|
ecore_list_append(devs, strdup(dev));
|
||||||
}
|
}
|
||||||
fclose(f);
|
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);
|
if (devs) ecore_list_goto_first(devs);
|
||||||
return devs;
|
return devs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,63 @@
|
||||||
|
/*
|
||||||
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||||
|
*/
|
||||||
#include <e.h>
|
#include <e.h>
|
||||||
#include "e_mod_main.h"
|
#include "e_mod_main.h"
|
||||||
#include "e_mod_net.h"
|
#include "e_mod_net.h"
|
||||||
#include "e_mod_config.h"
|
#include "e_mod_config.h"
|
||||||
#include "e_mod_configure.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;
|
typedef unsigned long bytes_t;
|
||||||
static void _bytes_to_string(bytes_t bytes, char *string, int size);
|
static void _bytes_to_string(bytes_t bytes, char *string, int size);
|
||||||
static void _cb_post(void *data, E_Menu *m);
|
static void _cb_post(void *data, E_Menu *m);
|
||||||
static void _cb_configure(void *data, E_Menu *m, E_Menu_Item *mi);
|
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
|
EAPI int
|
||||||
_cb_poll(void *data)
|
_cb_poll(void *data)
|
||||||
{
|
{
|
||||||
Instance *inst;
|
Instance *inst;
|
||||||
Config_Item *ci;
|
Config_Item *ci;
|
||||||
FILE *f;
|
char buf[256], popbuf[256], tmp[100];
|
||||||
char buf[256], popbuf[256], dev[64], tmp[100];
|
|
||||||
int found = 0;
|
|
||||||
long bin, bout;
|
long bin, bout;
|
||||||
bytes_t in, out, dummy = 0;
|
bytes_t in, out = 0;
|
||||||
|
|
||||||
inst = data;
|
inst = data;
|
||||||
ci = _config_item_get(inst->gcc->id);
|
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");
|
f = fopen("/proc/net/dev", "r");
|
||||||
if (!f) return 1;
|
if (!f) return 1;
|
||||||
|
|
||||||
|
@ -44,6 +79,25 @@ _cb_poll(void *data)
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (!found) return 1;
|
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;
|
bin = in - inst->in;
|
||||||
bout = out - inst->out;
|
bout = out - inst->out;
|
||||||
|
|
Loading…
Reference in New Issue