2008-06-21 13:33:06 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "common.h"
|
|
|
|
|
2009-01-23 13:56:20 +01:00
|
|
|
#define PROC_NET_SNMP "/proc/net/snmp"
|
|
|
|
|
2008-06-21 13:33:06 +02:00
|
|
|
int fw_packets(int argc, char **argv) {
|
|
|
|
FILE *f;
|
|
|
|
char buff[1024], *s;
|
|
|
|
if(argc > 1) {
|
|
|
|
if(!strcmp(argv[1], "config")) {
|
|
|
|
puts("graph_title Firewall Throughput\n"
|
|
|
|
"graph_args --base 1000 -l 0\n"
|
|
|
|
"graph_vlabel Packets/${graph_period}\n"
|
|
|
|
"graph_category network\n"
|
|
|
|
"received.label Received\n"
|
|
|
|
"received.draw AREA\n"
|
|
|
|
"received.type DERIVE\n"
|
|
|
|
"received.min 0\n"
|
|
|
|
"forwarded.label Forwarded\n"
|
|
|
|
"forwarded.draw LINE2\n"
|
|
|
|
"forwarded.type DERIVE\n"
|
|
|
|
"forwarded.min 0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!strcmp(argv[1], "autoconf")) {
|
2009-01-23 13:56:20 +01:00
|
|
|
if(0 == access(PROC_NET_SNMP, R_OK))
|
2008-06-21 13:33:06 +02:00
|
|
|
return writeyes();
|
|
|
|
else
|
2009-01-23 13:56:20 +01:00
|
|
|
return writeno(PROC_NET_SNMP " not readable");
|
2008-06-21 13:33:06 +02:00
|
|
|
}
|
|
|
|
}
|
2009-01-23 13:56:20 +01:00
|
|
|
if(!(f=fopen(PROC_NET_SNMP, "r"))) {
|
|
|
|
fputs("cannot open " PROC_NET_SNMP "\n", stderr);
|
2008-06-21 13:33:06 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
while(fgets(buff, 1024, f)) {
|
|
|
|
if(!strncmp(buff, "Ip: ", 4) && isdigit(buff[4])) {
|
|
|
|
fclose(f);
|
|
|
|
if(!(s = strtok(buff+4, " \t")))
|
|
|
|
break;
|
|
|
|
if(!(s = strtok(NULL, " \t")))
|
|
|
|
break;
|
|
|
|
if(!(s = strtok(NULL, " \t")))
|
|
|
|
break;
|
|
|
|
printf("received.value %s\n", s);
|
|
|
|
if(!(s = strtok(NULL, " \t")))
|
|
|
|
break;
|
|
|
|
if(!(s = strtok(NULL, " \t")))
|
|
|
|
break;
|
|
|
|
if(!(s = strtok(NULL, " \t")))
|
|
|
|
break;
|
|
|
|
printf("forwarded.value %s\n", s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
2009-01-23 13:56:20 +01:00
|
|
|
fputs("no ip line found in " PROC_NET_SNMP "\n", stderr);
|
2008-06-21 13:33:06 +02:00
|
|
|
return 1;
|
|
|
|
}
|