miniupnpc-libevent: add upnpc_delete_port_mapping()
This commit is contained in:
parent
8d5a9d72da
commit
3bf2398903
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: miniupnpc-libevent.c,v 1.8 2014/11/13 09:15:23 nanard Exp $ */
|
/* $Id: miniupnpc-libevent.c,v 1.10 2014/11/14 11:37:45 nanard Exp $ */
|
||||||
/* miniupnpc-libevent
|
/* miniupnpc-libevent
|
||||||
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
|
@ -632,6 +632,28 @@ int upnpc_get_link_layer_max_rate(upnpc_t * p)
|
||||||
"GetCommonLinkProperties", NULL, 0);
|
"GetCommonLinkProperties", NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int upnpc_delete_port_mapping(upnpc_t * p,
|
||||||
|
const char * remote_host, unsigned short ext_port,
|
||||||
|
const char * proto)
|
||||||
|
{
|
||||||
|
struct upnp_args args[3];
|
||||||
|
char ext_port_str[8];
|
||||||
|
|
||||||
|
if(proto == NULL || ext_port == 0)
|
||||||
|
return UPNPC_ERR_INVALID_ARGS;
|
||||||
|
snprintf(ext_port_str, sizeof(ext_port_str), "%hu", ext_port);
|
||||||
|
args[0].elt = "NewRemoteHost";
|
||||||
|
args[0].val = remote_host?remote_host:"";
|
||||||
|
args[1].elt = "NewExternalPort";
|
||||||
|
args[1].val = ext_port_str;
|
||||||
|
args[2].elt = "NewProtocol";
|
||||||
|
args[2].val = proto;
|
||||||
|
return upnpc_send_soap_request(p, p->control_conn_url,
|
||||||
|
"urn:schemas-upnp-org:service:WANIPConnection:1",
|
||||||
|
"DeletePortMapping",
|
||||||
|
args, 3);
|
||||||
|
}
|
||||||
|
|
||||||
int upnpc_add_port_mapping(upnpc_t * p,
|
int upnpc_add_port_mapping(upnpc_t * p,
|
||||||
const char * remote_host, unsigned short ext_port,
|
const char * remote_host, unsigned short ext_port,
|
||||||
unsigned short int_port, const char * int_client,
|
unsigned short int_port, const char * int_client,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: miniupnpc-libevent.h,v 1.3 2014/11/12 14:10:52 nanard Exp $ */
|
/* $Id: miniupnpc-libevent.h,v 1.5 2014/11/14 10:55:37 nanard Exp $ */
|
||||||
/* miniupnpc-libevent
|
/* miniupnpc-libevent
|
||||||
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
|
@ -65,6 +65,10 @@ int upnpc_add_port_mapping(upnpc_t * p,
|
||||||
const char * proto, const char * description,
|
const char * proto, const char * description,
|
||||||
unsigned int lease_duration);
|
unsigned int lease_duration);
|
||||||
|
|
||||||
|
int upnpc_delete_port_mapping(upnpc_t * p,
|
||||||
|
const char * remote_host, unsigned short ext_port,
|
||||||
|
const char * proto);
|
||||||
|
|
||||||
#ifdef UPNPC_USE_SELECT
|
#ifdef UPNPC_USE_SELECT
|
||||||
int upnpc_select_fds(upnpc_t * p, int * nfds, fd_set * readfds, fd_set * writefds);
|
int upnpc_select_fds(upnpc_t * p, int * nfds, fd_set * readfds, fd_set * writefds);
|
||||||
#endif /* UPNPC_USE_SELECT */
|
#endif /* UPNPC_USE_SELECT */
|
||||||
|
|
|
@ -39,7 +39,13 @@ static void ready(int code, void * data)
|
||||||
upnpc_get_external_ip_address(p);
|
upnpc_get_external_ip_address(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum { EGetExtIp = 0, EGetMaxRate, EAddPortMapping, EFinished } state = EGetExtIp;
|
static enum {
|
||||||
|
EGetExtIp = 0,
|
||||||
|
EGetMaxRate,
|
||||||
|
EAddPortMapping,
|
||||||
|
EDeletePortMapping,
|
||||||
|
EFinished
|
||||||
|
} state = EGetExtIp;
|
||||||
|
|
||||||
/* soap callback */
|
/* soap callback */
|
||||||
static void soap(int code, void * data)
|
static void soap(int code, void * data)
|
||||||
|
@ -60,6 +66,11 @@ static void soap(int code, void * data)
|
||||||
state = EAddPortMapping;
|
state = EAddPortMapping;
|
||||||
break;
|
break;
|
||||||
case EAddPortMapping:
|
case EAddPortMapping:
|
||||||
|
printf("OK!\n");
|
||||||
|
upnpc_delete_port_mapping(p, NULL, 60001, "TCP");
|
||||||
|
state = EDeletePortMapping;
|
||||||
|
break;
|
||||||
|
case EDeletePortMapping:
|
||||||
printf("OK!\n");
|
printf("OK!\n");
|
||||||
state = EFinished;
|
state = EFinished;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue