Ignore:
Timestamp:
Dec 8, 2007, 7:34:15 PM (14 years ago)
Author:
charles
Message:

Use libnatpmp for port mapping. rewrite the upnp/natpmp manager.

NOTE: this will break the xpjets build until SoftwareElves? or a volunteer patches the xcode project file to make a libnatpmp library just like was done for libminiupnp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r4029 r4092  
    146146}
    147147
    148 int
    149 tr_netOpenUDP( const struct in_addr * addr, tr_port_t port, int priority )
    150 {
    151     return tr_netOpen( addr, port, SOCK_DGRAM, priority );
    152 }
    153 
    154 #ifdef IP_ADD_MEMBERSHIP
    155 int tr_netMcastOpen( int port, const struct in_addr * addr )
    156 {
    157     int fd;
    158     struct ip_mreq req;
    159 
    160     fd = tr_netBindUDP( port );
    161     if( 0 > fd )
    162     {
    163         return -1;
    164     }
    165 
    166     memset( &req, 0, sizeof( req ) );
    167     req.imr_multiaddr.s_addr = addr->s_addr;
    168     req.imr_interface.s_addr = htonl( INADDR_ANY );
    169     if( setsockopt( fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&req, sizeof ( req ) ) )
    170     {
    171         tr_err( "Couldn't join multicast group (%s)", strerror( sockerrno ) );
    172         tr_netClose( fd );
    173         return -1;
    174     }
    175 
    176     return fd;
    177 }
    178 #else /* IP_ADD_MEMBERSHIP */
    179 int tr_netMcastOpen( int port UNUSED, const struct in_addr * addr UNUSED )
    180 {
    181     return -1;
    182 }
    183 #endif /* IP_ADD_MEMBERSHIP */
    184 
    185148static int
    186149tr_netBind( int port, int type )
     
    202165#endif
    203166
    204 #ifdef SO_REUSEPORT
    205     if( SOCK_DGRAM == type )
    206     {
    207         optval = 1;
    208         setsockopt( s, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof( optval ) );
    209     }
    210 #endif
    211 
    212167    memset( &sock, 0, sizeof( sock ) );
    213168    sock.sin_family      = AF_INET;
    214 
    215     /* Leopard closes a SO_REUSEADDR + INADDR_ANY hole, so we can't
    216      * use INADDR_ANY when binding for nat-pmp. For details, refer to
    217      * http://www.uwsg.indiana.edu/hypermail/linux/kernel/9902.1/0828.html .
    218      * This can probably be done cleaner, but since we're only using SOCK_DGRAM
    219      * for nat-pmp, this quick fix should work. */
    220     if ( SOCK_DGRAM == type )
    221         sock.sin_addr.s_addr = inet_addr( PMP_MCAST_ADDR );
    222     else
    223         sock.sin_addr.s_addr = INADDR_ANY;
    224 
     169    sock.sin_addr.s_addr = INADDR_ANY;
    225170    sock.sin_port        = htons( port );
    226171
     
    241186    return tr_netBind( port, SOCK_STREAM );
    242187}
    243 
    244 int
    245 tr_netBindUDP( int port )
    246 {
    247     return tr_netBind( port, SOCK_DGRAM );
    248 }
    249 
    250188
    251189int
Note: See TracChangeset for help on using the changeset viewer.