2 * locate the originating host
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
22 #include "locate_host.h"
25 void locate_host(char *tbuf)
27 struct sockaddr_in cs;
28 struct hostent *ch, *ch2;
34 if (getpeername(CC->client_socket, (struct sockaddr *) &cs, &len) < 0) {
35 strcpy(tbuf, config.c_fqdn);
38 #ifdef HAVE_NONREENTRANT_NETDB
39 begin_critical_section(S_NETDB);
42 if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
45 i = (char *) &cs.sin_addr;
50 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
51 goto end; /* because we might need to end the critical
54 /* check if the forward DNS agrees; if not, they're spoofing */
55 if ((ch2 = gethostbyname(ch->h_name)) == NULL)
58 /* check address for consistency */
59 for (; *ch2->h_addr_list; ch2->h_addr_list++)
60 if (!memcmp(*ch2->h_addr_list, &cs.sin_addr,
61 sizeof cs.sin_addr)) {
62 strncpy(tbuf, ch->h_name, 24);
65 goto bad_dns; /* they were spoofing. report a numeric IP
70 #ifdef HAVE_NONREENTRANT_NETDB
71 end_critical_section(S_NETDB);