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