cc2daacc5df3db6810a4657837ec4c4b17e9977e
1 /* Modified by: xChaos, 20130115 */
3 #include "cll1-0.6.2.h"
8 /* globals declared in prometheus.c */
9 extern struct IP
*ips
, *ip
, *sharedip
;
11 extern char *proxy_ip
;
14 extern int include_upload
;
16 /* ===================== traffic analyser - uses iptables ================ */
18 void get_traffic_statistics(const char *whichiptables
, int ipv6
)
23 textfile(Pipe
,str
) *line
,*lines
=NULL
;
27 sprintf(cmd
,"%s -L -v -x -n -t mangle", whichiptables
);
39 int col
, accept
= 0, proxyflag
= 0, valid
= 1, setchainname
= 0, commonflag
= 0;
40 unsigned long long traffic
= 0;
41 unsigned long pkts
= 0;
42 char *ipaddr
= NULL
,*ptr
;
44 valid_columns(ptr
, line
->str
, ' ', col
)
47 case 1: if(eq(ptr
,"Chain"))
51 else if(eq(ptr
,"pkts"))
57 sscanf(ptr
,"%lu",&pkts
);
60 case 2: if(setchainname
)
62 if(!strncmp(ptr
,"post_",5) || eq(ptr
,"POSTROUTING"))
68 if(!strncmp(ptr
,"forw_",5) || eq(ptr
,"FORWARD"))
73 if(eq(ptr
,"post_common") || eq(ptr
,"forw_common"))
80 sscanf(ptr
,"%Lu",&traffic
);
85 case 3: if((strncmp(ptr
,"post_",5) && strncmp(ptr
,"forw_",5)) || commonflag
)
87 accept
= eq(ptr
,mark
);
90 case 7: if(ipv6
&& !downloadflag
)
95 case 8: if(ipv6
&& downloadflag
)
103 if(strstr(proxy_ip
,ptr
))
114 case 9: if(!ipv6
&& downloadflag
)
121 if(accept
&& traffic
>0 && ipaddr
)
123 /* IPv6 subnet - /64 */
124 char *isipv6
= strstr(ipaddr
,"/64");
135 else if(!downloadflag
)
144 printf("IP %s: %Lu MB (%ld pkts)\n", ipaddr
, traffic
, pkts
);
146 if_exists(ip
, ips
, eqi(ip
->addr
,ipaddr
));
150 if(eq(ip
->addr
,"0.0.0.0/0"))
152 ip
->name
= "(unregistered)";
154 ip
->max
= ip
->desired
=free_max
;
170 ip
->traffic
+= traffic
;
172 ip
->direct
= ip
->traffic
-ip
->upload
-ip
->proxy
;
177 ip
->upload
= traffic
;
181 ip
->traffic
+= traffic
;
185 if(traffic
> ip
->traffic
)
187 ip
->traffic
= traffic
;
This page took 0.558051 seconds and 3 git commands to generate.