1 /***************************************************************************
2 * Copyright (C) 2004 by Intra2net AG *
3 * opensource@intra2net.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License *
7 * version 2.1 as published by the Free Software Foundation; *
9 ***************************************************************************/
18 #include <ipt_ACCOUNT_cl.h>
20 char *addr_to_dotted(unsigned int addr)
23 const unsigned char *bytep;
25 bytep = (const unsigned char *) &addr;
26 sprintf(buf, "%u.%u.%u.%u", bytep[0], bytep[1], bytep[2], bytep[3]);
30 int main(int argc, char *argv[])
32 struct ipt_ACCOUNT_context ctx;
33 struct ipt_account_handle_ip *entry;
38 printf("Syntax: %s TABLE-NAME\n", argv[0]);
42 if(ipt_ACCOUNT_init(&ctx))
44 printf("Init failed: %s\n", ctx.error_str);
50 printf("Run #%d\n", i);
52 // Get entries from table test
53 if (ipt_ACCOUNT_read_entries(&ctx, argv[1], 0))
55 printf("Read failed: %s\n", ctx.error_str);
56 ipt_ACCOUNT_deinit(&ctx);
60 // Output and free entries
61 while ((entry = ipt_ACCOUNT_get_next_entry(&ctx)) != NULL)
63 printf("IP: %s SRC packets: %u bytes: %u DST packets: %u bytes: %u\n",
64 addr_to_dotted(entry->ip), entry->src_packets, entry->src_bytes, entry->dst_packets, entry->dst_bytes);
70 ipt_ACCOUNT_deinit(&ctx);