mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
(trunk libT) #2191 "NAT-PMP and UPnP should also map UDP port" -- committed patch by starix.
This commit is contained in:
parent
f74e3b5b3a
commit
b2d0b673c2
1 changed files with 29 additions and 15 deletions
|
@ -141,13 +141,12 @@ tr_upnpPulse( tr_upnp * handle,
|
||||||
char portStr[8];
|
char portStr[8];
|
||||||
char intPort[8];
|
char intPort[8];
|
||||||
char intClient[16];
|
char intClient[16];
|
||||||
int i;
|
|
||||||
|
|
||||||
tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
|
tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
|
||||||
i = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL,
|
if( UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
|
||||||
handle->data.first.servicetype, portStr,
|
portStr, "TCP", intClient, intPort ) != UPNPCOMMAND_SUCCESS ||
|
||||||
"TCP", intClient, intPort );
|
UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
|
||||||
if( i != UPNPCOMMAND_SUCCESS )
|
portStr, "UDP", intClient, intPort ) != UPNPCOMMAND_SUCCESS )
|
||||||
{
|
{
|
||||||
tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
|
tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
|
||||||
handle->isMapped = FALSE;
|
handle->isMapped = FALSE;
|
||||||
|
@ -161,6 +160,9 @@ tr_upnpPulse( tr_upnp * handle,
|
||||||
UPNP_DeletePortMapping( handle->urls.controlURL,
|
UPNP_DeletePortMapping( handle->urls.controlURL,
|
||||||
handle->data.first.servicetype,
|
handle->data.first.servicetype,
|
||||||
portStr, "TCP", NULL );
|
portStr, "TCP", NULL );
|
||||||
|
UPNP_DeletePortMapping( handle->urls.controlURL,
|
||||||
|
handle->data.first.servicetype,
|
||||||
|
portStr, "UDP", NULL );
|
||||||
tr_ninf( getKey( ),
|
tr_ninf( getKey( ),
|
||||||
_(
|
_(
|
||||||
"Stopping port forwarding through \"%s\", service \"%s\"" ),
|
"Stopping port forwarding through \"%s\", service \"%s\"" ),
|
||||||
|
@ -178,7 +180,8 @@ tr_upnpPulse( tr_upnp * handle,
|
||||||
|
|
||||||
if( handle->state == TR_UPNP_MAP )
|
if( handle->state == TR_UPNP_MAP )
|
||||||
{
|
{
|
||||||
int err = -1;
|
int err_tcp = -1;
|
||||||
|
int err_udp = -1;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if( !handle->urls.controlURL || !handle->data.first.servicetype )
|
if( !handle->urls.controlURL || !handle->data.first.servicetype )
|
||||||
|
@ -187,13 +190,30 @@ tr_upnpPulse( tr_upnp * handle,
|
||||||
{
|
{
|
||||||
char portStr[16];
|
char portStr[16];
|
||||||
char desc[64];
|
char desc[64];
|
||||||
|
const int prev_errno = errno;
|
||||||
tr_snprintf( portStr, sizeof( portStr ), "%d", port );
|
tr_snprintf( portStr, sizeof( portStr ), "%d", port );
|
||||||
tr_snprintf( desc, sizeof( desc ), "%s at %d", TR_NAME, port );
|
tr_snprintf( desc, sizeof( desc ), "%s at %d", TR_NAME, port );
|
||||||
err = UPNP_AddPortMapping( handle->urls.controlURL,
|
|
||||||
|
errno = 0;
|
||||||
|
err_tcp = UPNP_AddPortMapping( handle->urls.controlURL,
|
||||||
handle->data.first.servicetype,
|
handle->data.first.servicetype,
|
||||||
portStr, portStr, handle->lanaddr,
|
portStr, portStr, handle->lanaddr,
|
||||||
desc, "TCP", NULL );
|
desc, "TCP", NULL );
|
||||||
handle->isMapped = !err;
|
if( err_tcp )
|
||||||
|
tr_ndbg( getKey( ), "TCP Port forwarding failed with error %d (errno %d - %s)",
|
||||||
|
err_tcp, errno, tr_strerror( errno ) );
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
err_udp = UPNP_AddPortMapping( handle->urls.controlURL,
|
||||||
|
handle->data.first.servicetype,
|
||||||
|
portStr, portStr, handle->lanaddr,
|
||||||
|
desc, "UDP", NULL );
|
||||||
|
if( err_udp )
|
||||||
|
tr_ndbg( getKey( ), "UDP Port forwarding failed with error %d (errno %d - %s)",
|
||||||
|
err_udp, errno, tr_strerror( errno ) );
|
||||||
|
|
||||||
|
errno = prev_errno;
|
||||||
|
handle->isMapped = !err_tcp | !err_udp;
|
||||||
}
|
}
|
||||||
tr_ninf( getKey( ),
|
tr_ninf( getKey( ),
|
||||||
_( "Port forwarding through \"%s\", service \"%s\". (local address: %s:%d)" ),
|
_( "Port forwarding through \"%s\", service \"%s\". (local address: %s:%d)" ),
|
||||||
|
@ -207,13 +227,7 @@ tr_upnpPulse( tr_upnp * handle,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tr_ndbg(
|
tr_ndbg( getKey( ), "If your router supports UPnP, please make sure UPnP is enabled!" );
|
||||||
getKey( ),
|
|
||||||
"Port forwarding failed with error %d (errno %d - %s)", err,
|
|
||||||
errno, tr_strerror( errno ) );
|
|
||||||
tr_ndbg(
|
|
||||||
getKey( ),
|
|
||||||
"If your router supports UPnP, please make sure UPnP is enabled!" );
|
|
||||||
handle->port = -1;
|
handle->port = -1;
|
||||||
handle->state = TR_UPNP_ERR;
|
handle->state = TR_UPNP_ERR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue