From a0d04d6253cf70877a11156059209e1f9a2efe31 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 7 May 2006 20:07:43 +0200 Subject: Got rid of all GLib GIOChannel-related calls outside proxy.c --- bitlbee.c | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 3aca30c5..fb04897d 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -33,7 +33,7 @@ #include #include -gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ); +void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ); int bitlbee_daemon_init() { @@ -43,7 +43,6 @@ int bitlbee_daemon_init() struct sockaddr_in listen_addr; #endif int i; - GIOChannel *ch; FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); @@ -90,8 +89,7 @@ int bitlbee_daemon_init() return( -1 ); } - ch = g_io_channel_unix_new( global.listen_socket ); - global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL ); + global.listen_watch_source_id = gaim_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL ); #ifndef _WIN32 if( !global.conf->nofork ) @@ -146,34 +144,28 @@ int bitlbee_inetd_init() return( 0 ); } -gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data ) +void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond ) { irc_t *irc = data; char line[513]; int st; - if( condition & G_IO_ERR || condition & G_IO_HUP ) - { - irc_abort( irc, 1, "Read error" ); - return FALSE; - } - st = read( irc->fd, line, sizeof( line ) - 1 ); if( st == 0 ) { irc_abort( irc, 1, "Connection reset by peer" ); - return FALSE; + goto no_more_events; } else if( st < 0 ) { if( sockerr_again() ) { - return TRUE; + return; } else { irc_abort( irc, 1, "Read error: %s", strerror( errno ) ); - return FALSE; + goto no_more_events; } } @@ -194,27 +186,31 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit if( !g_slist_find( irc_connection_list, irc ) ) { log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd ); - return FALSE; + goto no_more_events; } /* Very naughty, go read the RFCs! >:) */ if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) ) { irc_abort( irc, 0, "Maximum line length exceeded" ); - return FALSE; + goto no_more_events; } - return TRUE; + return; + +no_more_events: + gaim_input_remove( irc->r_watch_source_id ); + irc->r_watch_source_id = 0; } -gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data ) +void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond ) { irc_t *irc = data; int st, size; char *temp; if( irc->sendbuffer == NULL ) - return( FALSE ); + goto no_more_events; size = strlen( irc->sendbuffer ); st = write( irc->fd, irc->sendbuffer, size ); @@ -222,23 +218,22 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi if( st == 0 || ( st < 0 && !sockerr_again() ) ) { irc_abort( irc, 1, "Write error: %s", strerror( errno ) ); - return FALSE; + goto no_more_events; } else if( st < 0 ) /* && sockerr_again() */ { - return TRUE; + return; } if( st == size ) { g_free( irc->sendbuffer ); irc->sendbuffer = NULL; - irc->w_watch_source_id = 0; if( irc->status == USTATUS_SHUTDOWN ) irc_free( irc ); - return( FALSE ); + goto no_more_events; } else { @@ -246,13 +241,17 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi g_free( irc->sendbuffer ); irc->sendbuffer = temp; - return( TRUE ); + return; } + +no_more_events: + gaim_input_remove( irc->w_watch_source_id ); + irc->w_watch_source_id = 0; } -gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ) +void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ) { - size_t size = sizeof( struct sockaddr_in ); + socklen_t size = sizeof( struct sockaddr_in ); struct sockaddr_in conn_info; int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); pid_t client_pid = 0; @@ -260,7 +259,7 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi if( new_socket == -1 ) { log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) ); - return TRUE; + return; } if( global.conf->runmode == RUNMODE_FORKDAEMON ) @@ -319,8 +318,6 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket ); irc_new( new_socket ); } - - return TRUE; } void bitlbee_shutdown( gpointer data ) -- cgit v1.2.3 From ba9edaa568088900145bbd1004c864b7d408c38d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 10 May 2006 19:34:46 +0200 Subject: Moved everything to the BitlBee event handling API. --- bitlbee.c | 57 +++++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index fb04897d..e52830be 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -33,7 +33,7 @@ #include #include -void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ); +static gboolean bitlbee_io_new_client( gpointer data, gint source, b_input_condition condition ); int bitlbee_daemon_init() { @@ -89,7 +89,7 @@ int bitlbee_daemon_init() return( -1 ); } - global.listen_watch_source_id = gaim_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL ); + global.listen_watch_source_id = b_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL ); #ifndef _WIN32 if( !global.conf->nofork ) @@ -144,7 +144,7 @@ int bitlbee_inetd_init() return( 0 ); } -void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond ) +gboolean bitlbee_io_current_client_read( gpointer data, gint source, b_input_condition cond ) { irc_t *irc = data; char line[513]; @@ -154,18 +154,18 @@ void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondit if( st == 0 ) { irc_abort( irc, 1, "Connection reset by peer" ); - goto no_more_events; + return FALSE; } else if( st < 0 ) { if( sockerr_again() ) { - return; + return TRUE; } else { irc_abort( irc, 1, "Read error: %s", strerror( errno ) ); - goto no_more_events; + return FALSE; } } @@ -186,31 +186,27 @@ void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondit if( !g_slist_find( irc_connection_list, irc ) ) { log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd ); - goto no_more_events; + return FALSE; } /* Very naughty, go read the RFCs! >:) */ if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) ) { irc_abort( irc, 0, "Maximum line length exceeded" ); - goto no_more_events; + return FALSE; } - return; - -no_more_events: - gaim_input_remove( irc->r_watch_source_id ); - irc->r_watch_source_id = 0; + return TRUE; } -void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond ) +gboolean bitlbee_io_current_client_write( gpointer data, gint source, b_input_condition cond ) { irc_t *irc = data; int st, size; char *temp; if( irc->sendbuffer == NULL ) - goto no_more_events; + return FALSE; size = strlen( irc->sendbuffer ); st = write( irc->fd, irc->sendbuffer, size ); @@ -218,22 +214,23 @@ void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondi if( st == 0 || ( st < 0 && !sockerr_again() ) ) { irc_abort( irc, 1, "Write error: %s", strerror( errno ) ); - goto no_more_events; + return FALSE; } else if( st < 0 ) /* && sockerr_again() */ { - return; + return TRUE; } if( st == size ) { g_free( irc->sendbuffer ); irc->sendbuffer = NULL; + irc->w_watch_source_id = 0; if( irc->status == USTATUS_SHUTDOWN ) irc_free( irc ); - goto no_more_events; + return FALSE; } else { @@ -241,15 +238,11 @@ void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondi g_free( irc->sendbuffer ); irc->sendbuffer = temp; - return; + return TRUE; } - -no_more_events: - gaim_input_remove( irc->w_watch_source_id ); - irc->w_watch_source_id = 0; } -void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ) +static gboolean bitlbee_io_new_client( gpointer data, gint source, b_input_condition condition ) { socklen_t size = sizeof( struct sockaddr_in ); struct sockaddr_in conn_info; @@ -259,7 +252,7 @@ void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condi if( new_socket == -1 ) { log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) ); - return; + return TRUE; } if( global.conf->runmode == RUNMODE_FORKDAEMON ) @@ -284,7 +277,7 @@ void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condi child = g_new0( struct bitlbee_child, 1 ); child->pid = client_pid; child->ipc_fd = fds[0]; - child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); + child->ipc_inpa = b_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); child_list = g_slist_append( child_list, child ); log_message( LOGLVL_INFO, "Creating new subprocess with pid %d.", client_pid ); @@ -299,14 +292,14 @@ void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condi /* Close the listening socket, we're a client. */ close( global.listen_socket ); - g_source_remove( global.listen_watch_source_id ); + b_event_remove( global.listen_watch_source_id ); /* Make the connection. */ irc = irc_new( new_socket ); /* We can store the IPC fd there now. */ global.listen_socket = fds[1]; - global.listen_watch_source_id = gaim_input_add( fds[1], GAIM_INPUT_READ, ipc_child_read, irc ); + global.listen_watch_source_id = b_input_add( fds[1], GAIM_INPUT_READ, ipc_child_read, irc ); close( fds[0] ); @@ -318,14 +311,18 @@ void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condi log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket ); irc_new( new_socket ); } + + return TRUE; } -void bitlbee_shutdown( gpointer data ) +gboolean bitlbee_shutdown( gpointer data, gint fd, b_input_condition cond ) { /* Try to save data for all active connections (if desired). */ while( irc_connection_list != NULL ) irc_free( irc_connection_list->data ); /* We'll only reach this point when not running in inetd mode: */ - g_main_quit( global.loop ); + b_main_quit(); + + return FALSE; } -- cgit v1.2.3 From 919c27cc6f1d7654505ac17e80d1fd7197a233f5 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 14 May 2006 10:41:05 +0200 Subject: Fixed a little memory access bug. --- bitlbee.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index e52830be..748b7bba 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -33,7 +33,7 @@ #include #include -static gboolean bitlbee_io_new_client( gpointer data, gint source, b_input_condition condition ); +static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ); int bitlbee_daemon_init() { @@ -144,7 +144,7 @@ int bitlbee_inetd_init() return( 0 ); } -gboolean bitlbee_io_current_client_read( gpointer data, gint source, b_input_condition cond ) +gboolean bitlbee_io_current_client_read( gpointer data, gint fd, b_input_condition cond ) { irc_t *irc = data; char line[513]; @@ -185,7 +185,7 @@ gboolean bitlbee_io_current_client_read( gpointer data, gint source, b_input_con /* Normally, irc_process() shouldn't call irc_free() but irc_abort(). Just in case: */ if( !g_slist_find( irc_connection_list, irc ) ) { - log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd ); + log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", fd ); return FALSE; } @@ -199,7 +199,7 @@ gboolean bitlbee_io_current_client_read( gpointer data, gint source, b_input_con return TRUE; } -gboolean bitlbee_io_current_client_write( gpointer data, gint source, b_input_condition cond ) +gboolean bitlbee_io_current_client_write( gpointer data, gint fd, b_input_condition cond ) { irc_t *irc = data; int st, size; @@ -242,7 +242,7 @@ gboolean bitlbee_io_current_client_write( gpointer data, gint source, b_input_co } } -static gboolean bitlbee_io_new_client( gpointer data, gint source, b_input_condition condition ) +static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ) { socklen_t size = sizeof( struct sockaddr_in ); struct sockaddr_in conn_info; -- cgit v1.2.3 From 79e826a028f4b4c62c0c16e20af1fb13a9636324 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 15 Jun 2006 14:22:17 +0200 Subject: Converted irc->status to binary flags. (This also fixes auto-save-on-quit that broke because of USTATUS_SHUTDOWN. :-( ) --- bitlbee.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 3aca30c5..8cceca6f 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -235,7 +235,7 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi irc->sendbuffer = NULL; irc->w_watch_source_id = 0; - if( irc->status == USTATUS_SHUTDOWN ) + if( irc->status & USTATUS_SHUTDOWN ) irc_free( irc ); return( FALSE ); -- cgit v1.2.3 From 6e1fed7057ee26f21b0e59a5aeb292d4f3f0e8ae Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 25 Jun 2006 19:07:25 +0200 Subject: Using salted MD5 checksums for the user's BitlBee password and salted RC4 encryption for the IM account passwords, plus some calls to srand() to keep the salts secure and unique. --- bitlbee.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 1d4e2b34..cbad61dc 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -290,6 +290,10 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition { irc_t *irc; + /* Since we're fork()ing here, let's make sure we won't + get the same random numbers as the parent/siblings. */ + srand( time( NULL ) ^ getpid() ); + /* Close the listening socket, we're a client. */ close( global.listen_socket ); b_event_remove( global.listen_watch_source_id ); -- cgit v1.2.3 From b0a33a50735d93e1414a2e6c2007884d756429a3 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 11 Jul 2006 11:28:44 +0200 Subject: Better handling of situations where IPv6 is not available at run-time. --- bitlbee.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 1d4e2b34..f3cc3d4a 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -35,20 +35,31 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ); +#undef AF_INET6 +#define AF_INET6 666 + int bitlbee_daemon_init() { #ifdef IPV6 - struct sockaddr_in6 listen_addr; -#else - struct sockaddr_in listen_addr; + int use_ipv6 = 1; + struct sockaddr_in6 listen_addr6; #endif + struct sockaddr_in listen_addr; int i; FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); - global.listen_socket = socket( AF_INETx, SOCK_STREAM, 0 ); +#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" ); @@ -60,13 +71,21 @@ int bitlbee_daemon_init() setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, sizeof( i ) ); #ifdef IPV6 - listen_addr.sin6_family = AF_INETx; - listen_addr.sin6_port = htons( global.conf->port ); - i = inet_pton( AF_INETx, ipv6_wrap( global.conf->iface ), &listen_addr.sin6_addr ); -#else - listen_addr.sin_family = AF_INETx; - listen_addr.sin_port = htons( global.conf->port ); - i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin_addr ); + 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 + 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 ) @@ -75,7 +94,10 @@ int bitlbee_daemon_init() return( -1 ); } - i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) ); +#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 ) { log_error( "bind" ); -- cgit v1.2.3 From 639809488bb4ab59a4a4f15ef2d4cd34037a68a4 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 12 Jul 2006 10:07:47 +0200 Subject: Removed #defines used to simulate systems without IPv6 support. --- bitlbee.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index f3cc3d4a..85ae4621 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -35,9 +35,6 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ); -#undef AF_INET6 -#define AF_INET6 666 - int bitlbee_daemon_init() { #ifdef IPV6 -- cgit v1.2.3 From 46af1074101f0354490ea3940f16d6f84467de0e Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 18 Feb 2007 17:34:19 +0000 Subject: Fixed uninitialized memory issue in bitlbee.c listen socket setup code. Fixes #230 and #183. --- bitlbee.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 5870bbad..6a3625ee 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -68,6 +68,7 @@ int bitlbee_daemon_init() 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 ) @@ -75,6 +76,7 @@ int bitlbee_daemon_init() /* 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 ) -- cgit v1.2.3 From e9b755e3726fa41ac2d4ed1c3a6192d1af68edbc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 18 Oct 2007 18:44:25 +0200 Subject: Use standard functions for dealing with both IPv6 and IPv4. --- bitlbee.c | 95 +++++++++++++++++++++++++-------------------------------------- 1 file changed, 37 insertions(+), 58 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 6a3625ee..3065aa9d 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -37,72 +37,51 @@ 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 ) - { - log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface ); - return( -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': %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 ) - { - log_error( "bind" ); - return( -1 ); + + global.listen_socket = -1; + + for (res = addrinfo_bind; res; res = res->ai_next) { + 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 ) { -- cgit v1.2.3 From 7435ccf486eee2f60d6a8b2ab0029b8f4ce17ab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 18 Oct 2007 21:03:02 +0200 Subject: Fix indentation. --- bitlbee.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 3065aa9d..625ea214 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -44,14 +44,14 @@ int bitlbee_daemon_init() log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); - memset(&hints, 0, sizeof(hints)); + 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) { + i = getaddrinfo( global.conf->iface, global.conf->port, &hints, + &addrinfo_bind ); + if ( i ) { log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s", global.conf->iface, gai_strerror(i) ); return -1; @@ -59,10 +59,10 @@ int bitlbee_daemon_init() global.listen_socket = -1; - for (res = addrinfo_bind; res; res = res->ai_next) { - global.listen_socket = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (global.listen_socket < 0) + for ( res = addrinfo_bind; res; res = res->ai_next ) { + global.listen_socket = socket( res->ai_family, res->ai_socktype, + res->ai_protocol ); + if ( global.listen_socket < 0 ) continue; /* TIME_WAIT (?) sucks.. */ @@ -70,7 +70,7 @@ int bitlbee_daemon_init() setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, sizeof( i ) ); - i = bind( global.listen_socket, res->ai_addr, res->ai_addrlen); + i = bind( global.listen_socket, res->ai_addr, res->ai_addrlen ); if( i == -1 ) { log_error( "bind" ); @@ -80,7 +80,7 @@ int bitlbee_daemon_init() break; } - freeaddrinfo(addrinfo_bind); + freeaddrinfo( addrinfo_bind ); i = listen( global.listen_socket, 10 ); if( i == -1 ) -- cgit v1.2.3 From 3e1e11afc869238d5cfca899d4814fea8a877687 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 19 Nov 2007 23:41:42 +0000 Subject: Fixed NULL pointer dereference (in printf) when connected to a non-socket (which I do quite often when testing stuff). --- bitlbee.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 7a9a89d9..3d8a0310 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -49,12 +49,11 @@ int bitlbee_daemon_init() hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; - i = getaddrinfo( global.conf->iface, global.conf->port, &hints, - &addrinfo_bind ); + i = getaddrinfo( global.conf->iface, global.conf->port, &hints, &addrinfo_bind ); if( i ) { - log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s", - global.conf->iface, gai_strerror(i) ); + log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s", + global.conf->iface, gai_strerror(i) ); return -1; } @@ -62,15 +61,13 @@ int bitlbee_daemon_init() for( res = addrinfo_bind; res; res = res->ai_next ) { - global.listen_socket = socket( res->ai_family, res->ai_socktype, - res->ai_protocol ); + 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 ) ); + 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 ) @@ -118,8 +115,7 @@ int bitlbee_daemon_init() if( global.conf->runmode == RUNMODE_FORKDAEMON ) ipc_master_load_state(); - if( global.conf->runmode == RUNMODE_DAEMON || - global.conf->runmode == RUNMODE_FORKDAEMON ) + if( global.conf->runmode == RUNMODE_DAEMON || global.conf->runmode == RUNMODE_FORKDAEMON ) ipc_master_listen_socket(); if( ( fp = fopen( global.conf->pidfile, "w" ) ) ) -- cgit v1.2.3 From b6a2373c2c9a98594a87c54a4644f3c0e985e420 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 28 Nov 2007 23:24:26 +0000 Subject: Fixed the epoll+ForkDaemon combination. The libevent event handling didn't work very well on Linux 2.6 (and possibly others) in ForkDaemon mode. --- bitlbee.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 3d8a0310..3f488b46 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -292,6 +292,8 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition get the same random numbers as the parent/siblings. */ srand( time( NULL ) ^ getpid() ); + b_main_init(); + /* Close the listening socket, we're a client. */ close( global.listen_socket ); b_event_remove( global.listen_watch_source_id ); -- cgit v1.2.3 From 52744f8f65a278a59a8903d5c594e057d63c7006 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 17 Jan 2008 22:06:55 +0000 Subject: Fixing some Solaris compiler warnings (u_int->uint, adding some typecasts for pid_t variables). --- bitlbee.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index 3f488b46..c4b5abb3 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -278,7 +278,7 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition child->ipc_inpa = b_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); child_list = g_slist_append( child_list, child ); - log_message( LOGLVL_INFO, "Creating new subprocess with pid %d.", client_pid ); + log_message( LOGLVL_INFO, "Creating new subprocess with pid %d.", (int) client_pid ); /* Close some things we don't need in the parent process. */ close( new_socket ); -- cgit v1.2.3 From 1ecff5ee9ab540584a8b15814dcc15f706a26d4c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 10 Feb 2008 11:12:35 +0000 Subject: Making AI_ADDRCONFIG optional, it doesn't exist on at least NetBSD and (IIRC) OpenBSD systems. --- bitlbee.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bitlbee.c') diff --git a/bitlbee.c b/bitlbee.c index c4b5abb3..59a417f0 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -47,7 +47,11 @@ int bitlbee_daemon_init() memset( &hints, 0, sizeof( hints ) ); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; + hints.ai_flags = AI_PASSIVE +#ifdef AI_ADDRCONFIG + | AI_ADDRCONFIG +#endif + ; i = getaddrinfo( global.conf->iface, global.conf->port, &hints, &addrinfo_bind ); if( i ) -- cgit v1.2.3