Changeset e4d6271 for irc.c


Ignore:
Timestamp:
2005-12-27T14:39:32Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
e62762b
Parents:
238f828
Message:

IPv6 socket improvements. Daemon mode can now also listen on IPv6 sockets.
Also, when reverse lookup fails, BitlBee now correctly falls back to an
ASCII-formatted IP instead of "localhost.".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r238f828 re4d6271  
    4040irc_t *irc_new( int fd )
    4141{
    42         irc_t *irc = g_new0( irc_t, 1 );
    43        
     42        irc_t *irc;
     43        struct hostent *peer;
     44        unsigned int i;
     45        char buf[128];
     46#ifdef IPV6
     47        struct sockaddr_in6 sock[1];
     48#else
    4449        struct sockaddr_in sock[1];
    45 #ifdef IPV6
    46         struct sockaddr_in6 sock6[1];
    4750#endif
    48         struct hostent *peer;
    49         unsigned int i, j;
     51       
     52        irc = g_new0( irc_t, 1 );
    5053       
    5154        irc->fd = fd;
     
    7174       
    7275        i = sizeof( *sock );
    73 #ifdef IPV6
    74         j = sizeof( *sock6 );
    75 #endif
     76       
    7677        if( global.conf->hostname )
    7778                irc->myhost = g_strdup( global.conf->hostname );
    78         else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
    79         {
    80                 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
     79#ifdef IPV6
     80        else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
     81        {
     82                if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
    8183                        irc->myhost = g_strdup( peer->h_name );
    82         }
    83 #ifdef IPV6
    84         else if( getsockname( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 )
    85         {
    86                 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
     84                else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     85                        irc->myhost = g_strdup( buf );
     86        }
     87#else
     88        else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
     89        {
     90                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
    8791                        irc->myhost = g_strdup( peer->h_name );
     92                else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     93                        irc->myhost = g_strdup( buf );
    8894        }
    8995#endif
     
    9197        i = sizeof( *sock );
    9298#ifdef IPV6
    93         j = sizeof( *sock6 );
    94 #endif
    95         if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
    96         {
    97                 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
     99        if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
     100        {
     101                if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
    98102                        irc->host = g_strdup( peer->h_name );
    99         }
    100 #ifdef IPV6
    101         else if( getpeername( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 )
    102         {
    103                 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
     103                else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     104                        irc->host = g_strdup( buf );
     105        }
     106#else
     107        if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
     108        {
     109                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
    104110                        irc->host = g_strdup( peer->h_name );
     111                else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     112                        irc->host = g_strdup( buf );
    105113        }
    106114#endif
Note: See TracChangeset for help on using the changeset viewer.