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
event_cb(enum nf_conntrack_msg_type type,struct nf_conntrack * ct,void * data)8 static int event_cb(enum nf_conntrack_msg_type type,
9 struct nf_conntrack *ct,
10 void *data)
11 {
12 static int n = 0;
13 char buf[1024];
14
15 nfct_snprintf(buf, sizeof(buf), ct, type, NFCT_O_XML, NFCT_OF_TIME | NFCT_OF_TIMESTAMP);
16 printf("%s\n", buf);
17
18 if (++n == 10)
19 return NFCT_CB_STOP;
20
21 return NFCT_CB_CONTINUE;
22 }
23
main(void)24 int main(void)
25 {
26 int ret;
27 struct nfct_handle *h;
28
29 h = nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS);
30 if (!h) {
31 perror("nfct_open");
32 return 0;
33 }
34
35 nfct_callback_register(h, NFCT_T_ALL, event_cb, NULL);
36
37 printf("TEST: waiting for 10 events...\n");
38
39 ret = nfct_catch(h);
40
41 printf("TEST: conntrack events ");
42 if (ret == -1)
43 printf("(%d)(%s)\n", ret, strerror(errno));
44 else
45 printf("(OK)\n");
46
47 nfct_close(h);
48
49 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
50 }
51