version 1.1, 1999/09/26 20:53:34 |
version 1.2, 1999/09/29 21:14:16 |
|
|
struct sockaddr_in from; |
struct sockaddr_in from; |
int fromlen, i; |
int fromlen, i; |
struct hostent *hp; |
struct hostent *hp; |
char name[512]; |
char name[MAXHOSTNAMELEN]; |
|
|
/* Get IP address of client. */ |
/* Get IP address of client. */ |
fromlen = sizeof(from); |
fromlen = sizeof(from); |
|
|
if (getpeername(socket, (struct sockaddr *)&from, &fromlen) < 0) |
if (getpeername(socket, (struct sockaddr *)&from, &fromlen) < 0) |
{ |
{ |
error("getpeername failed: %.100s", strerror(errno)); |
error("getpeername failed: %.100s", strerror(errno)); |
strcpy(name, "UNKNOWN"); |
strlcpy(name, "UNKNOWN", sizeof name); |
goto check_ip_options; |
goto check_ip_options; |
} |
} |
|
|
|
|
{ |
{ |
/* Got host name, find canonic host name. */ |
/* Got host name, find canonic host name. */ |
if (strchr(hp->h_name, '.') != 0) |
if (strchr(hp->h_name, '.') != 0) |
strncpy(name, hp->h_name, sizeof(name)); |
strlcpy(name, hp->h_name, sizeof(name)); |
else if (hp->h_aliases != 0 |
else if (hp->h_aliases != 0 |
&& hp->h_aliases[0] != 0 |
&& hp->h_aliases[0] != 0 |
&& strchr(hp->h_aliases[0], '.') != 0) |
&& strchr(hp->h_aliases[0], '.') != 0) |
strncpy(name, hp->h_aliases[0], sizeof(name)); |
strlcpy(name, hp->h_aliases[0], sizeof(name)); |
else |
else |
strncpy(name, hp->h_name, sizeof(name)); |
strlcpy(name, hp->h_name, sizeof(name)); |
name[sizeof(name) - 1] = '\0'; |
|
|
|
/* Convert it to all lowercase (which is expected by the rest of this |
/* Convert it to all lowercase (which is expected by the rest of this |
software). */ |
software). */ |
|
|
if (!hp) |
if (!hp) |
{ |
{ |
log("reverse mapping checking gethostbyname for %.700s failed - POSSIBLE BREAKIN ATTEMPT!", name); |
log("reverse mapping checking gethostbyname for %.700s failed - POSSIBLE BREAKIN ATTEMPT!", name); |
strcpy(name, inet_ntoa(from.sin_addr)); |
strlcpy(name, inet_ntoa(from.sin_addr), sizeof name); |
goto check_ip_options; |
goto check_ip_options; |
} |
} |
/* Look for the address from the list of addresses. */ |
/* Look for the address from the list of addresses. */ |
|
|
/* Address not found for the host name. */ |
/* Address not found for the host name. */ |
log("Address %.100s maps to %.600s, but this does not map back to the address - POSSIBLE BREAKIN ATTEMPT!", |
log("Address %.100s maps to %.600s, but this does not map back to the address - POSSIBLE BREAKIN ATTEMPT!", |
inet_ntoa(from.sin_addr), name); |
inet_ntoa(from.sin_addr), name); |
strcpy(name, inet_ntoa(from.sin_addr)); |
strlcpy(name, inet_ntoa(from.sin_addr), sizeof name); |
goto check_ip_options; |
goto check_ip_options; |
} |
} |
/* Address was found for the host name. We accept the host name. */ |
/* Address was found for the host name. We accept the host name. */ |
|
|
else |
else |
{ |
{ |
/* Host name not found. Use ascii representation of the address. */ |
/* Host name not found. Use ascii representation of the address. */ |
strcpy(name, inet_ntoa(from.sin_addr)); |
strlcpy(name, inet_ntoa(from.sin_addr), sizeof name); |
log("Could not reverse map address %.100s.", name); |
log("Could not reverse map address %.100s.", name); |
} |
} |
|
|