7 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
10 static int new, update, destroy;
12 static int event_cb(
enum nf_conntrack_msg_type type,
13 struct nf_conntrack *ct,
16 if (type == NFCT_T_NEW)
18 else if (type == NFCT_T_UPDATE)
20 else if (type == NFCT_T_DESTROY)
23 if ((++events % 10000) == 0)
24 printf(
"%d events received (%d new, %d update, %d destroy)\n",
25 events,
new, update, destroy);
27 return NFCT_CB_CONTINUE;
30 static void sighandler(
int foo)
32 printf(
"%d events received (%d new, %d update, %d destroy)\n",
33 events,
new, update, destroy);
40 struct nfct_handle *h;
43 signal(SIGINT, sighandler);
45 h =
nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS);
51 setsockopt(
nfct_fd(h), SOL_NETLINK,
52 NETLINK_BROADCAST_SEND_ERROR, &on,
sizeof(
int));
53 setsockopt(
nfct_fd(h), SOL_NETLINK,
54 NETLINK_NO_ENOBUFS, &on,
sizeof(
int));
58 printf(
"TEST: waiting for events...\n");
62 printf(
"TEST: conntrack events ");
64 printf(
"(%d)(%s)\n", ret, strerror(errno));
70 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
int nfct_close(struct nfct_handle *cth)
int nfct_fd(struct nfct_handle *cth)
int nfct_callback_register(struct nfct_handle *h, enum nf_conntrack_msg_type type, int(*cb)(enum nf_conntrack_msg_type type, struct nf_conntrack *ct, void *data), void *data)
int nfct_catch(struct nfct_handle *h)
struct nfct_handle * nfct_open(uint8_t, unsigned)