Annotation of embedaddon/miniupnpd/pf/testpfpinhole.c, revision 1.1.1.1
1.1 misho 1: /* $Id: testpfpinhole.c,v 1.10 2012/04/22 23:12:51 nanard Exp $ */
2: /* MiniUPnP project
3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4: * (c) 2012 Thomas Bernard
5: * This software is subject to the conditions detailed
6: * in the LICENCE file provided within the distribution */
7:
8: #include <stdio.h>
9: #include <stdlib.h>
10: #include <sys/types.h>
11: #include <netinet/in.h>
12: #include <syslog.h>
13:
14: #include "../config.h"
15: #include "obsdrdr.h"
16: #include "pfpinhole.h"
17:
18: int runtime_flags = 0;
19: const char * tag = NULL;
20:
21: const char * anchor_name = "miniupnpd";
22: const char * queue = NULL;
23:
24: static int print_pinhole(int uid)
25: {
26: int r;
27: char rem_host[64];
28: unsigned short rem_port;
29: char int_client[64];
30: unsigned short int_port;
31: int proto;
32: unsigned int timestamp;
33: u_int64_t packets, bytes;
34:
35: r = get_pinhole((unsigned short)uid,
36: rem_host, sizeof(rem_host), &rem_port,
37: int_client, sizeof(int_client), &int_port,
38: &proto, ×tamp,
39: &packets, &bytes);
40: if(r < 0) {
41: fprintf(stderr, "get_pinhole(%d) returned %d\n", uid, r);
42: } else {
43: printf("pinhole %d : [%s]:%hu => [%s]:%hu proto=%d ts=%u\n",
44: uid, rem_host, rem_port, int_client, int_port,
45: proto, timestamp);
46: printf(" packets=%llu bytes=%llu\n", packets, bytes);
47: }
48: return r;
49: }
50:
51: int main(int argc, char * *argv)
52: {
53: #ifndef ENABLE_IPV6
54: fprintf(stderr,"nothing to test, ENABLE_IPV6 is not defined in config.h\n");
55: return 1;
56: #else
57: int uid;
58: int ret;
59:
60: openlog("testpfpinhole", LOG_PERROR, LOG_USER);
61: if(init_redirect() < 0) {
62: fprintf(stderr, "init_redirect() failed\n");
63: return 1;
64: }
65:
66: uid = add_pinhole("ep0", "2001::1:2:3", 12345, "123::ff", 54321, IPPROTO_UDP, 424242);
67: if(uid < 0) {
68: fprintf(stderr, "add_pinhole() failed\n");
69: }
70: printf("add_pinhole() returned %d\n", uid);
71: uid = add_pinhole("ep0", NULL, 0, "dead:beef::42:42", 8080, IPPROTO_UDP, 4321000);
72: if(uid < 0) {
73: fprintf(stderr, "add_pinhole() failed\n");
74: }
75: printf("add_pinhole() returned %d\n", uid);
76:
77: print_pinhole(1);
78: print_pinhole(2);
79: clean_pinhole_list(NULL);
80:
81: ret = delete_pinhole(1);
82: printf("delete_pinhole() returned %d\n", ret);
83: ret = delete_pinhole(2);
84: printf("delete_pinhole() returned %d\n", ret);
85: #endif
86: return 0;
87: }
88:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>