Ignore:
Timestamp:
Dec 18, 2008, 5:55:22 AM (13 years ago)
Author:
jhujhiti
Message:

(trunk libT) Refactor ipv6 bind socket check

This will let the RPC server use the same test mechanism eventually. Networking code belongs in net.c anyway.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r7417 r7436  
    156156}
    157157
     158tr_net_af_support
     159tr_net_getAFSupport( tr_port port )
     160{
     161    /* Do we care if an address is in use? Probably not, since it will be
     162     * caught later. This will only set up the list of sockets to bind. */
     163    static tr_bool alreadyDone       = FALSE;
     164    static tr_net_af_support support = { FALSE, FALSE };
     165    int s4, s6;
     166    if( alreadyDone )
     167        return support;
     168    s6 = tr_netBindTCP( &tr_in6addr_any, port, TRUE );
     169    if( s6 >= 0 || -s6 != EAFNOSUPPORT ) /* we support ipv6 */
     170    {
     171        listen( s6, 1 );
     172        support.has_inet6 = TRUE;
     173    }
     174    s4 = tr_netBindTCP( &tr_inaddr_any, port, TRUE );
     175    if( s4 >= 0 ) /* we bound *with* the ipv6 socket bound (need both)
     176                   * or only have ipv4 */
     177    {
     178        tr_netClose( s4 );
     179        support.needs_inet4 = TRUE;
     180    }
     181    if( s6 >= 0 )
     182        tr_netClose( s6 );
     183    alreadyDone = TRUE;
     184    return support;
     185}
     186
    158187/***********************************************************************
    159188 * Socket list housekeeping
Note: See TracChangeset for help on using the changeset viewer.