Changeset b0a33a5
- Timestamp:
- 2006-07-11T09:28:44Z (18 years ago)
- Branches:
- master
- Children:
- 6398094
- Parents:
- a93e3c8
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.c
ra93e3c8 rb0a33a5 36 36 static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ); 37 37 38 #undef AF_INET6 39 #define AF_INET6 666 40 38 41 int bitlbee_daemon_init() 39 42 { 40 43 #ifdef IPV6 41 struct sockaddr_in6 listen_addr; 42 #else 44 int use_ipv6 = 1; 45 struct sockaddr_in6 listen_addr6; 46 #endif 43 47 struct sockaddr_in listen_addr; 44 #endif45 48 int i; 46 49 FILE *fp; … … 49 52 log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); 50 53 51 global.listen_socket = socket( AF_INETx, SOCK_STREAM, 0 ); 54 #ifdef IPV6 55 if( ( global.listen_socket = socket( AF_INET6, SOCK_STREAM, 0 ) ) == -1 ) 56 { 57 use_ipv6 = 0; 58 #endif 59 global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 ); 60 #ifdef IPV6 61 } 62 #endif 52 63 if( global.listen_socket == -1 ) 53 64 { … … 61 72 62 73 #ifdef IPV6 63 listen_addr.sin6_family = AF_INETx; 64 listen_addr.sin6_port = htons( global.conf->port ); 65 i = inet_pton( AF_INETx, ipv6_wrap( global.conf->iface ), &listen_addr.sin6_addr ); 66 #else 67 listen_addr.sin_family = AF_INETx; 68 listen_addr.sin_port = htons( global.conf->port ); 69 i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin_addr ); 74 listen_addr6.sin6_family = AF_INET6; 75 listen_addr6.sin6_port = htons( global.conf->port ); 76 if( ( i = inet_pton( AF_INET6, ipv6_wrap( global.conf->iface ), &listen_addr6.sin6_addr ) ) != 1 ) 77 { 78 /* Forget about IPv6 in this function. */ 79 use_ipv6 = 0; 80 #endif 81 listen_addr.sin_family = AF_INET; 82 listen_addr.sin_port = htons( global.conf->port ); 83 if( strcmp( global.conf->iface, "::" ) == 0 ) 84 i = inet_pton( AF_INET, "0.0.0.0", &listen_addr.sin_addr ); 85 else 86 i = inet_pton( AF_INET, global.conf->iface, &listen_addr.sin_addr ); 87 #ifdef IPV6 88 } 70 89 #endif 71 90 … … 76 95 } 77 96 78 i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) ); 97 #ifdef IPV6 98 if( !use_ipv6 || ( i = bind( global.listen_socket, (struct sockaddr *) &listen_addr6, sizeof( listen_addr6 ) ) ) == -1 ) 99 #endif 100 i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) ); 79 101 if( i == -1 ) 80 102 { -
irc.c
ra93e3c8 rb0a33a5 46 46 char buf[128]; 47 47 #ifdef IPV6 48 struct sockaddr_in6 sock[1]; 49 #else 48 struct sockaddr_in6 sock6[1]; 49 unsigned int i6; 50 #endif 50 51 struct sockaddr_in sock[1]; 51 #endif52 52 53 53 irc = g_new0( irc_t, 1 ); … … 69 69 70 70 i = sizeof( *sock ); 71 #ifdef IPV6 72 i6 = sizeof( *sock6 ); 73 #endif 71 74 72 75 if( global.conf->hostname ) 73 76 irc->myhost = g_strdup( global.conf->hostname ); 74 77 #ifdef IPV6 75 else if( getsockname( irc->fd, (struct sockaddr*) sock , &i ) == 0 && sock->sin6_family == AF_INETx)76 { 77 if( ( peer = gethostbyaddr( (char*) &sock ->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx) ) )78 else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 79 { 80 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 78 81 irc->myhost = g_strdup( peer->h_name ); 79 else if( inet_ntop( AF_INET x, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )82 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 80 83 irc->myhost = g_strdup( ipv6_unwrap( buf ) ); 81 84 } 82 #e lse83 else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET x)84 { 85 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET x) ) )85 #endif 86 else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 87 { 88 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 86 89 irc->myhost = g_strdup( peer->h_name ); 87 else if( inet_ntop( AF_INET x, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )90 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 88 91 irc->myhost = g_strdup( buf ); 89 92 } 90 #endif91 93 92 94 i = sizeof( *sock ); 93 95 #ifdef IPV6 94 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx ) 95 { 96 if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) ) 96 i6 = sizeof( *sock6 ); 97 if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 98 { 99 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 97 100 irc->host = g_strdup( peer->h_name ); 98 else if( inet_ntop( AF_INET x, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )101 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 99 102 irc->host = g_strdup( ipv6_unwrap( buf ) ); 100 103 } 101 #else 102 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx ) 103 { 104 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) ) 104 else 105 #endif 106 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 107 { 108 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 105 109 irc->host = g_strdup( peer->h_name ); 106 else if( inet_ntop( AF_INET x, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )110 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 107 111 irc->host = g_strdup( buf ); 108 112 } 109 #endif110 113 111 114 /* Rare, but possible. */ -
sock.h
ra93e3c8 rb0a33a5 1 1 #include <errno.h> 2 2 #include <fcntl.h> 3 4 /* To cut down on the ifdef stuff a little bit in other places */5 #ifdef IPV66 #define AF_INETx AF_INET67 #else8 #define AF_INETx AF_INET9 #endif10 3 11 4 #ifndef _WIN32
Note: See TracChangeset
for help on using the changeset viewer.