| 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 |
|
| 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 |
struct nfct_attr_grp_ipv4 grp_ipv4 = { |
| 23 |
.src = inet_addr("1.1.1.1"), |
| 24 |
.dst = inet_addr("2.2.2.2") |
| 25 |
}; |
| 26 |
nfct_set_attr_grp(ct, ATTR_GRP_ORIG_IPV4, &grp_ipv4); |
| 27 |
|
| 28 |
struct nfct_attr_grp_port grp_port = { |
| 29 |
.sport = htons(20), |
| 30 |
.dport = htons(10) |
| 31 |
}; |
| 32 |
nfct_set_attr_grp(ct, ATTR_GRP_ORIG_PORT, &grp_port); |
| 33 |
nfct_set_attr_u8(ct, ATTR_L4PROTO, IPPROTO_TCP); |
| 34 |
|
| 35 |
nfct_setobjopt(ct, NFCT_SOPT_SETUP_REPLY); |
| 36 |
|
| 37 |
nfct_set_attr_u8(ct, ATTR_TCP_STATE, TCP_CONNTRACK_SYN_SENT); |
| 38 |
nfct_set_attr_u32(ct, ATTR_TIMEOUT, 100); |
| 39 |
nfct_set_attr(ct, ATTR_HELPER_NAME, "ftp"); |
| 40 |
|
| 41 |
h = nfct_open(CONNTRACK, 0); |
| 42 |
if (!h) { |
| 43 |
perror("nfct_open"); |
| 44 |
nfct_destroy(ct); |
| 45 |
return -1; |
| 46 |
} |
| 47 |
|
| 48 |
ret = nfct_query(h, NFCT_Q_CREATE, ct); |
| 49 |
|
| 50 |
printf("TEST: create conntrack "); |
| 51 |
if (ret == -1) |
| 52 |
printf("(%d)(%s)\n", ret, strerror(errno)); |
| 53 |
else |
| 54 |
printf("(OK)\n"); |
| 55 |
|
| 56 |
nfct_close(h); |
| 57 |
|
| 58 |
nfct_destroy(ct); |
| 59 |
|
| 60 |
ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS); |
| 61 |
} |