Ignore:
Timestamp:
Dec 2, 2008, 3:41:58 AM (13 years ago)
Author:
charles
Message:

(libT) re-apply jhujhiti's IPv6 patch. This merges in my tr_port cleanup, so any new bugs are mine :/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r7224 r7231  
    472472
    473473int
    474 tr_fdSocketAccept( int               b,
    475                    struct in_addr  * addr,
    476                    tr_port         * port )
     474tr_fdSocketAccept( int           b,
     475                   tr_address  * addr,
     476                   tr_port     * port )
    477477{
    478478    int                s = -1;
    479479    unsigned int       len;
    480     struct sockaddr_in sock;
     480    struct sockaddr_storage sock;
    481481
    482482    assert( addr );
     
    486486    if( gFd->socketCount < getSocketMax( gFd ) )
    487487    {
    488         len = sizeof( sock );
     488        len = sizeof( struct sockaddr );
    489489        s = accept( b, (struct sockaddr *) &sock, &len );
    490490    }
    491491    if( s > -1 )
    492492    {
    493         *addr = sock.sin_addr;
    494         *port = sock.sin_port;
     493        /* "The ss_family field of the sockaddr_storage structure will always
     494         * align with the family field of any protocol-specific structure." */
     495        if( sock.ss_family == AF_INET )
     496        {
     497            struct sockaddr_in * sock4 = (struct sockaddr_in *)&sock;
     498            addr->type = TR_AF_INET;
     499            addr->addr.addr4.s_addr = sock4->sin_addr.s_addr;
     500            *port = sock4->sin_port;
     501        }
     502        else
     503        {
     504            struct sockaddr_in6 * sock6 = (struct sockaddr_in6 *)&sock;
     505            addr->type = TR_AF_INET6;
     506            memcpy( &addr->addr, &sock6->sin6_addr,
     507                    sizeof( struct sockaddr_in6 ) );
     508            *port = sock6->sin6_port;
     509        }
    495510        ++gFd->socketCount;
    496511    }
Note: See TracChangeset for help on using the changeset viewer.