• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

conntrack_events.c

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <errno.h>
00005 
00006 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
00007 
00008 static int event_cb(enum nf_conntrack_msg_type type,
00009                     struct nf_conntrack *ct,
00010                     void *data)
00011 {
00012         static int n = 0;
00013         char buf[1024];
00014 
00015         nfct_snprintf(buf, sizeof(buf), ct, type, NFCT_O_XML, NFCT_OF_TIME);
00016         printf("%s\n", buf);
00017 
00018         if (++n == 10)
00019                 return NFCT_CB_STOP;
00020 
00021         return NFCT_CB_CONTINUE;
00022 }
00023 
00024 int main(void)
00025 {
00026         int ret;
00027         struct nfct_handle *h;
00028 
00029         h = nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS);
00030         if (!h) {
00031                 perror("nfct_open");
00032                 return 0;
00033         }
00034 
00035         nfct_callback_register(h, NFCT_T_ALL, event_cb, NULL);
00036 
00037         printf("TEST: waiting for 10 events...\n");
00038 
00039         ret = nfct_catch(h);
00040 
00041         printf("TEST: conntrack events ");
00042         if (ret == -1)
00043                 printf("(%d)(%s)\n", ret, strerror(errno));
00044         else
00045                 printf("(OK)\n");
00046 
00047         nfct_close(h);
00048 
00049         ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
00050 }

Generated on Wed Jan 26 2011 23:11:37 for libnetfilter_conntrack by  doxygen 1.7.1