netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pete Kay <petedao@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: need help with capturing packet and bytes count from conntrack
Date: Thu, 9 Sep 2010 21:19:51 +0800	[thread overview]
Message-ID: <AANLkTimVxDP9PMOcA2bAXqcxiXj+J1Yx1n3Jfvferntr@mail.gmail.com> (raw)

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

             reply	other threads:[~2010-09-09 13:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-09 13:19 Pete Kay [this message]
2010-09-09 23:19 ` need help with capturing packet and bytes count from conntrack James King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimVxDP9PMOcA2bAXqcxiXj+J1Yx1n3Jfvferntr@mail.gmail.com \
    --to=petedao@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).