libnetfilter_conntrack 1.0.9
expect_delete.c
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
9int main(void)
10{
11 int ret;
12 struct nfct_handle *h;
13 struct nf_conntrack *expected;
14 struct nf_expect *exp;
15
16 expected = nfct_new();
17 if (!expected) {
18 perror("nfct_new");
19 exit(EXIT_FAILURE);
20 }
21
22 nfct_set_attr_u8(expected, ATTR_L3PROTO, AF_INET);
23 nfct_set_attr_u32(expected, ATTR_IPV4_SRC, inet_addr("1.1.1.1"));
24 nfct_set_attr_u32(expected, ATTR_IPV4_DST, inet_addr("2.2.2.2"));
25
26 nfct_set_attr_u8(expected, ATTR_L4PROTO, IPPROTO_TCP);
27 nfct_set_attr_u16(expected, ATTR_PORT_SRC, 0);
28 nfct_set_attr_u16(expected, ATTR_PORT_DST, htons(10241));
29
30 exp = nfexp_new();
31 if (!exp) {
32 perror("nfexp_new");
33 nfct_destroy(expected);
34 exit(EXIT_FAILURE);
35 }
36
37 nfexp_set_attr(exp, ATTR_EXP_EXPECTED, expected);
38
39 h = nfct_open(EXPECT, 0);
40 if (!h) {
41 perror("nfct_open");
42 nfct_destroy(expected);
43 return -1;
44 }
45
46 ret = nfexp_query(h, NFCT_Q_DESTROY, exp);
47
48 printf("TEST: delete expectation ");
49 if (ret == -1)
50 printf("(%d)(%s)\n", ret, strerror(errno));
51 else
52 printf("(OK)\n");
53
54 nfct_close(h);
55
56 nfct_destroy(expected);
57
58 ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
59}
struct nfct_handle * nfct_open(uint8_t, unsigned)
Definition main.c:84
int nfct_close(struct nfct_handle *cth)
Definition main.c:105
int nfexp_query(struct nfct_handle *h, const enum nf_conntrack_query qt, const void *data)
Definition expect/api.c:695
void nfct_set_attr_u32(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint32_t value)
void nfct_destroy(struct nf_conntrack *ct)
void nfct_set_attr_u16(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint16_t value)
void nfct_set_attr_u8(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint8_t value)
struct nf_conntrack * nfct_new(void)
struct nf_expect * nfexp_new(void)
Definition expect/api.c:29
void nfexp_set_attr(struct nf_expect *exp, const enum nf_expect_attr type, const void *value)
Definition expect/api.c:309