Changeset b0a33a5 for irc.c


Ignore:
Timestamp:
2006-07-11T09:28:44Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
6398094
Parents:
a93e3c8
Message:

Better handling of situations where IPv6 is not available at run-time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    ra93e3c8 rb0a33a5  
    4646        char buf[128];
    4747#ifdef IPV6
    48         struct sockaddr_in6 sock[1];
    49 #else
     48        struct sockaddr_in6 sock6[1];
     49        unsigned int i6;
     50#endif
    5051        struct sockaddr_in sock[1];
    51 #endif
    5252       
    5353        irc = g_new0( irc_t, 1 );
     
    6969       
    7070        i = sizeof( *sock );
     71#ifdef IPV6
     72        i6 = sizeof( *sock6 );
     73#endif
    7174       
    7275        if( global.conf->hostname )
    7376                irc->myhost = g_strdup( global.conf->hostname );
    7477#ifdef IPV6
    75         else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
    76         {
    77                 if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
     78        else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 )
     79        {
     80                if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
    7881                        irc->myhost = g_strdup( peer->h_name );
    79                 else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     82                else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
    8083                        irc->myhost = g_strdup( ipv6_unwrap( buf ) );
    8184        }
    82 #else
    83         else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
    84         {
    85                 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
     85#endif
     86        else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
     87        {
     88                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
    8689                        irc->myhost = g_strdup( peer->h_name );
    87                 else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     90                else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
    8891                        irc->myhost = g_strdup( buf );
    8992        }
    90 #endif
    9193       
    9294        i = sizeof( *sock );
    9395#ifdef IPV6
    94         if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
    95         {
    96                 if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
     96        i6 = sizeof( *sock6 );
     97        if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 )
     98        {
     99                if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
    97100                        irc->host = g_strdup( peer->h_name );
    98                 else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     101                else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
    99102                        irc->host = g_strdup( ipv6_unwrap( buf ) );
    100103        }
    101 #else
    102         if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
    103         {
    104                 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
     104        else
     105#endif
     106        if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
     107        {
     108                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
    105109                        irc->host = g_strdup( peer->h_name );
    106                 else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     110                else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
    107111                        irc->host = g_strdup( buf );
    108112        }
    109 #endif
    110113       
    111114        /* Rare, but possible. */
Note: See TracChangeset for help on using the changeset viewer.