version 1.42, 2005/02/18 03:05:53 |
version 1.42.2.2, 2006/02/03 02:53:44 |
|
|
cleanup_exit(255); |
cleanup_exit(255); |
} |
} |
|
|
if (from.ss_family == AF_INET) |
|
check_ip_options(sock, ntop); |
|
|
|
if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop), |
if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop), |
NULL, 0, NI_NUMERICHOST) != 0) |
NULL, 0, NI_NUMERICHOST) != 0) |
fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed"); |
fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed"); |
|
|
|
if (from.ss_family == AF_INET) |
|
check_ip_options(sock, ntop); |
|
|
if (!use_dns) |
if (!use_dns) |
return xstrdup(ntop); |
return xstrdup(ntop); |
|
|
|
|
hints.ai_socktype = SOCK_STREAM; |
hints.ai_socktype = SOCK_STREAM; |
if (getaddrinfo(name, NULL, &hints, &aitop) != 0) { |
if (getaddrinfo(name, NULL, &hints, &aitop) != 0) { |
logit("reverse mapping checking getaddrinfo for %.700s " |
logit("reverse mapping checking getaddrinfo for %.700s " |
"failed - POSSIBLE BREAKIN ATTEMPT!", name); |
"failed - POSSIBLE BREAK-IN ATTEMPT!", name); |
return xstrdup(ntop); |
return xstrdup(ntop); |
} |
} |
/* Look for the address from the list of addresses. */ |
/* Look for the address from the list of addresses. */ |
|
|
if (!ai) { |
if (!ai) { |
/* Address not found for the host name. */ |
/* Address not found for the host name. */ |
logit("Address %.100s maps to %.600s, but this does not " |
logit("Address %.100s maps to %.600s, but this does not " |
"map back to the address - POSSIBLE BREAKIN ATTEMPT!", |
"map back to the address - POSSIBLE BREAK-IN ATTEMPT!", |
ntop, name); |
ntop, name); |
return xstrdup(ntop); |
return xstrdup(ntop); |
} |
} |
|
|
u_char options[200]; |
u_char options[200]; |
char text[sizeof(options) * 3 + 1]; |
char text[sizeof(options) * 3 + 1]; |
socklen_t option_size; |
socklen_t option_size; |
int i, ipproto; |
u_int i; |
|
int ipproto; |
struct protoent *ip; |
struct protoent *ip; |
|
|
if ((ip = getprotobyname("ip")) != NULL) |
if ((ip = getprotobyname("ip")) != NULL) |
|
|
for (i = 0; i < option_size; i++) |
for (i = 0; i < option_size; i++) |
snprintf(text + i*3, sizeof(text) - i*3, |
snprintf(text + i*3, sizeof(text) - i*3, |
" %2.2x", options[i]); |
" %2.2x", options[i]); |
logit("Connection from %.100s with IP options:%.800s", |
fatal("Connection from %.100s with IP options:%.800s", |
ipaddr, text); |
ipaddr, text); |
packet_disconnect("Connection from %.100s with IP options:%.800s", |
|
ipaddr, text); |
|
} |
} |
} |
} |
|
|
|
|
const char * |
const char * |
get_canonical_hostname(int use_dns) |
get_canonical_hostname(int use_dns) |
{ |
{ |
|
char *host; |
static char *canonical_host_name = NULL; |
static char *canonical_host_name = NULL; |
static int use_dns_done = 0; |
static char *remote_ip = NULL; |
|
|
/* 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 (use_dns && canonical_host_name != NULL) |
if (use_dns_done != use_dns) |
return canonical_host_name; |
xfree(canonical_host_name); |
if (!use_dns && remote_ip != NULL) |
else |
return remote_ip; |
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( |
host = get_remote_hostname(packet_get_connection_in(), use_dns); |
packet_get_connection_in(), use_dns); |
|
else |
else |
canonical_host_name = xstrdup("UNKNOWN"); |
host = "UNKNOWN"; |
|
|
use_dns_done = use_dns; |
if (use_dns) |
return canonical_host_name; |
canonical_host_name = host; |
|
else |
|
remote_ip = host; |
|
return host; |
} |
} |
|
|
/* |
/* |
|
|
} else { |
} else { |
if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) { |
if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) { |
debug("getpeername failed: %.100s", strerror(errno)); |
debug("getpeername failed: %.100s", strerror(errno)); |
cleanup_exit(255); |
return -1; |
} |
} |
} |
} |
/* Return port number. */ |
/* Return port number. */ |