4 * locate the originating host
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
25 #include "dynloader.h"
26 #include "locate_host.h"
27 #include "sysdep_decls.h"
31 void locate_host(char *tbuf, const struct in_addr *addr)
37 lprintf(9, "locate_host() called\n");
39 #ifdef HAVE_NONREENTRANT_NETDB
40 begin_critical_section(S_NETDB);
43 if ((ch = gethostbyaddr((char *) addr, sizeof(*addr), AF_INET)) ==
51 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
52 goto end; /* because we might need to end the critical
55 /* check if the forward DNS agrees; if not, they're spoofing */
56 i = strdoop(ch->h_name);
57 ch = gethostbyname(i);
62 /* check address for consistency */
63 for (; *ch->h_addr_list; ch->h_addr_list++)
64 if (!memcmp(*ch->h_addr_list, addr,
66 safestrncpy(tbuf, ch->h_name, 63);
69 goto bad_dns; /* they were spoofing. report a numeric IP
74 #ifdef HAVE_NONREENTRANT_NETDB
75 end_critical_section(S_NETDB);
79 lprintf(9, "locate_host() exiting\n");