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 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
9
main(void)10 int main(void)
11 {
12 int ret;
13 struct nfct_handle *h;
14 struct nf_conntrack *ct;
15
16 ct = nfct_new();
17 if (!ct) {
18 perror("nfct_new");
19 return 0;
20 }
21
22 nfct_set_attr_u8(ct, ATTR_L3PROTO, AF_INET);
23 nfct_set_attr_u32(ct, ATTR_IPV4_SRC, inet_addr("1.1.1.1"));
24 nfct_set_attr_u32(ct, ATTR_IPV4_DST, inet_addr("2.2.2.2"));
25
26 nfct_set_attr_u8(ct, ATTR_L4PROTO, IPPROTO_TCP);
27 nfct_set_attr_u16(ct, ATTR_PORT_SRC, htons(20));
28 nfct_set_attr_u16(ct, ATTR_PORT_DST, htons(10));
29
30 h = nfct_open(CONNTRACK, 0);
31 if (!h) {
32 perror("nfct_open");
33 nfct_destroy(ct);
34 return -1;
35 }
36
37 ret = nfct_query(h, NFCT_Q_DESTROY, ct);
38
39 printf("TEST: delete conntrack ");
40 if (ret == -1)
41 printf("(%d)(%s)\n", ret, strerror(errno));
42 else
43 printf("(OK)\n");
44
45 nfct_close(h);
46
47 nfct_destroy(ct);
48
49 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
50 }
51