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"
23 void locate_host(char *tbuf, const struct in_addr *addr)
29 #ifdef HAVE_NONREENTRANT_NETDB
30 begin_critical_section(S_NETDB);
33 if ((ch = gethostbyaddr((char *) addr, sizeof(*addr), AF_INET)) ==
41 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
42 goto end; /* because we might need to end the critical
45 /* check if the forward DNS agrees; if not, they're spoofing */
46 i = strdoop(ch->h_name);
47 ch = gethostbyname(i);
52 /* check address for consistency */
53 for (; *ch->h_addr_list; ch->h_addr_list++)
54 if (!memcmp(*ch->h_addr_list, addr,
56 safestrncpy(tbuf, ch->h_name, 25);
59 goto bad_dns; /* they were spoofing. report a numeric IP
64 #ifdef HAVE_NONREENTRANT_NETDB
65 end_critical_section(S_NETDB);