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 nfct_setobjopt(ct, NFCT_SOPT_SETUP_REPLY);
31
32 nfct_set_attr_u8(ct, ATTR_TCP_STATE, TCP_CONNTRACK_SYN_SENT);
33 nfct_set_attr_u32(ct, ATTR_TIMEOUT, 100);
34
35 nfct_set_attr_u32(ct, ATTR_SNAT_IPV4, inet_addr("8.8.8.8"));
36
37 h = nfct_open(CONNTRACK, 0);
38 if (!h) {
39 perror("nfct_open");
40 nfct_destroy(ct);
41 return -1;
42 }
43
44 ret = nfct_query(h, NFCT_Q_CREATE, ct);
45
46 printf("TEST: create conntrack ");
47 if (ret == -1)
48 printf("(%d)(%s)\n", ret, strerror(errno));
49 else
50 printf("(OK)\n");
51
52 nfct_close(h);
53
54 nfct_destroy(ct);
55
56 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
57 }
58