6 #include <libmnl/libmnl.h>
7 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
9 static int data_cb(
const struct nlmsghdr *nlh,
void *data)
11 struct nf_expect *exp;
12 uint32_t type = NFCT_T_UNKNOWN;
15 switch(nlh->nlmsg_type & 0xFF) {
16 case IPCTNL_MSG_EXP_NEW:
17 if (nlh->nlmsg_flags & (NLM_F_CREATE|NLM_F_EXCL))
22 case IPCTNL_MSG_EXP_DELETE:
23 type = NFCT_T_DESTROY;
31 nfexp_nlmsg_parse(nlh, exp);
34 type, NFCT_O_DEFAULT, 0);
44 struct mnl_socket *nl;
45 char buf[MNL_SOCKET_BUFFER_SIZE];
48 nl = mnl_socket_open(NETLINK_NETFILTER);
50 perror(
"mnl_socket_open");
54 if (mnl_socket_bind(nl, NF_NETLINK_CONNTRACK_EXP_NEW |
55 NF_NETLINK_CONNTRACK_EXP_UPDATE |
56 NF_NETLINK_CONNTRACK_EXP_DESTROY,
57 MNL_SOCKET_AUTOPID) < 0) {
58 perror(
"mnl_socket_bind");
63 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
65 perror(
"mnl_socket_recvfrom");
69 ret = mnl_cb_run(buf, ret, 0, 0, data_cb, NULL);
struct nf_expect * nfexp_new(void)
int nfexp_snprintf(char *buf, unsigned int size, const struct nf_expect *exp, const unsigned int msg_type, const unsigned int out_type, const unsigned int out_flags)
void nfexp_destroy(struct nf_expect *exp)