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_conntrack *ct;
12 uint32_t type = NFCT_T_UNKNOWN;
15 switch(nlh->nlmsg_type & 0xFF) {
16 case IPCTNL_MSG_CT_NEW:
17 if (nlh->nlmsg_flags & (NLM_F_CREATE|NLM_F_EXCL))
22 case IPCTNL_MSG_CT_DELETE:
23 type = NFCT_T_DESTROY;
31 nfct_nlmsg_parse(nlh, ct);
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_NEW |
55 NF_NETLINK_CONNTRACK_UPDATE |
56 NF_NETLINK_CONNTRACK_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);
void nfct_destroy(struct nf_conntrack *ct)
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)
struct nf_conntrack * nfct_new(void)