Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r7435ccf r5e2615a  
    4545{
    4646        irc_t *irc;
    47         struct sockaddr_storage sock;
    48         socklen_t socklen = sizeof( sock );
     47        struct hostent *peer;
     48        unsigned int i;
     49        char buf[128];
     50#ifdef IPV6
     51        struct sockaddr_in6 sock6[1];
     52        unsigned int i6;
     53#endif
     54        struct sockaddr_in sock[1];
    4955       
    5056        irc = g_new0( irc_t, 1 );
     
    6571        irc->channel = g_strdup( ROOT_CHAN );
    6672       
     73        i = sizeof( *sock );
     74#ifdef IPV6
     75        i6 = sizeof( *sock6 );
     76#endif
     77       
    6778        if( global.conf->hostname )
    6879                irc->myhost = g_strdup( global.conf->hostname );
    69         else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
    70         {
    71                 irc->myhost = g_new0( char, NI_MAXHOST );
    72 
    73                 if (getnameinfo( (struct sockaddr *) &sock, socklen, irc->myhost,
    74                                                 NI_MAXHOST, NULL, -1, 0) ) {
    75                         /* Rare, but possible. */
    76                         strncpy( irc->myhost, "localhost.", NI_MAXHOST );
    77                 }
    78         }
    79        
    80         if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
    81         {
    82                 irc->host = g_new0( char, NI_MAXHOST );
    83 
    84                 if ( getnameinfo( (struct sockaddr *)&sock, socklen, irc->host,
    85                                                 NI_MAXHOST, NULL, -1, 0 ) ) {
    86                         /* Rare, but possible. */
    87                         strncpy( irc->myhost, "localhost.", NI_MAXHOST );
    88                 }
    89         }
    90        
     80#ifdef IPV6
     81        else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 )
     82        {
     83                if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
     84                        irc->myhost = g_strdup( peer->h_name );
     85                else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     86                        irc->myhost = g_strdup( ipv6_unwrap( buf ) );
     87        }
     88#endif
     89        else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
     90        {
     91                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
     92                        irc->myhost = g_strdup( peer->h_name );
     93                else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     94                        irc->myhost = g_strdup( buf );
     95        }
     96       
     97        i = sizeof( *sock );
     98#ifdef IPV6
     99        i6 = sizeof( *sock6 );
     100        if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 )
     101        {
     102                if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
     103                        irc->host = g_strdup( peer->h_name );
     104                else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     105                        irc->host = g_strdup( ipv6_unwrap( buf ) );
     106        }
     107        else
     108#endif
     109        if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
     110        {
     111                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
     112                        irc->host = g_strdup( peer->h_name );
     113                else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     114                        irc->host = g_strdup( buf );
     115        }
     116       
     117        /* Rare, but possible. */
     118        if( !irc->host ) irc->host = g_strdup( "localhost." );
     119        if( !irc->myhost ) irc->myhost = g_strdup( "localhost." );
     120
    91121        if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
    92122                irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
     
    714744        irc_spawn( irc, u );
    715745       
    716         irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\nIf you've never used BitlBee before, please do read the help information using the \x02help\x02 command. Lots of FAQ's are answered there." );
     746        irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\nIf you've never used BitlBee before, please do read the help information using the \x02help\x02 command. Lots of FAQs are answered there." );
    717747       
    718748        if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
Note: See TracChangeset for help on using the changeset viewer.