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, size_t n, const struct in_addr *addr)
38 lprintf(9, "locate_host() called\n");
40 #ifdef HAVE_NONREENTRANT_NETDB
41 begin_critical_section(S_NETDB);
44 if ((ch = gethostbyaddr((const char *) addr, sizeof(*addr), AF_INET)) ==
47 i = (const char *) addr;
52 snprintf(tbuf, n, "%d.%d.%d.%d", a1, a2, a3, a4);
53 goto end; /* because we might need to end the critical
56 /* check if the forward DNS agrees; if not, they're spoofing */
57 j = strdoop(ch->h_name);
58 ch = gethostbyname(j);
63 /* check address for consistency */
64 for (; *ch->h_addr_list; ch->h_addr_list++)
65 if (!memcmp(*ch->h_addr_list, addr,
67 safestrncpy(tbuf, ch->h_name, 63);
70 goto bad_dns; /* they were spoofing. report a numeric IP
75 #ifdef HAVE_NONREENTRANT_NETDB
76 end_critical_section(S_NETDB);
80 lprintf(9, "locate_host() exiting\n");