7 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
8 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
10 static int event_cb(
enum nf_conntrack_msg_type type,
11 struct nf_conntrack *ct,
17 nfct_snprintf(buf,
sizeof(buf), ct, type, NFCT_O_PLAIN, NFCT_OF_TIME);
23 return NFCT_CB_CONTINUE;
29 struct nfct_handle *h;
30 struct nfct_filter *filter;
32 h =
nfct_open(CONNTRACK, NF_NETLINK_CONNTRACK_NEW |
33 NF_NETLINK_CONNTRACK_UPDATE);
41 perror(
"nfct_create_filter");
50 .state = TCP_CONNTRACK_ESTABLISHED
57 .addr = ntohl(inet_addr(
"127.0.0.1")),
64 NFCT_FILTER_LOGIC_NEGATIVE);
70 .addr = { 0x0, 0x0, 0x0, 0x1 },
71 .mask = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff },
77 NFCT_FILTER_LOGIC_NEGATIVE);
82 perror(
"nfct_filter_attach");
91 printf(
"TEST: waiting for 10 events...\n");
95 printf(
"TEST: conntrack events ");
97 printf(
"(%d)(%s)\n", ret, strerror(errno));
103 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
void nfct_filter_destroy(struct nfct_filter *filter)
void nfct_filter_add_attr_u32(struct nfct_filter *filter, const enum nfct_filter_attr attr, const uint32_t value)
int nfct_close(struct nfct_handle *cth)
int nfct_fd(struct nfct_handle *cth)
int nfct_snprintf(char *buf, unsigned int size, const struct nf_conntrack *ct, const unsigned int msg_type, const unsigned int out_type, const unsigned int out_flags)
void nfct_filter_add_attr(struct nfct_filter *filter, const enum nfct_filter_attr attr, const void *value)
struct nfct_filter * nfct_filter_create(void)
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_filter_set_logic(struct nfct_filter *filter, const enum nfct_filter_attr attr, const enum nfct_filter_logic logic)
int nfct_filter_attach(int fd, struct nfct_filter *filter)
int nfct_catch(struct nfct_handle *h)
struct nfct_handle * nfct_open(uint8_t, unsigned)