Changeset ebb95b6 for irc.c


Ignore:
Timestamp:
2007-11-14T23:42:07Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
50e1776
Parents:
a6df0b5 (diff), 1bf1ae6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging from devel/Jelmer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    ra6df0b5 rebb95b6  
    4545{
    4646        irc_t *irc;
    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];
     47        struct sockaddr_storage sock;
     48        socklen_t socklen = sizeof( sock );
    5549       
    5650        irc = g_new0( irc_t, 1 );
     
    7165        irc->channel = g_strdup( ROOT_CHAN );
    7266       
    73         i = sizeof( *sock );
    74 #ifdef IPV6
    75         i6 = sizeof( *sock6 );
    76 #endif
    77        
    7867        if( global.conf->hostname )
     68        {
    7969                irc->myhost = g_strdup( global.conf->hostname );
    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 )
     70        }
     71        else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
     72        {
     73                char buf[NI_MAXHOST+1];
     74
     75                if( getnameinfo( (struct sockaddr *) &sock, socklen, buf,
     76                                 NI_MAXHOST, NULL, -1, 0 ) == 0 )
     77                {
    8678                        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 )
     79                }
     80                else
     81                {
     82                        /* Rare, but possible. */
     83                        strncpy( irc->myhost, "localhost.localdomain", NI_MAXHOST );
     84                }
     85        }
     86       
     87        if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
     88        {
     89                char buf[NI_MAXHOST+1];
     90
     91                if( getnameinfo( (struct sockaddr *)&sock, socklen, buf,
     92                                 NI_MAXHOST, NULL, -1, 0 ) == 0 )
     93                {
    10594                        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 
     95                }
     96                else
     97                {
     98                        /* Rare, but possible. */
     99                        strncpy( irc->host, "localhost.localdomain", NI_MAXHOST );
     100                }
     101        }
     102       
    121103        if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
    122104                irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
     
    744726        irc_spawn( irc, u );
    745727       
    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 FAQ's are answered there." );
     728        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." );
    747729       
    748730        if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
Note: See TracChangeset for help on using the changeset viewer.