X-Git-Url: https://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parseiptables.c;h=36859289e14a9d8a40b70a5346d72095674b194d;hp=8544df788461c6a0aa29d6a83a89b7e68876a8d0;hb=47b5fd64878b8e1206cbdc7fc2ec65308b0d9e89;hpb=bf59a20b46290db34e1761926a39ee68164d636b diff --git a/parseiptables.c b/parseiptables.c index 8544df7..3685928 100644 --- a/parseiptables.c +++ b/parseiptables.c @@ -3,7 +3,7 @@ #include "cll1-0.6.2.h" #include "ipstruct.h" -#define STRLEN 512 +#define STRLEN 256 /* globals declared in prometheus.c */ extern struct IP *ips, *ip, *sharedip; @@ -13,35 +13,40 @@ extern int free_min; extern int free_max; extern int include_upload; +int traffic_detected = 0; +extern char *iptablesdump; + /* ===================== traffic analyser - uses iptables ================ */ void get_traffic_statistics(const char *whichiptables, int ipv6) { char *str,*cmd; - int downloadflag=0; - - textfile(Pipe,str) *line,*lines=NULL; - string(str,STRLEN); + int downloadflag = 0; + FILE *f; string(cmd,STRLEN); - sprintf(cmd,"%s -L -v -x -n -t mangle", whichiptables); - shell(cmd); - input(str,STRLEN) - { - create(line,Pipe); - line->str=str; - string(str,STRLEN); - append(line,lines); - } + sprintf(cmd, "%s -L -v -x -n -t mangle>%s", whichiptables, iptablesdump); + /*-----------------------------------------------------------------*/ + printf("Running %s ...\n", cmd); + /*-----------------------------------------------------------------*/ + system(cmd); + /*-----------------------------------------------------------------*/ + printf("Processing %s ...\n", iptablesdump); + /*-----------------------------------------------------------------*/ + f = fopen(iptablesdump,"r"); + if(!f) + perror(iptablesdump); - for_each(line,lines) + while(!feof(f)) { int col, accept = 0, /*proxyflag = 0, */valid = 1, setchainname = 0, commonflag = 0; unsigned long long traffic = 0; unsigned long pkts = 0; char *ipaddr = NULL,*ptr; - valid_columns(ptr, line->str, ' ', col) + string(str, STRLEN); + fgets(str, STRLEN, f); + valid_columns(ptr, str, ' ', col) if(valid) switch(col) { case 1: if(eq(ptr,"Chain")) @@ -150,6 +155,7 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) printf("(down) "); } + traffic_detected = 1; printf("%s %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts); if_exists(ip, ips, eqi(ip->addr,ipaddr));