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_expect *exp;
13 uint32_t type = NFCT_T_UNKNOWN;
20 if (nfexp_nlmsg_parse(nlh, exp) < 0) {
21 perror(
"failed to parse message from kernel");
35 struct mnl_socket *nl;
36 char buf[MNL_SOCKET_BUFFER_SIZE];
42 nl = mnl_socket_open(NETLINK_NETFILTER);
44 perror(
"mnl_socket_open");
48 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
49 perror(
"mnl_socket_bind");
53 portid = mnl_socket_get_portid(nl);
55 nlh = mnl_nlmsg_put_header(buf);
56 nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK_EXP << 8) | IPCTNL_MSG_EXP_GET;
57 nlh->nlmsg_flags = NLM_F_REQUEST|NLM_F_DUMP|NLM_F_ACK;
58 nlh->nlmsg_seq = seq = time(NULL);
60 nfh = mnl_nlmsg_put_extra_header(nlh,
sizeof(
struct nfgenmsg));
61 nfh->nfgen_family = AF_INET;
62 nfh->version = NFNETLINK_V0;
65 ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len);
67 perror(
"mnl_socket_recvfrom");
71 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
73 ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL);
74 if (ret <= MNL_CB_STOP)
77 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
80 perror(
"mnl_socket_recvfrom");
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)