libnetfilter_conntrack 1.0.9
conntrack_dump.c
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5
6#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
7
8static int cb(enum nf_conntrack_msg_type type,
9 struct nf_conntrack *ct,
10 void *data)
11{
12 char buf[1024];
13
14 nfct_snprintf(buf, sizeof(buf), ct, NFCT_T_UNKNOWN, NFCT_O_DEFAULT, NFCT_OF_SHOW_LAYER3 | NFCT_OF_TIMESTAMP);
15 printf("%s\n", buf);
16
17 return NFCT_CB_CONTINUE;
18}
19
20int main(void)
21{
22 int ret;
23 uint32_t family = AF_INET;
24 struct nfct_handle *h;
25
26 h = nfct_open(CONNTRACK, 0);
27 if (!h) {
28 perror("nfct_open");
29 return -1;
30 }
31
32 nfct_callback_register(h, NFCT_T_ALL, cb, NULL);
33 ret = nfct_query(h, NFCT_Q_DUMP, &family);
34
35 printf("TEST: get conntrack ");
36 if (ret == -1)
37 printf("(%d)(%s)\n", ret, strerror(errno));
38 else
39 printf("(OK)\n");
40
41 nfct_close(h);
42
43 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
44}
int nfct_callback_register(struct nfct_handle *h, enum nf_conntrack_msg_type type, int(*cb)(enum nf_conntrack_msg_type type, struct nf_conntrack *ct, void *data), void *data)
struct nfct_handle * nfct_open(uint8_t, unsigned)
Definition main.c:84
int nfct_close(struct nfct_handle *cth)
Definition main.c:105
int nfct_query(struct nfct_handle *h, const enum nf_conntrack_query query, const void *data)
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)