7 #include <libmnl/libmnl.h>
8 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
10 static int data_cb(
const struct nlmsghdr *nlh,
void *data)
12 struct nf_conntrack *ct;
19 nfct_nlmsg_parse(nlh, ct);
21 nfct_snprintf(buf,
sizeof(buf), ct, NFCT_T_UNKNOWN, NFCT_O_DEFAULT, 0);
31 struct mnl_socket *nl;
34 char buf[MNL_SOCKET_BUFFER_SIZE];
35 unsigned int seq, portid;
38 nl = mnl_socket_open(NETLINK_NETFILTER);
40 perror(
"mnl_socket_open");
44 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
45 perror(
"mnl_socket_bind");
48 portid = mnl_socket_get_portid(nl);
50 nlh = mnl_nlmsg_put_header(buf);
51 nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK << 8) | IPCTNL_MSG_CT_GET;
52 nlh->nlmsg_flags = NLM_F_REQUEST|NLM_F_DUMP;
53 nlh->nlmsg_seq = seq = time(NULL);
55 nfh = mnl_nlmsg_put_extra_header(nlh,
sizeof(
struct nfgenmsg));
56 nfh->nfgen_family = AF_INET;
57 nfh->version = NFNETLINK_V0;
60 ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len);
62 perror(
"mnl_socket_recvfrom");
66 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
68 ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL);
69 if (ret <= MNL_CB_STOP)
71 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
74 perror(
"mnl_socket_recvfrom");
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)