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_expect *exp,
00010 void *data)
00011 {
00012 static int n = 0;
00013 char buf[1024];
00014
00015 nfexp_snprintf(buf, 1024, exp, type, NFCT_O_DEFAULT, 0);
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(EXPECT, NF_NETLINK_CONNTRACK_EXP_NEW |
00030 NF_NETLINK_CONNTRACK_EXP_UPDATE |
00031 NF_NETLINK_CONNTRACK_EXP_DESTROY);
00032 if (!h) {
00033 perror("nfct_open");
00034 return -1;
00035 }
00036
00037 nfexp_callback_register(h, NFCT_T_ALL, event_cb, NULL);
00038
00039 printf("TEST: waiting for 10 expectation events...\n");
00040
00041 ret = nfexp_catch(h);
00042
00043 printf("TEST: expectation events ");
00044 if (ret == -1)
00045 printf("(%d)(%s)\n", ret, strerror(errno));
00046 else
00047 printf("(OK)\n");
00048
00049 nfct_close(h);
00050
00051 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
00052 }