1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <arpa/inet.h>
6
7 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
8
main(void)9 int main(void)
10 {
11 int ret;
12 struct nfct_handle *h;
13 struct nf_conntrack *expected;
14 struct nf_expect *exp;
15
16 expected = nfct_new();
17 if (!expected) {
18 perror("nfct_new");
19 exit(EXIT_FAILURE);
20 }
21
22 nfct_set_attr_u8(expected, ATTR_L3PROTO, AF_INET);
23 nfct_set_attr_u32(expected, ATTR_IPV4_SRC, inet_addr("1.1.1.1"));
24 nfct_set_attr_u32(expected, ATTR_IPV4_DST, inet_addr("2.2.2.2"));
25
26 nfct_set_attr_u8(expected, ATTR_L4PROTO, IPPROTO_TCP);
27 nfct_set_attr_u16(expected, ATTR_PORT_SRC, 0);
28 nfct_set_attr_u16(expected, ATTR_PORT_DST, htons(10241));
29
30 exp = nfexp_new();
31 if (!exp) {
32 perror("nfexp_new");
33 nfct_destroy(expected);
34 exit(EXIT_FAILURE);
35 }
36
37 nfexp_set_attr(exp, ATTR_EXP_EXPECTED, expected);
38
39 h = nfct_open(EXPECT, 0);
40 if (!h) {
41 perror("nfct_open");
42 nfct_destroy(expected);
43 return -1;
44 }
45
46 ret = nfexp_query(h, NFCT_Q_DESTROY, exp);
47
48 printf("TEST: delete expectation ");
49 if (ret == -1)
50 printf("(%d)(%s)\n", ret, strerror(errno));
51 else
52 printf("(OK)\n");
53
54 nfct_close(h);
55
56 nfct_destroy(expected);
57
58 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
59 }
60