- Timestamp:
- 2007-10-18T16:44:25Z (17 years ago)
- Branches:
- master
- Children:
- 7435ccf
- Parents:
- c511365
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.c
rc511365 re9b755e 45 45 { 46 46 irc_t *irc; 47 struct hostent *peer; 48 unsigned int i; 49 char buf[128]; 50 #ifdef IPV6 51 struct sockaddr_in6 sock6[1]; 52 unsigned int i6; 53 #endif 54 struct sockaddr_in sock[1]; 47 struct sockaddr_storage sock; 48 socklen_t socklen = sizeof(sock); 55 49 56 50 irc = g_new0( irc_t, 1 ); … … 71 65 irc->channel = g_strdup( ROOT_CHAN ); 72 66 73 i = sizeof( *sock );74 #ifdef IPV675 i6 = sizeof( *sock6 );76 #endif77 78 67 if( global.conf->hostname ) 79 68 irc->myhost = g_strdup( global.conf->hostname ); 80 #ifdef IPV6 81 else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 82 { 83 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 84 irc->myhost = g_strdup( peer->h_name ); 85 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 86 irc->myhost = g_strdup( ipv6_unwrap( buf ) ); 87 } 88 #endif 89 else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 90 { 91 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 92 irc->myhost = g_strdup( peer->h_name ); 93 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 94 irc->myhost = g_strdup( buf ); 95 } 96 97 i = sizeof( *sock ); 98 #ifdef IPV6 99 i6 = sizeof( *sock6 ); 100 if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) 101 { 102 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) 103 irc->host = g_strdup( peer->h_name ); 104 else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) 105 irc->host = g_strdup( ipv6_unwrap( buf ) ); 106 } 107 else 108 #endif 109 if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) 110 { 111 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) 112 irc->host = g_strdup( peer->h_name ); 113 else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) 114 irc->host = g_strdup( buf ); 115 } 116 117 /* Rare, but possible. */ 118 if( !irc->host ) irc->host = g_strdup( "localhost." ); 119 if( !irc->myhost ) irc->myhost = g_strdup( "localhost." ); 120 69 else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0) 70 { 71 irc->myhost = g_new0(char, NI_MAXHOST); 72 73 if (getnameinfo((struct sockaddr *)&sock, socklen, irc->myhost, 74 NI_MAXHOST, NULL, -1, 0)) { 75 /* Rare, but possible. */ 76 strncpy(irc->myhost, "localhost.", NI_MAXHOST); 77 } 78 } 79 80 if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0) 81 { 82 irc->host = g_new0(char, NI_MAXHOST); 83 84 if (getnameinfo((struct sockaddr *)&sock, socklen, irc->host, 85 NI_MAXHOST, NULL, -1, 0)) { 86 /* Rare, but possible. */ 87 strncpy(irc->myhost, "localhost.", NI_MAXHOST); 88 } 89 } 90 121 91 if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 ) 122 92 irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
Note: See TracChangeset
for help on using the changeset viewer.