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 n = 0;
00009
00010 static int
00011 ct_event_cb(enum nf_conntrack_msg_type type,struct nf_conntrack *ct, void *data)
00012 {
00013 char buf[1024];
00014
00015 nfct_snprintf(buf, sizeof(buf), ct, type, NFCT_O_PLAIN, NFCT_OF_TIME);
00016 printf("[CT] %s\n", buf);
00017
00018 if (++n == 20)
00019 return NFCT_CB_STOP;
00020
00021 return NFCT_CB_CONTINUE;
00022 }
00023
00024 static int
00025 exp_event_cb(enum nf_conntrack_msg_type type,struct nf_expect *exp, void *data)
00026 {
00027 char buf[1024];
00028
00029 nfexp_snprintf(buf, 1024, exp, type, NFCT_O_DEFAULT, 0);
00030 printf("[EXP] %s\n", buf);
00031
00032 if (++n == 20)
00033 return NFCT_CB_STOP;
00034
00035 return NFCT_CB_CONTINUE;
00036 }
00037
00038 int main(void)
00039 {
00040 int ret = 0;
00041 struct nfct_handle *h;
00042
00043 h = nfct_open(NFNL_SUBSYS_NONE, NF_NETLINK_CONNTRACK_EXP_NEW |
00044 NF_NETLINK_CONNTRACK_EXP_UPDATE |
00045 NF_NETLINK_CONNTRACK_EXP_DESTROY |
00046 NF_NETLINK_CONNTRACK_NEW |
00047 NF_NETLINK_CONNTRACK_UPDATE |
00048 NF_NETLINK_CONNTRACK_DESTROY);
00049 if (h == NULL) {
00050 perror("nfct_open");
00051 return -1;
00052 }
00053
00054 nfexp_callback_register(h, NFCT_T_ALL, exp_event_cb, NULL);
00055 nfct_callback_register(h, NFCT_T_ALL, ct_event_cb, NULL);
00056
00057 printf("TEST: waiting for 20 expectation events...\n");
00058
00059
00060 ret = nfct_catch(h);
00061
00062 printf("TEST: expectation events ");
00063 if (ret == -1)
00064 printf("(%d)(%s)\n", ret, strerror(errno));
00065 else
00066 printf("(OK)\n");
00067
00068 nfct_close(h);
00069
00070 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
00071 }