X-Git-Url: https://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parseiptables.c;h=36859289e14a9d8a40b70a5346d72095674b194d;hp=cc2daacc5df3db6810a4657837ec4c4b17e9977e;hb=47b5fd64878b8e1206cbdc7fc2ec65308b0d9e89;hpb=d7357b63c9942c72481993bdb9632861c1d83a55 diff --git a/parseiptables.c b/parseiptables.c index cc2daac..3685928 100644 --- a/parseiptables.c +++ b/parseiptables.c @@ -1,47 +1,52 @@ -/* Modified by: xChaos, 20130115 */ +/* Modified by: xChaos, 20131208 */ #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; extern char *mark; -extern char *proxy_ip; +/* extern char *proxy_ip; */ 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; + 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")) @@ -98,14 +103,17 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) } else if(!ipv6) { - if(downloadflag) +/* if(downloadflag) { if(strstr(proxy_ip,ptr)) { proxyflag = 1; } - } - else + + } + else + { */ + if(!downloadflag) { ipaddr = ptr; } @@ -125,14 +133,20 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) if(ipv6 && isipv6) { *isipv6=0; - printf("(IPv6) "); + printf("(IPv6) "); } - + else + { + printf("(IPv4) "); + } +/* if(proxyflag) { printf("(proxy) "); } - else if(!downloadflag) + else +*/ + if(!downloadflag) { printf("(up) "); } @@ -141,12 +155,13 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) printf("(down) "); } - printf("IP %s: %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts); + traffic_detected = 1; + printf("%s %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts); if_exists(ip, ips, eqi(ip->addr,ipaddr)); else { - TheIP(ipaddr); + TheIP(ipaddr, FALSE); if(eq(ip->addr,"0.0.0.0/0")) { ip->name = "(unregistered)"; @@ -161,30 +176,33 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) if(downloadflag) { +/* if(proxyflag) { ip->proxy = traffic; } else - { - ip->traffic += traffic; - } - ip->direct = ip->traffic-ip->upload-ip->proxy; - ip->pktsdown = pkts; + {*/ + ip->traffic += traffic; + ip->traffic_down += traffic; +/* } */ + ip->direct += traffic; /*-ip->proxy;*/ + ip->pktsdown += pkts; } else { - ip->upload = traffic; - ip->pktsup = pkts; + ip->upload += traffic; + ip->traffic_up += traffic; + ip->pktsup += pkts; if(include_upload) { ip->traffic += traffic; } else { - if(traffic > ip->traffic) + if(ip->upload > ip->traffic) { - ip->traffic = traffic; + ip->traffic = ip->upload; } } }