diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2005-12-27 15:39:32 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2005-12-27 15:39:32 +0100 |
commit | e4d62711995840def3a2d51f62923d95cb368cee (patch) | |
tree | b53c3762820dc54aa997a05be8da33bdf2340b2f | |
parent | 238f828cb3524a2a09337d7502cc6db9556fc67a (diff) |
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.".
-rw-r--r-- | bitlbee.c | 25 | ||||
-rw-r--r-- | irc.c | 50 | ||||
-rw-r--r-- | protocols/http_client.c | 2 | ||||
-rw-r--r-- | protocols/oscar/oscar.c | 2 | ||||
-rw-r--r-- | sock.h | 7 |
5 files changed, 59 insertions, 27 deletions
@@ -67,24 +67,41 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi int bitlbee_daemon_init() { +#ifdef IPV6 + struct sockaddr_in6 listen_addr; +#else struct sockaddr_in listen_addr; +#endif int i; GIOChannel *ch; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); - global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 ); + global.listen_socket = socket( AF_INETx, SOCK_STREAM, 0 ); if( global.listen_socket == -1 ) { log_error( "socket" ); return( -1 ); } - listen_addr.sin_family = AF_INET; + +#ifdef IPV6 + listen_addr.sin6_family = AF_INETx; + listen_addr.sin6_port = htons( global.conf->port ); + i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin6_addr ); +#else + listen_addr.sin_family = AF_INETx; listen_addr.sin_port = htons( global.conf->port ); - listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface ); + i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin_addr ); +#endif + + if( i != 1 ) + { + log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface ); + return( -1 ); + } - i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) ); + i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) ); if( i == -1 ) { log_error( "bind" ); @@ -39,14 +39,17 @@ static char *passchange (irc_t *irc, void *set, char *value) irc_t *irc_new( int fd ) { - irc_t *irc = g_new0( irc_t, 1 ); - - struct sockaddr_in sock[1]; + irc_t *irc; + struct hostent *peer; + unsigned int i; + char buf[128]; #ifdef IPV6 - struct sockaddr_in6 sock6[1]; + struct sockaddr_in6 sock[1]; +#else + struct sockaddr_in sock[1]; #endif - struct hostent *peer; - unsigned int i, j; + + irc = g_new0( irc_t, 1 ); irc->fd = fd; irc->io_channel = g_io_channel_unix_new( fd ); @@ -70,38 +73,43 @@ irc_t *irc_new( int fd ) irc->channel = g_strdup( ROOT_CHAN ); i = sizeof( *sock ); -#ifdef IPV6 - j = sizeof( *sock6 ); -#endif + if( global.conf->hostname ) irc->myhost = g_strdup( global.conf->hostname ); - else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) +#ifdef IPV6 + else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx ) { - if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) + if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) ) irc->myhost = g_strdup( peer->h_name ); + else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) + irc->myhost = g_strdup( buf ); } -#ifdef IPV6 - else if( getsockname( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 ) +#else + else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx ) { - if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) + if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) ) irc->myhost = g_strdup( peer->h_name ); + else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) + irc->myhost = g_strdup( buf ); } #endif i = sizeof( *sock ); #ifdef IPV6 - j = sizeof( *sock6 ); -#endif - if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) + if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx ) { - if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) + if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) ) irc->host = g_strdup( peer->h_name ); + else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) + irc->host = g_strdup( buf ); } -#ifdef IPV6 - else if( getpeername( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 ) +#else + if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx ) { - if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) + if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) ) irc->host = g_strdup( peer->h_name ); + else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) + irc->host = g_strdup( buf ); } #endif diff --git a/protocols/http_client.c b/protocols/http_client.c index 51424e1c..9417e200 100644 --- a/protocols/http_client.c +++ b/protocols/http_client.c @@ -26,9 +26,9 @@ #include <string.h> #include <stdio.h> -#include "sock.h" #include "http_client.h" #include "url.h" +#include "sock.h" static void http_connected( gpointer data, int source, GaimInputCondition cond ); diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 5f19f12b..b4bfb220 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -20,7 +20,6 @@ * */ -#include "sock.h" #include <errno.h> #include <ctype.h> #include <string.h> @@ -32,6 +31,7 @@ #include "nogaim.h" #include "bitlbee.h" #include "proxy.h" +#include "sock.h" #include "aim.h" #include "icq.h" @@ -1,6 +1,13 @@ #include <errno.h> #include <fcntl.h> +/* To cut down on the ifdef stuff a little bit in other places */ +#ifdef IPV6 +#define AF_INETx AF_INET6 +#else +#define AF_INETx AF_INET +#endif + #ifndef _WIN32 #include <unistd.h> #include <sys/socket.h> |