aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitlbee.c93
-rw-r--r--conf.c23
-rw-r--r--conf.h4
-rwxr-xr-xconfigure7
-rw-r--r--crypting.h6
-rw-r--r--help.h2
-rw-r--r--irc.c74
-rw-r--r--lib/misc.c2
-rw-r--r--lib/proxy.c4
-rw-r--r--protocols/nogaim.c6
-rw-r--r--storage.h2
11 files changed, 82 insertions, 141 deletions
diff --git a/bitlbee.c b/bitlbee.c
index 6a3625ee..7a9a89d9 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -37,72 +37,53 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition
int bitlbee_daemon_init()
{
-#ifdef IPV6
- int use_ipv6 = 1;
- struct sockaddr_in6 listen_addr6;
-#endif
- struct sockaddr_in listen_addr;
+ struct addrinfo *res, hints, *addrinfo_bind;
int i;
FILE *fp;
log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG );
log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG );
-#ifdef IPV6
- if( ( global.listen_socket = socket( AF_INET6, SOCK_STREAM, 0 ) ) == -1 )
- {
- use_ipv6 = 0;
-#endif
- global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 );
-#ifdef IPV6
- }
-#endif
- if( global.listen_socket == -1 )
- {
- log_error( "socket" );
- return( -1 );
- }
-
- /* TIME_WAIT (?) sucks.. */
- i = 1;
- setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, sizeof( i ) );
-
-#ifdef IPV6
- memset( &listen_addr6, 0, sizeof( listen_addr6 ) );
- listen_addr6.sin6_family = AF_INET6;
- listen_addr6.sin6_port = htons( global.conf->port );
- if( ( i = inet_pton( AF_INET6, ipv6_wrap( global.conf->iface ), &listen_addr6.sin6_addr ) ) != 1 )
- {
- /* Forget about IPv6 in this function. */
- use_ipv6 = 0;
-#endif
- memset( &listen_addr, 0, sizeof( listen_addr ) );
- listen_addr.sin_family = AF_INET;
- listen_addr.sin_port = htons( global.conf->port );
- if( strcmp( global.conf->iface, "::" ) == 0 )
- i = inet_pton( AF_INET, "0.0.0.0", &listen_addr.sin_addr );
- else
- i = inet_pton( AF_INET, global.conf->iface, &listen_addr.sin_addr );
-#ifdef IPV6
- }
-#endif
-
- if( i != 1 )
+ memset( &hints, 0, sizeof( hints ) );
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
+
+ i = getaddrinfo( global.conf->iface, global.conf->port, &hints,
+ &addrinfo_bind );
+ if( i )
{
- log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface );
- return( -1 );
+ log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s",
+ global.conf->iface, gai_strerror(i) );
+ return -1;
}
-
-#ifdef IPV6
- if( !use_ipv6 || ( i = bind( global.listen_socket, (struct sockaddr *) &listen_addr6, sizeof( listen_addr6 ) ) ) == -1 )
-#endif
- i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) );
- if( i == -1 )
+
+ global.listen_socket = -1;
+
+ for( res = addrinfo_bind; res; res = res->ai_next )
{
- log_error( "bind" );
- return( -1 );
+ global.listen_socket = socket( res->ai_family, res->ai_socktype,
+ res->ai_protocol );
+ if( global.listen_socket < 0 )
+ continue;
+
+ /* TIME_WAIT (?) sucks.. */
+ i = 1;
+ setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i,
+ sizeof( i ) );
+
+ i = bind( global.listen_socket, res->ai_addr, res->ai_addrlen );
+ if( i == -1 )
+ {
+ log_error( "bind" );
+ return( -1 );
+ }
+
+ break;
}
-
+
+ freeaddrinfo( addrinfo_bind );
+
i = listen( global.listen_socket, 10 );
if( i == -1 )
{
diff --git a/conf.c b/conf.c
index 09fd08e1..551e8f5e 100644
--- a/conf.c
+++ b/conf.c
@@ -46,12 +46,8 @@ conf_t *conf_load( int argc, char *argv[] )
conf = g_new0( conf_t, 1 );
-#ifdef IPV6
- conf->iface = "::";
-#else
- conf->iface = "0.0.0.0";
-#endif
- conf->port = 6667;
+ conf->iface = NULL;
+ conf->port = "6667";
conf->nofork = 0;
conf->verbose = 0;
conf->primary_storage = "xml";
@@ -88,12 +84,8 @@ conf_t *conf_load( int argc, char *argv[] )
}
else if( opt == 'p' )
{
- if( ( sscanf( optarg, "%d", &i ) != 1 ) || ( i <= 0 ) || ( i > 65535 ) )
- {
- fprintf( stderr, "Invalid port number: %s\n", optarg );
- return( NULL );
- }
- conf->port = i;
+ g_free( conf->port );
+ conf->port = g_strdup( optarg );
}
else if( opt == 'P' )
{
@@ -203,12 +195,7 @@ static int conf_loadini( conf_t *conf, char *file )
}
else if( g_strcasecmp( ini->key, "daemonport" ) == 0 )
{
- if( ( sscanf( ini->value, "%d", &i ) != 1 ) || ( i <= 0 ) || ( i > 65535 ) )
- {
- fprintf( stderr, "Invalid port number: %s\n", ini->value );
- return( 0 );
- }
- conf->port = i;
+ conf->port = g_strdup( ini->value );
}
else if( g_strcasecmp( ini->key, "authmode" ) == 0 )
{
diff --git a/conf.h b/conf.h
index e852dbef..5138ce11 100644
--- a/conf.h
+++ b/conf.h
@@ -32,7 +32,7 @@ typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } au
typedef struct conf
{
char *iface;
- signed int port;
+ char *port;
int nofork;
int verbose;
runmode_t runmode;
@@ -50,7 +50,7 @@ typedef struct conf
int ping_timeout;
} conf_t;
-conf_t *conf_load( int argc, char *argv[] );
+G_GNUC_MALLOC conf_t *conf_load( int argc, char *argv[] );
void conf_loaddefaults( irc_t *irc );
#endif
diff --git a/configure b/configure
index ffa0e2f2..bc9960a9 100755
--- a/configure
+++ b/configure
@@ -29,7 +29,6 @@ debug=0
strip=1
gcov=0
plugins=1
-ipv6=1
events=glib
ldap=0
@@ -71,8 +70,6 @@ Option Description Default
--gcov=0/1 Disable/enable test coverage reporting $gcov
--plugins=0/1 Disable/enable plugins support $plugins
---ipv6=0/1 IPv6 socket support $ipv6
-
--events=... Event handler (glib, libevent) $events
--ssl=... SSL library to use (gnutls, nss, openssl, bogus, auto)
$ssl
@@ -134,10 +131,6 @@ cat<<EOF>config.h
#define CPU "$cpu"
EOF
-if [ "$ipv6" = "1" ]; then
- echo '#define IPV6' >> config.h
-fi
-
if [ "$debug" = "1" ]; then
[ -z "$CFLAGS" ] && CFLAGS=-g
echo 'DEBUG=1' >> Makefile.settings
diff --git a/crypting.h b/crypting.h
index fbaa7dcc..e13b0433 100644
--- a/crypting.h
+++ b/crypting.h
@@ -24,6 +24,6 @@
*/
int checkpass (const char *password, const char *md5sum);
-char *hashpass (const char *password);
-char *obfucrypt (char *line, const char *password);
-char *deobfucrypt (char *line, const char *password);
+G_GNUC_MALLOC char *hashpass (const char *password);
+G_GNUC_MALLOC char *obfucrypt (char *line, const char *password);
+G_GNUC_MALLOC char *deobfucrypt (char *line, const char *password);
diff --git a/help.h b/help.h
index 07182e9c..32aba723 100644
--- a/help.h
+++ b/help.h
@@ -42,7 +42,7 @@ typedef struct help
struct help *next;
} help_t;
-help_t *help_init( help_t **help, const char *helpfile );
+G_GNUC_MALLOC help_t *help_init( help_t **help, const char *helpfile );
char *help_get( help_t **help, char *string );
#endif
diff --git a/irc.c b/irc.c
index 1a936d47..0bebf9b0 100644
--- a/irc.c
+++ b/irc.c
@@ -44,14 +44,8 @@ static char *passchange( set_t *set, char *value )
irc_t *irc_new( int fd )
{
irc_t *irc;
- struct hostent *peer;
- unsigned int i;
- char buf[128];
-#ifdef IPV6
- struct sockaddr_in6 sock6[1];
- unsigned int i6;
-#endif
- struct sockaddr_in sock[1];
+ struct sockaddr_storage sock;
+ socklen_t socklen = sizeof( sock );
irc = g_new0( irc_t, 1 );
@@ -70,54 +64,42 @@ irc_t *irc_new( int fd )
irc->mynick = g_strdup( ROOT_NICK );
irc->channel = g_strdup( ROOT_CHAN );
- i = sizeof( *sock );
-#ifdef IPV6
- i6 = sizeof( *sock6 );
-#endif
-
if( global.conf->hostname )
- irc->myhost = g_strdup( global.conf->hostname );
-#ifdef IPV6
- else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 )
{
- if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
- irc->myhost = g_strdup( peer->h_name );
- else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
- irc->myhost = g_strdup( ipv6_unwrap( buf ) );
+ irc->myhost = g_strdup( global.conf->hostname );
}
-#endif
- else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
+ else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
{
- if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
- irc->myhost = g_strdup( peer->h_name );
- else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
- irc->myhost = g_strdup( buf );
+ char buf[NI_MAXHOST+1];
+
+ if( getnameinfo( (struct sockaddr *) &sock, socklen, buf,
+ NI_MAXHOST, NULL, -1, 0 ) == 0 )
+ {
+ irc->myhost = g_strdup( ipv6_unwrap( buf ) );
+ }
+ else
+ {
+ /* Rare, but possible. */
+ strncpy( irc->myhost, "localhost.localdomain", NI_MAXHOST );
+ }
}
- i = sizeof( *sock );
-#ifdef IPV6
- i6 = sizeof( *sock6 );
- if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 )
+ if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
{
- if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
- irc->host = g_strdup( peer->h_name );
- else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
+ char buf[NI_MAXHOST+1];
+
+ if( getnameinfo( (struct sockaddr *)&sock, socklen, buf,
+ NI_MAXHOST, NULL, -1, 0 ) == 0 )
+ {
irc->host = g_strdup( ipv6_unwrap( buf ) );
- }
- else
-#endif
- if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
- {
- if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
- irc->host = g_strdup( peer->h_name );
- else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
- irc->host = g_strdup( buf );
+ }
+ else
+ {
+ /* Rare, but possible. */
+ strncpy( irc->host, "localhost.localdomain", NI_MAXHOST );
+ }
}
- /* Rare, but possible. */
- if( !irc->host ) irc->host = g_strdup( "localhost." );
- if( !irc->myhost ) irc->myhost = g_strdup( "localhost." );
-
if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
diff --git a/lib/misc.c b/lib/misc.c
index 5e385d4a..c977029f 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -321,7 +321,6 @@ char *strip_newlines( char *source )
return source;
}
-#ifdef IPV6
/* Wrap an IPv4 address into IPv6 space. Not thread-safe... */
char *ipv6_wrap( char *src )
{
@@ -359,7 +358,6 @@ char *ipv6_unwrap( char *src )
return ( src + 7 );
}
-#endif
/* Convert from one charset to another.
diff --git a/lib/proxy.c b/lib/proxy.c
index 7911b06f..dff5d0a4 100644
--- a/lib/proxy.c
+++ b/lib/proxy.c
@@ -210,7 +210,7 @@ static gboolean http_canwrite(gpointer data, gint source, b_input_condition cond
return FALSE;
}
- if (proxyuser && *proxyuser) {
+ if (strlen(proxyuser) > 0) {
char *t1, *t2;
t1 = g_strdup_printf("%s:%s", proxyuser, proxypass);
t2 = tobase64(t1);
@@ -538,7 +538,7 @@ int proxy_connect(const char *host, int port, b_event_handler func, gpointer dat
phb->func = func;
phb->data = data;
- if ((proxytype == PROXY_NONE) || !proxyhost || !proxyhost[0] || !proxyport || (proxyport == -1))
+ if ((proxytype == PROXY_NONE) || strlen(proxyhost) > 0 || !proxyport || (proxyport == -1))
return proxy_connect_none(host, port, phb);
else if (proxytype == PROXY_HTTP)
return proxy_connect_http(host, port, phb);
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index d90870ad..d0395fa9 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -35,7 +35,7 @@
#include "nogaim.h"
#include <ctype.h>
-static int remove_chat_buddy_silent( struct groupchat *b, char *handle );
+static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
GSList *connections;
@@ -555,7 +555,7 @@ void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags,
/* Remove him/her from the conversations to prevent PART messages after he/she QUIT already */
for( c = ic->conversations; c; c = c->next )
- remove_chat_buddy_silent( c, (char*) handle );
+ remove_chat_buddy_silent( c, handle );
}
if( flags & OPT_AWAY )
@@ -820,7 +820,7 @@ void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason )
irc_part( b->ic->irc, u, b->channel );
}
-static int remove_chat_buddy_silent( struct groupchat *b, char *handle )
+static int remove_chat_buddy_silent( struct groupchat *b, const char *handle )
{
GList *i;
diff --git a/storage.h b/storage.h
index 3c641088..d114dec4 100644
--- a/storage.h
+++ b/storage.h
@@ -61,6 +61,6 @@ storage_status_t storage_remove (const char *nick, const char *password);
storage_status_t storage_rename (const char *onick, const char *nnick, const char *password);
void register_storage_backend(storage_t *);
-GList *storage_init(const char *primary, char **migrate);
+G_GNUC_MALLOC GList *storage_init(const char *primary, char **migrate);
#endif /* __STORAGE_H__ */