version 1.29, 2001/12/19 07:18:56 |
version 1.30, 2002/01/29 14:32:03 |
|
|
*/ |
*/ |
|
|
static char * |
static char * |
get_remote_hostname(int socket, int reverse_mapping_check) |
get_remote_hostname(int socket, int verify_reverse_mapping) |
{ |
{ |
struct sockaddr_storage from; |
struct sockaddr_storage from; |
int i; |
int i; |
|
|
if (isupper(name[i])) |
if (isupper(name[i])) |
name[i] = tolower(name[i]); |
name[i] = tolower(name[i]); |
|
|
if (!reverse_mapping_check) |
if (!verify_reverse_mapping) |
return xstrdup(name); |
return xstrdup(name); |
/* |
/* |
* Map it back to an IP address and check that the given |
* Map it back to an IP address and check that the given |
|
|
*/ |
*/ |
|
|
const char * |
const char * |
get_canonical_hostname(int reverse_mapping_check) |
get_canonical_hostname(int verify_reverse_mapping) |
{ |
{ |
static char *canonical_host_name = NULL; |
static char *canonical_host_name = NULL; |
static int reverse_mapping_checked = 0; |
static int verify_reverse_mapping_done = 0; |
|
|
/* Check if we have previously retrieved name with same option. */ |
/* Check if we have previously retrieved name with same option. */ |
if (canonical_host_name != NULL) { |
if (canonical_host_name != NULL) { |
if (reverse_mapping_checked != reverse_mapping_check) |
if (verify_reverse_mapping_done != verify_reverse_mapping) |
xfree(canonical_host_name); |
xfree(canonical_host_name); |
else |
else |
return canonical_host_name; |
return canonical_host_name; |
|
|
/* Get the real hostname if socket; otherwise return UNKNOWN. */ |
/* Get the real hostname if socket; otherwise return UNKNOWN. */ |
if (packet_connection_is_on_socket()) |
if (packet_connection_is_on_socket()) |
canonical_host_name = get_remote_hostname( |
canonical_host_name = get_remote_hostname( |
packet_get_connection_in(), reverse_mapping_check); |
packet_get_connection_in(), verify_reverse_mapping); |
else |
else |
canonical_host_name = xstrdup("UNKNOWN"); |
canonical_host_name = xstrdup("UNKNOWN"); |
|
|
reverse_mapping_checked = reverse_mapping_check; |
verify_reverse_mapping_done = verify_reverse_mapping; |
return canonical_host_name; |
return canonical_host_name; |
} |
} |
|
|
|
|
} |
} |
|
|
const char * |
const char * |
get_remote_name_or_ip(u_int utmp_len, int reverse_mapping_check) |
get_remote_name_or_ip(u_int utmp_len, int verify_reverse_mapping) |
{ |
{ |
static const char *remote = ""; |
static const char *remote = ""; |
if (utmp_len > 0) |
if (utmp_len > 0) |
remote = get_canonical_hostname(reverse_mapping_check); |
remote = get_canonical_hostname(verify_reverse_mapping); |
if (utmp_len == 0 || strlen(remote) > utmp_len) |
if (utmp_len == 0 || strlen(remote) > utmp_len) |
remote = get_remote_ipaddr(); |
remote = get_remote_ipaddr(); |
return remote; |
return remote; |