[iptstate-commit] iptstate iptstate.cc,1.17.2.1,1.17.2.2
Brought to you by:
jaymzh
|
From: Phil D. <ja...@us...> - 2010-01-17 01:27:37
|
Update of /cvsroot/iptstate/iptstate In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv31425 Modified Files: Tag: cpp_ification_branch iptstate.cc Log Message: (Copying commit from HEAD) Use unsigned numbers for srcpt, dstpt, bytes, and packets in the table_t struct to avoid negative numbers. Also, be sure to report the total number of bytes and packets in a connection by including both the in and out traffic. This patch is based largely on a patch by Vladimir <do...@nm...> which fixed this for bytes and packets, with small modifications by me. Signed-off-by: Phil Dibowitz <ph...@ip...> Index: iptstate.cc =================================================================== RCS file: /cvsroot/iptstate/iptstate/iptstate.cc,v retrieving revision 1.17.2.1 retrieving revision 1.17.2.2 diff -u -d -r1.17.2.1 -r1.17.2.2 --- iptstate.cc 23 Oct 2009 15:57:24 -0000 1.17.2.1 +++ iptstate.cc 17 Jan 2010 01:27:28 -0000 1.17.2.2 @@ -141,8 +141,7 @@ struct table_t { string proto, state, ttl, sname, dname, spname, dpname; in_addr src, dst; - int srcpt, dstpt, bytes, packets; - unsigned int id; + unsigned int srcpt, dstpt, bytes, packets, id; }; // x/y of the terminal window struct screensize_t { @@ -156,7 +155,7 @@ }; // Struct 'o counters struct counters_t { - int total, tcp, udp, icmp, other, skipped; + unsigned int total, tcp, udp, icmp, other, skipped; }; // Various filters to be applied pending the right flags in flags_t struct filters_t { @@ -164,7 +163,8 @@ }; // The max-length of fields in the stable table struct max_t { - unsigned int src, dst, proto, state, ttl, bytes, packets; + unsigned int src, dst, proto, state, ttl; + unsigned long bytes, packets; }; struct hook_data { vector<table_t> *stable; @@ -215,7 +215,7 @@ /* * This determines the length of an integer (i.e. number of digits) */ -unsigned int digits(int x) +unsigned int digits(unsigned long x) { return (unsigned int) floor(log10((double)x))+1; } @@ -314,7 +314,7 @@ } } -void resolve_port(const int &port, string &name, const string &proto) +void resolve_port(const unsigned int &port, string &name, const string &proto) { struct servent *portinfo = NULL; @@ -979,10 +979,11 @@ entry.src.s_addr = nfct_get_attr_u32(ct, ATTR_ORIG_IPV4_SRC); entry.dst.s_addr = nfct_get_attr_u32(ct, ATTR_ORIG_IPV4_DST); - // Counters - entry.bytes = nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_BYTES); - entry.packets = - nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_PACKETS); + // Counters (summary, in + out) + entry.bytes = nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_BYTES) + + nfct_get_attr_u32(ct, ATTR_REPL_COUNTER_BYTES); + entry.packets = nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_PACKETS) + + nfct_get_attr_u32(ct, ATTR_REPL_COUNTER_PACKETS); if (digits(entry.bytes) > max->bytes) { max->bytes = digits(entry.bytes); @@ -1068,7 +1069,7 @@ } if (flags->filter_srcpt - && (entry.srcpt != atoi(filters->srcpt.c_str()))) { + && (entry.srcpt != (unsigned int)atoi(filters->srcpt.c_str()))) { counts->skipped++; return NFCT_CB_CONTINUE; } @@ -1080,7 +1081,7 @@ } if (flags->filter_dstpt - && (entry.dstpt != atoi(filters->dstpt.c_str()))) { + && (entry.dstpt != (unsigned int)atoi(filters->dstpt.c_str()))) { counts->skipped++; return NFCT_CB_CONTINUE; } |