Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

canohost.h File Reference

Go to the source code of this file.

Functions

const charget_canonical_hostname (int)
const charget_remote_ipaddr (void)
const charget_remote_name_or_ip (u_int, int)
charget_peer_ipaddr (int)
int get_peer_port (int)
charget_local_ipaddr (int)
charget_local_name (int)
int get_remote_port (void)
int get_local_port (void)
void ipv64_normalise_mapped (struct sockaddr_storage *, socklen_t *)


Function Documentation

const char* get_canonical_hostname int   ) 
 

Definition at line 199 of file canohost.c.

References get_remote_hostname(), host, packet_connection_is_on_socket(), and packet_get_connection_in().

Referenced by allowed_user(), auth_log(), auth_parse_options(), auth_rhosts(), auth_rhosts_rsa(), get_remote_name_or_ip(), getpwnamallow(), hostbased_key_allowed(), and main().

00200 {
00201         char *host;
00202         static char *canonical_host_name = NULL;
00203         static char *remote_ip = NULL;
00204 
00205         /* Check if we have previously retrieved name with same option. */
00206         if (use_dns && canonical_host_name != NULL)
00207                 return canonical_host_name;
00208         if (!use_dns && remote_ip != NULL)
00209                 return remote_ip;
00210 
00211         /* Get the real hostname if socket; otherwise return UNKNOWN. */
00212         if (packet_connection_is_on_socket())
00213                 host = get_remote_hostname(packet_get_connection_in(), use_dns);
00214         else
00215                 host = "UNKNOWN";
00216 
00217         if (use_dns)
00218                 canonical_host_name = host;
00219         else
00220                 remote_ip = host;
00221         return host;
00222 }

char* get_local_ipaddr int   ) 
 

Definition at line 277 of file canohost.c.

References get_socket_address(), NI_NUMERICHOST, and xstrdup().

Referenced by do_setup_env().

00278 {
00279         char *p;
00280 
00281         if ((p = get_socket_address(sock, 0, NI_NUMERICHOST)) != NULL)
00282                 return p;
00283         return xstrdup("UNKNOWN");
00284 }

char* get_local_name int   ) 
 

Definition at line 287 of file canohost.c.

References get_socket_address(), and NI_NAMEREQD.

Referenced by main(), and userauth_hostbased().

00288 {
00289         return get_socket_address(sock, 0, NI_NAMEREQD);
00290 }

int get_local_port void   ) 
 

Definition at line 400 of file canohost.c.

References get_port().

Referenced by do_setup_env().

00401 {
00402         return get_port(1);
00403 }

char* get_peer_ipaddr int   ) 
 

Definition at line 267 of file canohost.c.

References get_socket_address(), NI_NUMERICHOST, and xstrdup().

Referenced by channel_post_x11_listener(), get_remote_ipaddr(), and port_open_helper().

00268 {
00269         char *p;
00270 
00271         if ((p = get_socket_address(sock, 1, NI_NUMERICHOST)) != NULL)
00272                 return p;
00273         return xstrdup("UNKNOWN");
00274 }

int get_peer_port int   ) 
 

Definition at line 382 of file canohost.c.

References get_sock_port().

Referenced by channel_post_x11_listener(), and port_open_helper().

00383 {
00384         return get_sock_port(sock, 0);
00385 }

const char* get_remote_ipaddr void   ) 
 

Definition at line 298 of file canohost.c.

References cleanup_exit(), get_peer_ipaddr(), packet_connection_is_on_socket(), packet_get_connection_in(), and xstrdup().

Referenced by allowed_user(), auth_log(), auth_parse_options(), auth_rhosts(), auth_root_allowed(), do_setup_env(), do_ssh1_kex(), get_remote_name_or_ip(), getpwnamallow(), grace_alarm_handler(), hostbased_key_allowed(), packet_read_poll_seqnr(), packet_read_seqnr(), process_input(), ssh1_session_key(), and sshd_exchange_identification().

00299 {
00300         static char *canonical_host_ip = NULL;
00301 
00302         /* Check whether we have cached the ipaddr. */
00303         if (canonical_host_ip == NULL) {
00304                 if (packet_connection_is_on_socket()) {
00305                         canonical_host_ip =
00306                             get_peer_ipaddr(packet_get_connection_in());
00307                         if (canonical_host_ip == NULL)
00308                                 cleanup_exit(255);
00309                 } else {
00310                         /* If not on socket, return UNKNOWN. */
00311                         canonical_host_ip = xstrdup("UNKNOWN");
00312                 }
00313         }
00314         return canonical_host_ip;
00315 }

const char* get_remote_name_or_ip u_int  ,
int 
 

Definition at line 318 of file canohost.c.

References get_canonical_hostname(), and get_remote_ipaddr().

Referenced by do_child(), do_login(), and mm_record_login().

00319 {
00320         static const char *remote = "";
00321         if (utmp_len > 0)
00322                 remote = get_canonical_hostname(use_dns);
00323         if (utmp_len == 0 || strlen(remote) > utmp_len)
00324                 remote = get_remote_ipaddr();
00325         return remote;
00326 }

int get_remote_port void   ) 
 

Definition at line 388 of file canohost.c.

References get_port().

Referenced by auth_log(), do_setup_env(), and main().

00389 {
00390         static int port = -1;
00391 
00392         /* Cache to avoid getpeername() on a dead connection */
00393         if (port == -1)
00394                 port = get_port(0);
00395 
00396         return port;
00397 }

void ipv64_normalise_mapped struct sockaddr_storage ,
socklen_t * 
 

Definition at line 168 of file canohost.c.

References AF_INET6, debug3(), IN6_IS_ADDR_V4MAPPED, sockaddr_in6::sin6_addr, and sockaddr_in6::sin6_port.

Referenced by get_remote_hostname(), and get_socket_address().

00169 {
00170         struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)addr;
00171         struct sockaddr_in *a4 = (struct sockaddr_in *)addr;
00172         struct in_addr inaddr;
00173         u_int16_t port;
00174 
00175         if (addr->ss_family != AF_INET6 ||
00176             !IN6_IS_ADDR_V4MAPPED(&a6->sin6_addr))
00177                 return;
00178 
00179         debug3("Normalising mapped IPv4 in IPv6 address");
00180 
00181         memcpy(&inaddr, ((char *)&a6->sin6_addr) + 12, sizeof(inaddr));
00182         port = a6->sin6_port;
00183 
00184         memset(addr, 0, sizeof(*a4));
00185 
00186         a4->sin_family = AF_INET;
00187         *len = sizeof(*a4);
00188         memcpy(&a4->sin_addr, &inaddr, sizeof(inaddr));
00189         a4->sin_port = port;
00190 }


© sourcejam.com 2005-2008