Changeset e4d6271


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.".

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.c

    r238f828 re4d6271  
    6868int bitlbee_daemon_init()
    6969{
     70#ifdef IPV6
     71        struct sockaddr_in6 listen_addr;
     72#else
    7073        struct sockaddr_in listen_addr;
     74#endif
    7175        int i;
    7276        GIOChannel *ch;
     
    7579        log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG );
    7680       
    77         global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 );
     81        global.listen_socket = socket( AF_INETx, SOCK_STREAM, 0 );
    7882        if( global.listen_socket == -1 )
    7983        {
     
    8185                return( -1 );
    8286        }
    83         listen_addr.sin_family = AF_INET;
     87       
     88#ifdef IPV6
     89        listen_addr.sin6_family = AF_INETx;
     90        listen_addr.sin6_port = htons( global.conf->port );
     91        i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin6_addr );
     92#else
     93        listen_addr.sin_family = AF_INETx;
    8494        listen_addr.sin_port = htons( global.conf->port );
    85         listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface );
    86        
    87         i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) );
     95        i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin_addr );
     96#endif
     97       
     98        if( i != 1 )
     99        {
     100                log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface );
     101                return( -1 );
     102        }
     103       
     104        i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) );
    88105        if( i == -1 )
    89106        {
  • 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
  • protocols/http_client.c

    r238f828 re4d6271  
    2727#include <stdio.h>
    2828
    29 #include "sock.h"
    3029#include "http_client.h"
    3130#include "url.h"
     31#include "sock.h"
    3232
    3333
  • protocols/oscar/oscar.c

    r238f828 re4d6271  
    2121 */
    2222
    23 #include "sock.h"
    2423#include <errno.h>
    2524#include <ctype.h>
     
    3332#include "bitlbee.h"
    3433#include "proxy.h"
     34#include "sock.h"
    3535
    3636#include "aim.h"
  • sock.h

    r238f828 re4d6271  
    11#include <errno.h>
    22#include <fcntl.h>
     3
     4/* To cut down on the ifdef stuff a little bit in other places */
     5#ifdef IPV6
     6#define AF_INETx AF_INET6
     7#else
     8#define AF_INETx AF_INET
     9#endif
    310
    411#ifndef _WIN32
Note: See TracChangeset for help on using the changeset viewer.