4 * locate the originating host
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
21 #include "locate_host.h"
22 #include "sysdep_decls.h"
26 void locate_host(char *tbuf, const struct in_addr *addr)
32 lprintf(9, "locate_host() called\n");
34 #ifdef HAVE_NONREENTRANT_NETDB
35 begin_critical_section(S_NETDB);
38 if ((ch = gethostbyaddr((char *) addr, sizeof(*addr), AF_INET)) ==
46 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
47 goto end; /* because we might need to end the critical
50 /* check if the forward DNS agrees; if not, they're spoofing */
51 i = strdoop(ch->h_name);
52 ch = gethostbyname(i);
57 /* check address for consistency */
58 for (; *ch->h_addr_list; ch->h_addr_list++)
59 if (!memcmp(*ch->h_addr_list, addr,
61 safestrncpy(tbuf, ch->h_name, 25);
64 goto bad_dns; /* they were spoofing. report a numeric IP
69 #ifdef HAVE_NONREENTRANT_NETDB
70 end_critical_section(S_NETDB);
74 lprintf(9, "locate_host() exiting\n");