7 #include <libmnl/libmnl.h>
8 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
10 #include <linux/netfilter/nf_conntrack_tcp.h>
14 struct mnl_socket *nl;
17 char buf[MNL_SOCKET_BUFFER_SIZE];
18 unsigned int seq, portid;
21 nl = mnl_socket_open(NETLINK_NETFILTER);
23 perror(
"mnl_socket_open");
27 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
28 perror(
"mnl_socket_bind");
31 portid = mnl_socket_get_portid(nl);
33 nlh = mnl_nlmsg_put_header(buf);
34 nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK << 8) | IPCTNL_MSG_CT_DELETE;
35 nlh->nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
36 nlh->nlmsg_seq = seq = time(NULL);
38 nfh = mnl_nlmsg_put_extra_header(nlh,
sizeof(
struct nfgenmsg));
39 nfh->nfgen_family = AF_INET;
40 nfh->version = NFNETLINK_V0;
43 ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len);
45 perror(
"mnl_socket_recvfrom");
49 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
51 ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
52 if (ret <= MNL_CB_STOP)
54 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
57 perror(
"mnl_socket_recvfrom");