diff --git a/README.md b/README.md index 1328b11..0f64497 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 1. 样式调整 2. 删除鼠标悬浮信息中的流量统计 +3. 移除非linux的适配代码 ## 包管理器安装 diff --git a/panel-plugin/os.h b/panel-plugin/os.h index 2db420f..84b4e30 100644 --- a/panel-plugin/os.h +++ b/panel-plugin/os.h @@ -22,204 +22,23 @@ #ifndef _OS_H #define _OS_H -#if defined (__sun__) -# define __Solaris__ 1 -#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#ifdef __HPUX__ /* H P U X */ -# define _XOPEN_SOURCE_EXTENDED -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__APPLE__) /* Mac OS X */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__DragonFly__) /* D R A G O N F L Y */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) /* F R E E B S D */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__NetBSD__) /* N E T B S D */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__OpenBSD__) || defined (__MicroBSD__) /* O P E N B S D */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__linux__) /* L I N U X */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#elif defined (__Solaris__) /* S O L A R I S */ -# include -# define _WIDEC_H -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#else -# error "OS not supported" -#endif - -#endif diff --git a/panel-plugin/wormulon/freebsd.c b/panel-plugin/wormulon/freebsd.c deleted file mode 100644 index 2174ede..0000000 --- a/panel-plugin/wormulon/freebsd.c +++ /dev/null @@ -1,152 +0,0 @@ -/***************************************************************************** - * - * init_osspecific() - * - * Init function - * - ****************************************************************************/ - -void init_osspecific(netdata* data) -{ - data->watchif = -1; - -#ifdef DEBUG - fprintf( stderr, "The netload plugin was initialized for FreeBSD.\n" ); -#endif -} - - -/***************************************************************************** - * - * checkinterface() - * - * check if a given interface exists and is up. - * return TRUE if it does and FALSE if not - * - ****************************************************************************/ - -int checkinterface(netdata* data) -{ - int validinterface = FALSE; - - int i, num_iface; - size_t len; - int name[6]; - struct ifmibdata ifmd; - -#ifdef DEBUG - fprintf( stderr, "Checking the interface '%s' now ...\n", data->ifdata.if_name ); -#endif - - - len = sizeof(num_iface); - sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); - for (i=1; i <= num_iface; i++) - { - name[0] = CTL_NET; - name[1] = PF_LINK; - name[2] = NETLINK_GENERIC; - name[3] = IFMIB_IFDATA; - name[4] = i; - name[5] = IFDATA_GENERAL; - - len = sizeof(ifmd); - sysctl(name, 6, &ifmd, &len, NULL, 0); - if (strcmp(ifmd.ifmd_name, (char *)data->ifdata.if_name) == 0) - { - /* - * now we have an interface and just have to see if it's up - * in case we just want to debug media types we disable - * IFF_UP flags - */ -#ifndef MEDIADEBUG - if (ifmd.ifmd_flags & IFF_UP) -#endif - validinterface = TRUE; - break; /* in any case we can stop searching here */ - } - } - return validinterface; -} - -/****************************************************************************** - * - * get_stat() - * - * use sysctl() to read the statistics and fill statistics struct - * - ****************************************************************************/ - -int get_stat(netdata* data) -{ - /* - * use sysctl() to get the right interface number if !dev_opened - * then read the data directly from the ifmd_data struct - */ - - int i, num_iface; - size_t len; - int name[6]; - struct ifmibdata ifmd; - unsigned long rx_o, tx_o; - - if (!data->dev_opened) - { - len = sizeof(num_iface); - sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, - NULL, 0); - for (i=1; i <= num_iface; i++) - { - name[0] = CTL_NET; - name[1] = PF_LINK; - name[2] = NETLINK_GENERIC; - name[3] = IFMIB_IFDATA; - name[4] = i; - name[5] = IFDATA_GENERAL; - - len = sizeof(ifmd); - sysctl(name, 6, &ifmd, &len, NULL, 0); - if (strcmp(ifmd.ifmd_name, (char *)data->ifdata.if_name) == 0) - { - /* got the right interface */ -#ifdef DEBUG - fprintf( stderr, "Got the right interface.\n"); -#endif - data->watchif = i; - data->dev_opened++; - } - else - { -#ifdef DEBUG - fprintf( stderr, "Got NOT the right interface.\n"); -#endif - } - } - } - /* in any case read the struct and record statistics */ - name[0] = CTL_NET; - name[1] = PF_LINK; - name[2] = NETLINK_GENERIC; - name[3] = IFMIB_IFDATA; - name[4] = data->watchif; - name[5] = IFDATA_GENERAL; - - len = sizeof(ifmd); - sysctl(name, 6, &ifmd, &len, NULL, 0); - - rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; - - data->stats.tx_packets = ifmd.ifmd_data.ifi_opackets; - data->stats.rx_packets = ifmd.ifmd_data.ifi_ipackets; - data->stats.rx_bytes = ifmd.ifmd_data.ifi_ibytes; - data->stats.tx_bytes = ifmd.ifmd_data.ifi_obytes; - data->stats.rx_errors = ifmd.ifmd_data.ifi_ierrors; - data->stats.tx_errors = ifmd.ifmd_data.ifi_oerrors; - - if (rx_o > data->stats.rx_bytes) - data->stats.rx_over++; - if (tx_o > data->stats.tx_bytes) - data->stats.tx_over++; - - return (0); -} diff --git a/panel-plugin/wormulon/freebsd.h b/panel-plugin/wormulon/freebsd.h deleted file mode 100644 index 84822f9..0000000 --- a/panel-plugin/wormulon/freebsd.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef FREEBSD_H -#define FREEBSD_H - -#include "../net.h" - -void init_osspecific(netdata* data); -int checkinterface(netdata* data); -int get_stat(netdata* data); - -#endif diff --git a/panel-plugin/wormulon/hpux.c b/panel-plugin/wormulon/hpux.c deleted file mode 100644 index ebe5c4e..0000000 --- a/panel-plugin/wormulon/hpux.c +++ /dev/null @@ -1,197 +0,0 @@ -#include -#define WAIT_PCKS_COUNTER 15 - -/***************************************************************************** - * - * init_osspecific() - * - * Init function - * - ****************************************************************************/ - -void init_osspecific(netdata* data) -{ - wait_pcks_counter = WAIT_PCKS_COUNTER+1; - -#ifdef DEBUG - fprintf( stderr, "The netload plugin was initialized for HP_UX.\n" ); -#endif - -} - - - -/***************************************************************************** - * - * _countinterfaces() - * - * count all network interfaces in the system. This function is intended to - * use it only in hpux.c - * - ****************************************************************************/ - -int _countinterfaces(void) -{ - int val, num_iface=-1, sd; - if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return (-1); - - if (ioctl(sd, SIOCGIFNUM, &val) != -1) - num_iface = val; - close(sd); - - return num_iface; -} - -/***************************************************************************** - * - * _getifdata() - * - * get the Interface-ID, the Interface-Speed, and over all, check if the - * given interface really exists. This function is intended to use it only in - * hpux.c - * - ****************************************************************************/ - -void _getifdata() -{ - int buffer, fd, val, ret = -1; - unsigned int len, i; - char tmpinterfacestring[sizeof(data->ifdata.if_name)+1],*strstrmatch; - struct nmparms params; - mib_ifEntry * if_buf; - - - /* - * The interface description is more then the pure devicename. - * Let's do some formating to allow a propper pattern matching - */ - strcpy(tmpinterfacestring,data->ifdata.if_name); - strcat(tmpinterfacestring," "); - - for (i=0; i <= data->ifdata.if_amount; i++) - { - if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0) - { - if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) { - params.objid = ID_ifEntry; - params.buffer = if_buf; - len = sizeof(mib_ifEntry); - params.len = &len; - if_buf->ifIndex = i+1; - if ((ret = get_mib_info(fd, ¶ms)) == 0) { - /* - * The interface given by the user must start at the - * beginning of if_buf->ifDescr. If that's the case, - * strstrmatch is equal to if_buf->ifDescr. If not, - * strstrmatch might be a subset of if_buf->ifDescr, - * or NULL - */ - strstrmatch = strstr(if_buf->ifDescr, (char *)tmpinterfacestring); - if ( strstrmatch && (strcmp(strstrmatch,if_buf->ifDescr)== 0)) - { - data->ifdata.if_valid = 1; - data->ifdata.if_id = i+1; - break; - } - } - } - } - free(if_buf); - close_mib(fd); - } - return; -} - -/***************************************************************************** - * - * checkinterface() - * - * check if a given interface exists, return 1 if it does and 0 if not (This - * function is a wrapper function for _countinterfaces && _getifdata.) - * - ****************************************************************************/ -int checkinterface(netdata* data) -{ - /* == 0 no network interfaces, -1 sth. went wrong */ - if ((data->ifdata.if_amount =_countinterfaces()) > 0) - _getifdata(); - return data->ifdata.if_valid; -} - -/****************************************************************************** - * - * get_stat() - * - * stub function for all unsupported operating systems - * - *****************************************************************************/ - -int get_stat(netdata* data) -{ - int i,fd, ret=-1; - unsigned int len; - unsigned long rx_o, tx_o; - struct nmparms params, params2; - mib_ifEntry *if_buf; - - if (data->ifdata.if_valid == 1 && (fd = open_mib("/dev/lan", O_RDWR, 0, 0)) >= 0) - { - if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) - { - if_buf->ifIndex = data->ifdata.if_id; - params.objid = ID_ifEntry; - params.buffer = if_buf; - len = (unsigned int) sizeof(mib_ifEntry); - params.len = &len; - if ((ret = get_mib_info(fd, ¶ms)) == 0) - { - rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; - - data->stats.tx_bytes = if_buf->ifOutOctets; - data->stats.rx_bytes = if_buf->ifInOctets; - data->stats.tx_errors = if_buf->ifOutErrors; - data->stats.rx_errors = if_buf->ifInErrors; - - if (rx_o > data->stats.rx_bytes) - data->stats.rx_over++; - if (tx_o > data->stats.tx_bytes) - data->stats.tx_over++; - } - } - free(if_buf); - - /* - * Getting the tx/rx packets every run often hurts to much performance - * With WAIT_PCKS_COUNTER=15 i save on my system 43% cpu usage.instead of - * WAIT_PCKS_COUNTER=0 - */ - if( data->wait_pcks_counter > WAIT_PCKS_COUNTER ) - { - if ((if_ptr = (nmapi_logstat *) malloc(sizeof(nmapi_logstat) * data->ifdata.if_amount)) != 0 ) - { - len = (unsigned int) data->ifdata.if_amount *sizeof(nmapi_logstat); - if ((ret = get_logical_stat(if_ptr, &len)) == 0) - { - for (i=0; i <= data->ifdata.if_amount; i++) - { - if(if_ptr[i].ifindex == data->ifdata.if_id) - { - data->stats.tx_packets = if_ptr[i].out_packets; - data->stats.rx_packets = if_ptr[i].in_packets; - } - } - } - } - free(if_ptr); - data->wait_pcks_counter = 0; - } - else - { - data->wait_pcks_counter++; - } - } - close_mib(fd); - - return(0); -} diff --git a/panel-plugin/wormulon/hpux.h b/panel-plugin/wormulon/hpux.h deleted file mode 100644 index f10f403..0000000 --- a/panel-plugin/wormulon/hpux.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef HPUX_H -#define HPUX_H - -#include "../net.h" - -void init_osspecific(netdata* data); -int checkinterface(netdata* data); -int get_stat(netdata* data); - -#endif /* HPUX_H */ diff --git a/panel-plugin/wormulon/macos.c b/panel-plugin/wormulon/macos.c deleted file mode 100644 index 595d698..0000000 --- a/panel-plugin/wormulon/macos.c +++ /dev/null @@ -1,171 +0,0 @@ -/***************************************************************************** - * - * init_osspecific() - * - * Init function - * - ****************************************************************************/ - -void init_osspecific(netdata* data) -{ - data->mib_name1[0] = CTL_NET; - data->mib_name1[1] = PF_ROUTE; - data->mib_name1[2] = 0; - data->mib_name1[3] = 0; - data->mib_name1[4] = NET_RT_IFLIST; - data->mib_name1[5] = 0; - - data->mib_name2[0] = CTL_NET; - data->mib_name2[1] = PF_ROUTE; - data->mib_name2[2] = 0; - data->mib_name2[3] = 0; - data->mib_name2[4] = NET_RT_IFLIST; - data->mib_name2[5] = 0; - -#ifdef DEBUG - fprintf( stderr, "The netload plugin was initialized for NetBSD.\n" ); -#endif -} - - -/***************************************************************************** - * - * checkinterface() - * - * check if a given interface exists, return TRUE if it does and FALSE if not - * - ****************************************************************************/ -int checkinterface(netdata* data) -{ - int validinterface = FALSE; - char *lim, *next; - struct if_msghdr *ifm, *nextifm; - struct sockaddr_dl *sdl; - size_t needed; - char s[32]; - - if (sysctl(data->mib_name1, 6, NULL, &needed, NULL, 0) < 0) - return FALSE; - if (data->alloc1 < (signed long) needed) - { - if (data->buf1 != NULL) - free (data->buf1); - data->buf1 = malloc(needed); - if (data->buf1 == NULL) - return FALSE; - data->alloc1 = needed; - } - - if (sysctl(data->mib_name1, 6, data->buf1, &needed, NULL, 0) < 0) - return FALSE; - lim = data->buf1 + needed; - next = data->buf1; - while ((next < lim) && (validinterface == 0)) - { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type != RTM_IFINFO) - return FALSE; - next += ifm->ifm_msglen; - - while (next < lim) - { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - next += nextifm->ifm_msglen; - } - - if (ifm->ifm_flags & IFF_UP) - { - sdl = (struct sockaddr_dl *)(ifm + 1); - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; - /* search for the right network interface */ - if (sdl->sdl_family != AF_LINK) - continue; - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - else - { - validinterface = TRUE; - break; /* stop searching */ - } - } - } - return validinterface; -} -/****************************************************************************** - * - * get_stat() - * - * this code is based on gkrellm code (thanks guys!) - * - ****************************************************************************/ - -int get_stat(netdata* data) -{ - char *lim, *next; - struct if_msghdr *ifm, *nextifm; - struct sockaddr_dl *sdl; - char s[32]; - size_t needed; - unsigned long rx_o, tx_o; - - if (sysctl(data->mib_name2, 6, NULL, &needed, NULL, 0) < 0) - return 1; - if (data->alloc2 < (signed long) needed) - { - if (data->buf2 != NULL) - free (data->buf2); - data->buf2 = malloc(needed); - if (data->buf2 == NULL) - return 1; - data->alloc2 = needed; - } - - if (sysctl(data->mib_name2, 6, data->buf2, &needed, NULL, 0) < 0) - return 1; - lim = data->buf2 + needed; - next = data->buf2; - while (next < lim) - { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type != RTM_IFINFO) - return 1; - next += ifm->ifm_msglen; - - while (next < lim) - { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - next += nextifm->ifm_msglen; - } - - if (ifm->ifm_flags & IFF_UP) - { - sdl = (struct sockaddr_dl *)(ifm + 1); - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; - - /* search for the right network interface */ - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - - rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; - /* write stats */ - data->stats.tx_packets = ifm->ifm_data.ifi_opackets; - data->stats.rx_packets = ifm->ifm_data.ifi_ipackets; - data->stats.rx_bytes = ifm->ifm_data.ifi_ibytes; - data->stats.tx_bytes = ifm->ifm_data.ifi_obytes; - data->stats.rx_errors = ifm->ifm_data.ifi_ierrors; - data->stats.tx_errors = ifm->ifm_data.ifi_oerrors; - - if (rx_o > data->stats.rx_bytes) - data->stats.rx_over++; - if (tx_o > data->stats.tx_bytes) - data->stats.tx_over++; - } - } - return 0; -} diff --git a/panel-plugin/wormulon/macos.h b/panel-plugin/wormulon/macos.h deleted file mode 100644 index 8e8e323..0000000 --- a/panel-plugin/wormulon/macos.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MACOS_H -#define MACOS_H - -#include "../net.h" - -void init_osspecific(netdata* data); -int checkinterface(netdata* data); -int get_stat(netdata* data); - -#endif /* MACOS_H */ diff --git a/panel-plugin/wormulon/netbsd.c b/panel-plugin/wormulon/netbsd.c deleted file mode 100644 index 595d698..0000000 --- a/panel-plugin/wormulon/netbsd.c +++ /dev/null @@ -1,171 +0,0 @@ -/***************************************************************************** - * - * init_osspecific() - * - * Init function - * - ****************************************************************************/ - -void init_osspecific(netdata* data) -{ - data->mib_name1[0] = CTL_NET; - data->mib_name1[1] = PF_ROUTE; - data->mib_name1[2] = 0; - data->mib_name1[3] = 0; - data->mib_name1[4] = NET_RT_IFLIST; - data->mib_name1[5] = 0; - - data->mib_name2[0] = CTL_NET; - data->mib_name2[1] = PF_ROUTE; - data->mib_name2[2] = 0; - data->mib_name2[3] = 0; - data->mib_name2[4] = NET_RT_IFLIST; - data->mib_name2[5] = 0; - -#ifdef DEBUG - fprintf( stderr, "The netload plugin was initialized for NetBSD.\n" ); -#endif -} - - -/***************************************************************************** - * - * checkinterface() - * - * check if a given interface exists, return TRUE if it does and FALSE if not - * - ****************************************************************************/ -int checkinterface(netdata* data) -{ - int validinterface = FALSE; - char *lim, *next; - struct if_msghdr *ifm, *nextifm; - struct sockaddr_dl *sdl; - size_t needed; - char s[32]; - - if (sysctl(data->mib_name1, 6, NULL, &needed, NULL, 0) < 0) - return FALSE; - if (data->alloc1 < (signed long) needed) - { - if (data->buf1 != NULL) - free (data->buf1); - data->buf1 = malloc(needed); - if (data->buf1 == NULL) - return FALSE; - data->alloc1 = needed; - } - - if (sysctl(data->mib_name1, 6, data->buf1, &needed, NULL, 0) < 0) - return FALSE; - lim = data->buf1 + needed; - next = data->buf1; - while ((next < lim) && (validinterface == 0)) - { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type != RTM_IFINFO) - return FALSE; - next += ifm->ifm_msglen; - - while (next < lim) - { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - next += nextifm->ifm_msglen; - } - - if (ifm->ifm_flags & IFF_UP) - { - sdl = (struct sockaddr_dl *)(ifm + 1); - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; - /* search for the right network interface */ - if (sdl->sdl_family != AF_LINK) - continue; - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - else - { - validinterface = TRUE; - break; /* stop searching */ - } - } - } - return validinterface; -} -/****************************************************************************** - * - * get_stat() - * - * this code is based on gkrellm code (thanks guys!) - * - ****************************************************************************/ - -int get_stat(netdata* data) -{ - char *lim, *next; - struct if_msghdr *ifm, *nextifm; - struct sockaddr_dl *sdl; - char s[32]; - size_t needed; - unsigned long rx_o, tx_o; - - if (sysctl(data->mib_name2, 6, NULL, &needed, NULL, 0) < 0) - return 1; - if (data->alloc2 < (signed long) needed) - { - if (data->buf2 != NULL) - free (data->buf2); - data->buf2 = malloc(needed); - if (data->buf2 == NULL) - return 1; - data->alloc2 = needed; - } - - if (sysctl(data->mib_name2, 6, data->buf2, &needed, NULL, 0) < 0) - return 1; - lim = data->buf2 + needed; - next = data->buf2; - while (next < lim) - { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type != RTM_IFINFO) - return 1; - next += ifm->ifm_msglen; - - while (next < lim) - { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - next += nextifm->ifm_msglen; - } - - if (ifm->ifm_flags & IFF_UP) - { - sdl = (struct sockaddr_dl *)(ifm + 1); - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; - - /* search for the right network interface */ - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - - rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; - /* write stats */ - data->stats.tx_packets = ifm->ifm_data.ifi_opackets; - data->stats.rx_packets = ifm->ifm_data.ifi_ipackets; - data->stats.rx_bytes = ifm->ifm_data.ifi_ibytes; - data->stats.tx_bytes = ifm->ifm_data.ifi_obytes; - data->stats.rx_errors = ifm->ifm_data.ifi_ierrors; - data->stats.tx_errors = ifm->ifm_data.ifi_oerrors; - - if (rx_o > data->stats.rx_bytes) - data->stats.rx_over++; - if (tx_o > data->stats.tx_bytes) - data->stats.tx_over++; - } - } - return 0; -} diff --git a/panel-plugin/wormulon/netbsd.h b/panel-plugin/wormulon/netbsd.h deleted file mode 100644 index 87c90d5..0000000 --- a/panel-plugin/wormulon/netbsd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef NETBSD_H -#define NETBSD_H - -#include "../net.h" - -void init_osspecific(netdata* data); -int checkinterface(netdata* data); -int get_stat(netdata* data); - -#endif /* NETBSD_H */ diff --git a/panel-plugin/wormulon/openbsd.c b/panel-plugin/wormulon/openbsd.c deleted file mode 100644 index b138c6b..0000000 --- a/panel-plugin/wormulon/openbsd.c +++ /dev/null @@ -1,173 +0,0 @@ -/***************************************************************************** - * - * init_osspecific() - * - * Init function - * - ****************************************************************************/ - -void init_osspecific(netdata* data) -{ - data->mib_name1[0] = CTL_NET; - data->mib_name1[1] = PF_ROUTE; - data->mib_name1[2] = 0; - data->mib_name1[3] = 0; - data->mib_name1[4] = NET_RT_IFLIST; - data->mib_name1[5] = 0; - - data->mib_name2[0] = CTL_NET; - data->mib_name2[1] = PF_ROUTE; - data->mib_name2[2] = 0; - data->mib_name2[3] = 0; - data->mib_name2[4] = NET_RT_IFLIST; - data->mib_name2[5] = 0; - -#ifdef DEBUG - fprintf( stderr, "The netload plugin was initialized for OpenBSD.\n" ); -#endif -} - -/***************************************************************************** - * - * checkinterface() - * - * check if a given interface exists, return TRUE if it does and FALSE if not - * - ****************************************************************************/ -int checkinterface(netdata* data) -{ - int validinterface = FALSE; - char *lim, *next; - struct if_msghdr *ifm, *nextifm; - struct sockaddr_dl *sdl; - size_t needed; - char s[32]; - - if (sysctl(data->mib_name1, 6, NULL, &needed, NULL, 0) < 0) - return FALSE; - if (data->alloc1 < (signed long) needed) - { - if (data->buf1 != NULL) - free (data->buf1); - data->buf1 = malloc(needed); - if (data->buf1 == NULL) - return FALSE; - data->alloc1 = needed; - } - - if (sysctl(data->mib_name1, 6, data->buf1, &needed, NULL, 0) < 0) - return FALSE; - - lim = data->buf1 + needed; - next = data->buf1; - while ((next < lim) && (validinterface == 0)) - { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type != RTM_IFINFO) - return FALSE; - next += ifm->ifm_msglen; - - while (next < lim) - { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - next += nextifm->ifm_msglen; - } - - if (ifm->ifm_flags & IFF_UP) - { - sdl = (struct sockaddr_dl *)(ifm + 1); - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; - /* search for the right network interface */ - if (sdl->sdl_family != AF_LINK) - continue; - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - else - { - validinterface = TRUE; - break; /* stop searching */ - } - } - } - return validinterface; -} - -/***************************************************************************** - * - * get_stat() - * - * this code is based on gkrellm code (thanks guys!) - * - ****************************************************************************/ - -int get_stat(netdata* data) -{ - char *lim, *next; - struct if_msghdr *ifm, *nextifm; - struct sockaddr_dl *sdl; - char s[32]; - size_t needed; - unsigned long rx_o, tx_o; - - if (sysctl(data->mib_name2, 6, NULL, &needed, NULL, 0) < 0) - return 1; - if (data->alloc2 < (signed long) needed) - { - if (data->buf2 != NULL) - free (data->buf2); - data->buf2 = malloc(needed); - if (data->buf2 == NULL) - return 1; - data->alloc2 = needed; - } - - if (sysctl(data->mib_name2, 6, data->buf2, &needed, NULL, 0) < 0) - return 1; - lim = data->buf2 + needed; - next = data->buf2; - while (next < lim) - { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type != RTM_IFINFO) - return 1; - next += ifm->ifm_msglen; - - while (next < lim) - { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - next += nextifm->ifm_msglen; - } - - if (ifm->ifm_flags & IFF_UP) - { - sdl = (struct sockaddr_dl *)(ifm + 1); - /* search for the right network interface */ - if (sdl->sdl_family != AF_LINK) - continue; - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - - rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; - /* write stats */ - data->stats.tx_packets = ifm->ifm_data.ifi_opackets; - data->stats.rx_packets = ifm->ifm_data.ifi_ipackets; - data->stats.rx_bytes = ifm->ifm_data.ifi_ibytes; - data->stats.tx_bytes = ifm->ifm_data.ifi_obytes; - data->stats.rx_errors = ifm->ifm_data.ifi_ierrors; - data->stats.tx_errors = ifm->ifm_data.ifi_oerrors; - - if (rx_o > data->stats.rx_bytes) - data->stats.rx_over++; - if (tx_o > data->stats.tx_bytes) - data->stats.tx_over++; - } - } - return 0; -} diff --git a/panel-plugin/wormulon/openbsd.h b/panel-plugin/wormulon/openbsd.h deleted file mode 100644 index 6d9737a..0000000 --- a/panel-plugin/wormulon/openbsd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OPENBSD_H -#define OPENBSD_H - -#include "../net.h" - -void init_osspecific(netdata* data); -int checkinterface(netdata* data); -int get_stat(netdata* data); - -#endif /* OPENBSD_H */ diff --git a/panel-plugin/wormulon/solaris.c b/panel-plugin/wormulon/solaris.c deleted file mode 100644 index 7d98d38..0000000 --- a/panel-plugin/wormulon/solaris.c +++ /dev/null @@ -1,151 +0,0 @@ -/***************************************************************************** - * - * init_osspecific() - * - * Init function - * - ****************************************************************************/ - -void init_osspecific(netdata* data) -{ - /* nothing */ - -#ifdef DEBUG - fprintf( stderr, "The netload plugin was initialized for Sun Solaris.\n" ); -#endif - -} - -/***************************************************************************** - * - * checkinterface() - * - * check if a given interface exists, return TRUE if it does and FALSE if not - * - ****************************************************************************/ - -int checkinterface(netdata* data) -{ - int validinterface = FALSE; - int sockfd, i, numifs, numifreqs; - size_t bufsize; - char *buf; - struct ifreq ifr, *ifrp; - struct ifconf ifc; - unsigned long rx_o, tx_o; - - if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - { - perror("socket"); - return FALSE; - } - if (ioctl(sockfd, SIOCGIFNUM, (char *) &numifs) < 0) - { - perror("SIOCGIFNUM"); - close(sockfd); - return FALSE; - } - bufsize = ((size_t) numifs) * sizeof(struct ifreq); - buf = (char *) malloc(bufsize); - if (!buf) - { - perror("malloc"); - close(sockfd); - return FALSE; - } - - ifc.ifc_len = bufsize; - ifc.ifc_buf = buf; - - if (ioctl(sockfd, SIOCGIFCONF, (char *) &ifc) < 0) - { - perror("SIOCGIFCONF"); - close(sockfd); - free(buf); - return FALSE; - } - - ifrp = ifc.ifc_req; - numifreqs = ifc.ifc_len / sizeof(struct ifreq); - - for (i = 0; i < numifreqs; i++, ifrp++) - { - memset((char *)&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); - /* do not check for loopback device as it cannot be monitored */ - if (!strncmp(ifr.ifr_name, "lo", 2)) - continue; - if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) - { - perror("SIOCGIFFLAGS"); - continue; - } - if (!strcmp(data->ifdata.if_name, ifr.ifr_name) && (ifr.ifr_flags & IFF_UP)) - { - validinterface = TRUE; - break; - } - } - free(buf); - close(sockfd); - - return validinterface; -} - -/***************************************************************************** - * - * get_stat() - * - * use the Solaris kstat_*() interface to gather statistics - * We have to open/close *kc each time :( - * - ****************************************************************************/ - -int get_stat(netdata* data) -{ - kstat_t *ksp; - kstat_named_t *knp; - kstat_ctl_t *kc; - unsigned long rx_o, tx_o; - - if ((kc = kstat_open()) == NULL) - { - perror("kstat_open()"); - return 1; - } - - rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; - - ksp = kstat_lookup(kc, NULL, -1, data->ifdata.if_name); - if (ksp && kstat_read(kc, ksp, NULL) >= 0) - { - knp = (kstat_named_t *)kstat_data_lookup(ksp, "opackets"); - if (knp) - data->stats.tx_packets = knp->value.ui32; - knp = (kstat_named_t *)kstat_data_lookup(ksp, "ipackets"); - if (knp) - data->stats.rx_packets = knp->value.ui32; - knp = (kstat_named_t *)kstat_data_lookup(ksp, "obytes"); - if (knp) - data->stats.tx_bytes = knp->value.ui32; - knp = (kstat_named_t *)kstat_data_lookup(ksp, "rbytes"); - if (knp) - data->stats.rx_bytes = knp->value.ui32; - knp = (kstat_named_t *)kstat_data_lookup(ksp, "oerrors"); - if (knp) - data->stats.tx_errors = knp->value.ui32; - knp = (kstat_named_t *)kstat_data_lookup(ksp, "ierrors"); - if (knp) - data->stats.rx_errors = knp->value.ui32; - } - - kstat_close(kc); - - /* check for overflows */ - if (rx_o > data->stats.rx_bytes) - data->stats.rx_over++; - if (tx_o > data->stats.tx_bytes) - data->stats.tx_over++; - - return 0; -} diff --git a/panel-plugin/wormulon/solaris.h b/panel-plugin/wormulon/solaris.h deleted file mode 100644 index e113747..0000000 --- a/panel-plugin/wormulon/solaris.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SOLARIS_H -#define SOLARIS_H - -#include "../net.h" - -void init_osspecific(netdata* data); -int checkinterface(netdata* data); -int get_stat(netdata* data); - -#endif /* SOLARIS_H */