2014-05-15 21:27:51 +00:00
|
|
|
/* $Id: testpfpinhole.c,v 1.12 2014/05/15 21:23:43 nanard Exp $ */
|
2012-04-18 20:53:51 +00:00
|
|
|
/* MiniUPnP project
|
|
|
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
2014-02-28 19:20:51 +00:00
|
|
|
* (c) 2012-2014 Thomas Bernard
|
2012-04-18 20:53:51 +00:00
|
|
|
* This software is subject to the conditions detailed
|
|
|
|
* in the LICENCE file provided within the distribution */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
2012-04-20 14:49:04 +00:00
|
|
|
#include "../config.h"
|
2012-04-18 20:53:51 +00:00
|
|
|
#include "obsdrdr.h"
|
|
|
|
#include "pfpinhole.h"
|
|
|
|
|
|
|
|
int runtime_flags = 0;
|
|
|
|
const char * tag = NULL;
|
|
|
|
|
|
|
|
const char * anchor_name = "miniupnpd";
|
|
|
|
const char * queue = NULL;
|
|
|
|
|
2014-02-28 19:20:51 +00:00
|
|
|
#ifdef ENABLE_IPV6
|
2012-04-20 22:08:06 +00:00
|
|
|
static int print_pinhole(int uid)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
char rem_host[64];
|
|
|
|
unsigned short rem_port;
|
|
|
|
char int_client[64];
|
|
|
|
unsigned short int_port;
|
|
|
|
int proto;
|
|
|
|
unsigned int timestamp;
|
2012-04-22 23:47:37 +00:00
|
|
|
u_int64_t packets, bytes;
|
2014-05-15 21:27:51 +00:00
|
|
|
char desc[64];
|
2012-04-20 22:08:06 +00:00
|
|
|
|
2014-02-28 19:20:51 +00:00
|
|
|
r = get_pinhole_info((unsigned short)uid,
|
|
|
|
rem_host, sizeof(rem_host), &rem_port,
|
|
|
|
int_client, sizeof(int_client), &int_port,
|
2014-05-15 21:27:51 +00:00
|
|
|
&proto,
|
|
|
|
desc, sizeof(desc),
|
|
|
|
×tamp,
|
2014-02-28 19:20:51 +00:00
|
|
|
&packets, &bytes);
|
2012-04-20 22:08:06 +00:00
|
|
|
if(r < 0) {
|
|
|
|
fprintf(stderr, "get_pinhole(%d) returned %d\n", uid, r);
|
|
|
|
} else {
|
|
|
|
printf("pinhole %d : [%s]:%hu => [%s]:%hu proto=%d ts=%u\n",
|
|
|
|
uid, rem_host, rem_port, int_client, int_port,
|
|
|
|
proto, timestamp);
|
2014-05-15 21:27:51 +00:00
|
|
|
printf(" desc='%s'\n", desc);
|
2012-04-22 23:47:37 +00:00
|
|
|
printf(" packets=%llu bytes=%llu\n", packets, bytes);
|
2012-04-20 22:08:06 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2014-02-28 19:20:51 +00:00
|
|
|
#endif
|
2012-04-20 22:08:06 +00:00
|
|
|
|
2012-04-18 20:53:51 +00:00
|
|
|
int main(int argc, char * *argv)
|
|
|
|
{
|
2012-04-20 14:49:04 +00:00
|
|
|
#ifndef ENABLE_IPV6
|
|
|
|
fprintf(stderr,"nothing to test, ENABLE_IPV6 is not defined in config.h\n");
|
|
|
|
return 1;
|
|
|
|
#else
|
2012-04-19 22:07:13 +00:00
|
|
|
int uid;
|
2012-04-18 20:53:51 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
openlog("testpfpinhole", LOG_PERROR, LOG_USER);
|
|
|
|
if(init_redirect() < 0) {
|
|
|
|
fprintf(stderr, "init_redirect() failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-05-15 21:27:51 +00:00
|
|
|
uid = add_pinhole("ep0", "2001::1:2:3", 12345, "123::ff", 54321, IPPROTO_UDP, "description test 1", 424242);
|
2012-04-19 22:07:13 +00:00
|
|
|
if(uid < 0) {
|
|
|
|
fprintf(stderr, "add_pinhole() failed\n");
|
|
|
|
}
|
|
|
|
printf("add_pinhole() returned %d\n", uid);
|
2014-05-15 21:27:51 +00:00
|
|
|
uid = add_pinhole("ep0", NULL, 0, "dead:beef::42:42", 8080, IPPROTO_UDP, "description test 2", 4321000);
|
2012-04-19 22:07:13 +00:00
|
|
|
if(uid < 0) {
|
|
|
|
fprintf(stderr, "add_pinhole() failed\n");
|
|
|
|
}
|
|
|
|
printf("add_pinhole() returned %d\n", uid);
|
|
|
|
|
2012-04-20 22:08:06 +00:00
|
|
|
print_pinhole(1);
|
|
|
|
print_pinhole(2);
|
2012-04-22 00:58:27 +00:00
|
|
|
clean_pinhole_list(NULL);
|
2012-04-20 22:08:06 +00:00
|
|
|
|
2012-04-19 22:07:13 +00:00
|
|
|
ret = delete_pinhole(1);
|
|
|
|
printf("delete_pinhole() returned %d\n", ret);
|
|
|
|
ret = delete_pinhole(2);
|
|
|
|
printf("delete_pinhole() returned %d\n", ret);
|
2012-04-20 14:49:04 +00:00
|
|
|
#endif
|
2012-04-18 20:53:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|