remove other os
parent
96b17fc5f7
commit
bfdda2fde9
|
@ -22,204 +22,23 @@
|
|||
#ifndef _OS_H
|
||||
#define _OS_H
|
||||
|
||||
#if defined (__sun__)
|
||||
# define __Solaris__ 1
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/param.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#ifdef __HPUX__ /* H P U X */
|
||||
# define _XOPEN_SOURCE_EXTENDED
|
||||
# include <stdio.h>
|
||||
# include <sys/param.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <stropts.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/stdsyms.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <sys/mib.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <net/if.h>
|
||||
#elif defined (__APPLE__) /* Mac OS X */
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <curses.h>
|
||||
# include <ifaddrs.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/route.h>
|
||||
# include <net/if_dl.h>
|
||||
# include <net/if.h>
|
||||
# include <net/if_media.h>
|
||||
# include <net/if_mib.h>
|
||||
# include <arpa/inet.h>
|
||||
#elif defined (__DragonFly__) /* D R A G O N F L Y */
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <net/if_media.h>
|
||||
# include <net/if_mib.h>
|
||||
# include <arpa/inet.h>
|
||||
#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) /* F R E E B S D */
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <net/if_media.h>
|
||||
# include <net/if_mib.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <ifaddrs.h>
|
||||
#elif defined (__NetBSD__) /* N E T B S D */
|
||||
# include <stdio.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <net/if_media.h>
|
||||
# include <net/route.h>
|
||||
# include <net/if_dl.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <net/if.h>
|
||||
# include <ifaddrs.h>
|
||||
#elif defined (__OpenBSD__) || defined (__MicroBSD__) /* O P E N B S D */
|
||||
# include <stdio.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <net/if_media.h>
|
||||
# include <net/if_dl.h>
|
||||
# include <net/route.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <ifaddrs.h>
|
||||
#elif defined (__linux__) /* L I N U X */
|
||||
# include <stdio.h>
|
||||
# include <sys/param.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <ifaddrs.h>
|
||||
#elif defined (__Solaris__) /* S O L A R I S */
|
||||
# include <stdio.h>
|
||||
# define _WIDEC_H
|
||||
# include <sys/param.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <netinet/in.h>
|
||||
# include <net/if.h>
|
||||
# include <stropts.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/sockio.h>
|
||||
# include <net/if.h>
|
||||
# include <kstat.h>
|
||||
# include <net/if.h>
|
||||
# include <sys/sockio.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <net/if.h>
|
||||
#else
|
||||
# error "OS not supported"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -1,197 +0,0 @@
|
|||
#include <netio.h>
|
||||
#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);
|
||||
}
|
|
@ -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 */
|
|
@ -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;
|
||||
}
|
|
@ -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 */
|
|
@ -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;
|
||||
}
|
|
@ -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 */
|
|
@ -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;
|
||||
}
|
|
@ -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 */
|
|
@ -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;
|
||||
}
|
|
@ -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 */
|
Loading…
Reference in New Issue