| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <string.h> |
| 4 |
#include <errno.h> |
| 5 |
|
| 6 |
#include <libnetfilter_conntrack/libnetfilter_conntrack.h> |
| 7 |
|
| 8 |
static int cb(enum nf_conntrack_msg_type type, |
| 9 |
struct nf_conntrack *ct, |
| 10 |
void *data) |
| 11 |
{ |
| 12 |
char buf[1024]; |
| 13 |
|
| 14 |
nfct_snprintf(buf, sizeof(buf), ct, NFCT_T_UNKNOWN, NFCT_O_DEFAULT, NFCT_OF_SHOW_LAYER3 | NFCT_OF_TIMESTAMP); |
| 15 |
printf("%s\n", buf); |
| 16 |
|
| 17 |
return NFCT_CB_CONTINUE; |
| 18 |
} |
| 19 |
|
| 20 |
int main(void) |
| 21 |
{ |
| 22 |
int ret; |
| 23 |
struct nfct_handle *h; |
| 24 |
|
| 25 |
h = nfct_open(CONNTRACK, 0); |
| 26 |
if (!h) { |
| 27 |
perror("nfct_open"); |
| 28 |
return -1; |
| 29 |
} |
| 30 |
struct nfct_filter_dump *filter_dump = nfct_filter_dump_create(); |
| 31 |
if (filter_dump == NULL) { |
| 32 |
perror("nfct_filter_dump_alloc"); |
| 33 |
return -1; |
| 34 |
} |
| 35 |
struct nfct_filter_dump_mark filter_dump_mark = { |
| 36 |
.val = 1, |
| 37 |
.mask = 0xffffffff, |
| 38 |
}; |
| 39 |
nfct_filter_dump_set_attr(filter_dump, NFCT_FILTER_DUMP_MARK, |
| 40 |
&filter_dump_mark); |
| 41 |
nfct_filter_dump_set_attr_u8(filter_dump, NFCT_FILTER_DUMP_L3NUM, |
| 42 |
AF_INET); |
| 43 |
nfct_filter_dump_set_attr_u16(filter_dump, NFCT_FILTER_DUMP_ZONE, |
| 44 |
123); |
| 45 |
|
| 46 |
nfct_callback_register(h, NFCT_T_ALL, cb, NULL); |
| 47 |
ret = nfct_query(h, NFCT_Q_DUMP_FILTER, filter_dump); |
| 48 |
|
| 49 |
nfct_filter_dump_destroy(filter_dump); |
| 50 |
|
| 51 |
printf("TEST: get conntrack "); |
| 52 |
if (ret == -1) |
| 53 |
printf("(%d)(%s)\n", ret, strerror(errno)); |
| 54 |
else |
| 55 |
printf("(OK)\n"); |
| 56 |
|
| 57 |
nfct_close(h); |
| 58 |
|
| 59 |
ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS); |
| 60 |
} |