Changeset 11680


Ignore:
Timestamp:
Jan 15, 2011, 5:06:11 PM (12 years ago)
Author:
jordan
Message:

(trunk libT) #2191 "NAT-PMP and UPnP should also map UDP port" -- committed patch by starix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/upnp.c

    r11599 r11680  
    142142        char intPort[8];
    143143        char intClient[16];
    144         int i;
    145144
    146145        tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
    147         i = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL,
    148                                               handle->data.first.servicetype, portStr,
    149                                               "TCP", intClient, intPort );
    150         if( i != UPNPCOMMAND_SUCCESS )
     146        if( UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
     147            portStr, "TCP", intClient, intPort ) != UPNPCOMMAND_SUCCESS  ||
     148            UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
     149            portStr, "UDP", intClient, intPort ) != UPNPCOMMAND_SUCCESS )
    151150        {
    152151            tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
     
    162161                                handle->data.first.servicetype,
    163162                                portStr, "TCP", NULL );
     163        UPNP_DeletePortMapping( handle->urls.controlURL,
     164                                handle->data.first.servicetype,
     165                                portStr, "UDP", NULL );
    164166        tr_ninf( getKey( ),
    165167                 _(
     
    179181    if( handle->state == TR_UPNP_MAP )
    180182    {
    181         int  err = -1;
     183        int  err_tcp = -1;
     184        int  err_udp = -1;
    182185        errno = 0;
    183186
     
    188191            char portStr[16];
    189192            char desc[64];
     193            const int prev_errno = errno;
    190194            tr_snprintf( portStr, sizeof( portStr ), "%d", port );
    191195            tr_snprintf( desc, sizeof( desc ), "%s at %d", TR_NAME, port );
    192             err = UPNP_AddPortMapping( handle->urls.controlURL,
     196
     197            errno = 0;
     198            err_tcp = UPNP_AddPortMapping( handle->urls.controlURL,
    193199                                       handle->data.first.servicetype,
    194200                                       portStr, portStr, handle->lanaddr,
    195201                                       desc, "TCP", NULL );
    196             handle->isMapped = !err;
     202            if( err_tcp )
     203                tr_ndbg( getKey( ), "TCP Port forwarding failed with error %d (errno %d - %s)",
     204                         err_tcp, errno, tr_strerror( errno ) );
     205
     206            errno = 0;
     207            err_udp = UPNP_AddPortMapping( handle->urls.controlURL,
     208                                       handle->data.first.servicetype,
     209                                       portStr, portStr, handle->lanaddr,
     210                                       desc, "UDP", NULL );
     211            if( err_udp )
     212                tr_ndbg( getKey( ), "UDP Port forwarding failed with error %d (errno %d - %s)",
     213                         err_udp, errno, tr_strerror( errno ) );
     214
     215            errno = prev_errno;
     216            handle->isMapped = !err_tcp | !err_udp;
    197217        }
    198218        tr_ninf( getKey( ),
     
    208228        else
    209229        {
    210             tr_ndbg(
    211                  getKey( ),
    212                 "Port forwarding failed with error %d (errno %d - %s)", err,
    213                 errno, tr_strerror( errno ) );
    214             tr_ndbg(
    215                 getKey( ),
    216                 "If your router supports UPnP, please make sure UPnP is enabled!" );
     230            tr_ndbg( getKey( ), "If your router supports UPnP, please make sure UPnP is enabled!" );
    217231            handle->port = -1;
    218232            handle->state = TR_UPNP_ERR;
Note: See TracChangeset for help on using the changeset viewer.