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
cb(enum nf_conntrack_msg_type type,struct nf_conntrack * ct,void * data)8 static 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
main(void)20 int 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 }
45