-#ifdef HAVE_NONREENTRANT_NETDB
- begin_critical_section(S_NETDB);
-#endif
-
- i = (const char *) addr;
- a1 = ((*i++) & 0xff);
- a2 = ((*i++) & 0xff);
- a3 = ((*i++) & 0xff);
- a4 = ((*i++) & 0xff);
- sprintf(address_string, "%d.%d.%d.%d", a1, a2, a3, a4);
-
- if (abuf != NULL) {
- safestrncpy(abuf, address_string, na);
- }
-
- if ((ch = gethostbyaddr((const char *) addr,
- sizeof(*addr), AF_INET)) == NULL) {
-bad_dns:
- safestrncpy(tbuf, address_string, n);
- goto end; /* because we might need to end the critical
- section */
- }
- /* check if the forward DNS agrees; if not, they're spoofing */
- j = strdup(ch->h_name);
- ch = gethostbyname(j);
- free(j);
- if (ch == NULL)
- goto bad_dns;
-
- /* check address for consistency */
- for (; *ch->h_addr_list; ch->h_addr_list++)
- if (!memcmp(*ch->h_addr_list, addr,
- sizeof *addr)) {
- safestrncpy(tbuf, ch->h_name, 63);
- goto end;
- }
- goto bad_dns; /* they were spoofing. report a numeric IP
- address. */
-
- end:
-
-#ifdef HAVE_NONREENTRANT_NETDB
- end_critical_section(S_NETDB);
-#endif