netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* need help with capturing packet and bytes count from conntrack
@ 2010-09-09 13:19 Pete Kay
  2010-09-09 23:19 ` James King
  0 siblings, 1 reply; 2+ messages in thread
From: Pete Kay @ 2010-09-09 13:19 UTC (permalink / raw)
  To: netfilter-devel

Hi,

I am trying to write a small piece of code to obtain the packet count
and bytes count for a connection.

Here is what I get from conntrack -L

[root@linux]# conntrack -L -p udp -s 192.168.1.179 -d 192.168.1.115
--sport 10374
udp      17 88 src=192.168.1.179 dst=192.168.1.115 sport=10374
dport=26926 packets=850 bytes=170000 src=192.168.1.56
dst=192.168.1.115 sport=16395 dport=26924 packets=571 bytes=159880
[ASSURED] mark=0 use=1

=============
When I run the following source code, I get 0 for all caller_bytes,
callee_bytes, caller_packets, callee_packets, does anyone know what is
wrong with my code here?


 uint32_t caller_bytes, callee_bytes, caller_packets, callee_packets;
        int ret = 0;
        struct nfct_handle *h;
        struct nf_conntrack *ct;
        ct = nfct_new();
        if (!ct) {
                perror("nfct_new");

        }

        switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel),
SWITCH_LOG_DEBUG, "end_point_media_ip=[%s] end_point_media_port=[%s]
server_media_ip=[%s] se$

        nfct_set_attr_u8(ct, ATTR_L3PROTO, AF_INET);
        nfct_set_attr_u32(ct, ATTR_IPV4_SRC, inet_addr("192.168.1.179"));
        nfct_set_attr_u32(ct, ATTR_IPV4_DST, inet_addr("192.168.1.115"));
        nfct_set_attr_u8(ct, ATTR_L4PROTO, IPPROTO_UDP);
        nfct_set_attr_u16(ct, ATTR_PORT_SRC, htons(10374);
        nfct_set_attr_u16(ct, ATTR_PORT_DST, htons(26926);

        h = nfct_open(CONNTRACK, 0);
        if (!h) {
                perror("nfct_open");
        }
        ret = nfct_query(h, NFCT_Q_GET, ct);
        printf("TEST: query conntrack ");
        if (ret == -1)
              printf("(%d)(%s)\n", ret, strerror(errno));
        else
              printf("(OK)\n");


        caller_bytes = nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_BYTES);
        callee_bytes = nfct_get_attr_u32(ct, ATTR_REPL_COUNTER_BYTES);
        caller_packets = nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_PACKETS);
        callee_packets = nfct_get_attr_u32(ct, ATTR_REPL_COUNTER_PACKETS);
        nfct_close(h);

        printf("caller_bytes=[%lu] callee_bytes=[%lu]
caller_packet=[%lu] callee_packet=[%lu]\n", (unsigned
long)caller_bytes, (unsigned long)callee_bytes, (unsigned
long)caller_packets,(unsigned long) callee_packets);




Thank you in advance for all your kind help.



thanks,
P

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-09 23:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-09 13:19 need help with capturing packet and bytes count from conntrack Pete Kay
2010-09-09 23:19 ` James King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).