Changeset 7413


Ignore:
Timestamp:
Dec 16, 2008, 9:06:47 PM (12 years ago)
Author:
charles
Message:

(trunk libT) more runtime safety checks

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r7410 r7413  
    6969}
    7070
     71tr_bool
     72tr_isAddress( const tr_address * a )
     73{
     74    return a && ( a->type==AF_INET || a->type==AF_INET6 );
     75}
    7176
    7277const char *
    7378tr_ntop( const tr_address * src, char * dst, int size )
    74 {
     79{
     80    assert( tr_isAddress( src ) );
     81
    7582    if( src->type == TR_AF_INET )
    7683        return inet_ntop( AF_INET, &src->addr, dst, size );
     
    114121tr_normalizeV4Mapped( tr_address * const addr )
    115122{
     123    assert( tr_isAddress( addr ) );
     124
    116125    if( addr->type == TR_AF_INET6 && IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 ) )
    117126    {
     
    133142    int addrlen;
    134143
    135     assert( a );
    136     assert( b );
    137     assert( a->type == TR_AF_INET || a->type == TR_AF_INET6 );
    138     assert( b->type == TR_AF_INET || b->type == TR_AF_INET6 );
     144    assert( tr_isAddress( a ) );
     145    assert( tr_isAddress( b ) );
    139146
    140147    /* IPv6 addresses are always "greater than" IPv4 */
     
    164171{
    165172    tr_socketList * tmp;
     173
    166174    assert( head );
     175    assert( tr_isAddress( addr ) );
     176
    167177    for( tmp = head; tmp->next; tmp = tmp->next );
    168178    tmp->next = tr_socketListNew( addr );
     
    174184{
    175185    tr_socketList * tmp;
     186
     187    assert( tr_isAddress( addr ) );
     188
    176189    tmp = tr_new( tr_socketList, 1 );
    177190    tmp->socket = -1;
     
    185198{
    186199    assert( head );
     200
    187201    if( head->next )
    188202        tr_socketListFree( head->next );
     
    195209{
    196210    tr_socketList * tmp;
     211
    197212    assert( head );
    198213    assert( el );
     214
    199215    for( tmp = head; tmp->next && tmp->next != el; tmp = tmp->next );
    200216    tmp->next = el->next;
     
    208224{
    209225    tr_socketList * tmp;
     226
    210227    assert( head );
    211228    assert( start );
     229
    212230    for( tmp = head; tmp->next && tmp->next != start; tmp = tmp->next );
    213231    tr_socketListFree( start );
     
    215233}
    216234
     235#if 0
    217236int
    218237tr_socketListGetSocket( const tr_socketList * const el )
    219238{
    220239    assert( el );
     240
    221241    return el->socket;
    222242}
     
    228248    return &el->addr;
    229249}
     250#endif
    230251
    231252void
     
    246267
    247268int
    248 tr_netSetTOS( int s,
    249               int tos )
     269tr_netSetTOS( int s, int tos )
    250270{
    251271#ifdef IP_TOS
     
    302322    struct sockaddr_in  sock4;
    303323    struct sockaddr_in6 sock6;
     324
     325    assert( tr_isAddress( addr ) );
     326
    304327    if( addr->type == TR_AF_INET )
    305328    {
     
    333356    socklen_t               addrlen;
    334357
     358    assert( tr_isAddress( addr ) );
     359
    335360    if( ( s = createSocket( ( addr->type == TR_AF_INET ? AF_INET : AF_INET6 ),
    336361                            type ) ) < 0 )
     
    369394    const int               type = SOCK_STREAM;
    370395    int                     addrlen;
     396
     397    assert( tr_isAddress( addr ) );
    371398
    372399#if defined( SO_REUSEADDR ) || defined( SO_REUSEPORT )
     
    408435              tr_port     * port )
    409436{
    410     int fd = makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
     437    int fd;
     438
     439    assert( tr_isAddress( addr ) );
     440
     441    fd = makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
    411442    setSndBuf( session, fd );
    412443    return fd;
  • trunk/libtransmission/net.h

    r7397 r7413  
    8282void tr_normalizeV4Mapped( tr_address * const addr );
    8383
     84tr_bool tr_isAddress( const tr_address * a );
     85
    8486/***********************************************************************
    8587 * Socket list housekeeping
Note: See TracChangeset for help on using the changeset viewer.