2 * locate the originating host
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
19 #include "locate_host.h"
20 #include "sysdep_decls.h"
24 void locate_host(char *tbuf, const struct in_addr *addr)
30 lprintf(9, "locate_host() called\n");
32 #ifdef HAVE_NONREENTRANT_NETDB
33 begin_critical_section(S_NETDB);
36 if ((ch = gethostbyaddr((char *) addr, sizeof(*addr), AF_INET)) ==
44 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
45 goto end; /* because we might need to end the critical
48 /* check if the forward DNS agrees; if not, they're spoofing */
49 i = strdoop(ch->h_name);
50 ch = gethostbyname(i);
55 /* check address for consistency */
56 for (; *ch->h_addr_list; ch->h_addr_list++)
57 if (!memcmp(*ch->h_addr_list, addr,
59 safestrncpy(tbuf, ch->h_name, 25);
62 goto bad_dns; /* they were spoofing. report a numeric IP
67 #ifdef HAVE_NONREENTRANT_NETDB
68 end_critical_section(S_NETDB);
72 lprintf(9, "locate_host() exiting\n");