| 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 |
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 |
h = nfct_open(CONNTRACK, 0); |
| 36 |
if (!h) { |
| 37 |
perror("nfct_open"); |
| 38 |
nfct_destroy(ct); |
| 39 |
return -1; |
| 40 |
} |
| 41 |
|
| 42 |
ret = nfct_query(h, NFCT_Q_CREATE, ct); |
| 43 |
|
| 44 |
printf("TEST: create conntrack "); |
| 45 |
if (ret == -1) |
| 46 |
printf("(%d)(%s)\n", ret, strerror(errno)); |
| 47 |
else |
| 48 |
printf("(OK)\n"); |
| 49 |
|
| 50 |
nfct_close(h); |
| 51 |
|
| 52 |
nfct_destroy(ct); |
| 53 |
|
| 54 |
ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS); |
| 55 |
} |