5 #include <libmnl/libmnl.h>
6 #include <libnetfilter_acct/libnetfilter_acct.h>
8 static int nfacct_cb(
const struct nlmsghdr *nlh,
void *data)
10 struct nfacct *nfacct;
20 perror(
"nfacct_parse_nl_msg");
25 NFACCT_SNPRINTF_T_PLAIN, NFACCT_SNPRINTF_F_FULL);
34 int main(
int argc,
char *argv[])
36 struct mnl_socket *nl;
37 char buf[MNL_SOCKET_BUFFER_SIZE];
44 fprintf(stderr,
"Usage: %s [-z]\n", argv[0]);
48 if (argc == 2 && strncmp(argv[1],
"-z", strlen(
"-z")) == 0)
53 NFNL_MSG_ACCT_GET_CTRZERO :
57 nl = mnl_socket_open(NETLINK_NETFILTER);
59 perror(
"mnl_socket_open");
63 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
64 perror(
"mnl_socket_bind");
67 portid = mnl_socket_get_portid(nl);
69 if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
70 perror(
"mnl_socket_send");
74 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
76 ret = mnl_cb_run(buf, ret, seq, portid, nfacct_cb, &full);
79 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
void nfacct_free(struct nfacct *nfacct)
int nfacct_nlmsg_parse_payload(const struct nlmsghdr *nlh, struct nfacct *nfacct)
struct nlmsghdr * nfacct_nlmsg_build_hdr(char *buf, uint8_t cmd, uint16_t flags, uint32_t seq)
struct nfacct * nfacct_alloc(void)
int nfacct_snprintf(char *buf, size_t size, struct nfacct *nfacct, uint16_t type, uint16_t flags)