con->cs_host[sizeof con->cs_host - 1] = 0;
len = sizeof sin;
if (!CC->is_local_socket) {
- if (!getpeername(con->client_socket, (struct sockaddr *) &sin, &len)) {
- locate_host(con->cs_host, sizeof con->cs_host,
- con->cs_addr, sizeof con->cs_addr,
- &sin.sin_addr
- );
- }
+ locate_host(con->cs_host, sizeof con->cs_host,
+ con->cs_addr, sizeof con->cs_addr,
+ con->client_socket
+ );
}
else {
- strcpy(con->cs_host, "");
+ con->cs_host[0] = 0;
+ con->cs_addr[0] = 0;
#ifdef HAVE_STRUCT_UCRED
{
/* as http://www.wsinnovations.com/softeng/articles/uds.html told us... */
#endif
-/* Hacks to work around nameser.h declarations missing on OpenBSD
- * see also: http://search.cpan.org/src/MIKER/Net-DNS-ToolKit-0.30/ToolKit.h
- */
-
-#ifndef NS_INT16SZ
-# ifdef INT16SZ
-# define NS_INT16SZ INT16SZ
-# endif
-#endif
-
-#ifndef NS_INT32SZ
-# ifdef INT32SZ
-# define NS_INT32SZ INT32SZ
-# endif
-#endif
-
-#ifndef NS_GET16
-# ifdef GETSHORT
-# define NS_GET16 GETSHORT
-# endif
-#endif
-
-
-/***************************************************************************/
-
-
-void locate_host(char *tbuf, size_t n,
- char *abuf, size_t na,
- const struct in_addr *addr)
+void locate_host(char *tbuf, size_t n, char *abuf, size_t na, int client_socket)
{
- struct hostent *ch;
- const char *i;
- char *j;
- int a1, a2, a3, a4;
- char address_string[SIZ];
-
+ struct sockaddr_in6 clientaddr;
+ unsigned int addrlen = sizeof(clientaddr);
-#ifdef HAVE_NONREENTRANT_NETDB
- begin_critical_section(S_NETDB);
-#endif
-
- i = (const char *) addr;
- a1 = ((*i++) & 0xff);
- a2 = ((*i++) & 0xff);
- a3 = ((*i++) & 0xff);
- a4 = ((*i++) & 0xff);
- sprintf(address_string, "%d.%d.%d.%d", a1, a2, a3, a4);
-
- if (abuf != NULL) {
- safestrncpy(abuf, address_string, na);
- }
-
- if ((ch = gethostbyaddr((const char *) addr,
- sizeof(*addr), AF_INET)) == NULL) {
-bad_dns:
- safestrncpy(tbuf, address_string, n);
- goto end; /* because we might need to end the critical
- section */
- }
- /* check if the forward DNS agrees; if not, they're spoofing */
- j = strdup(ch->h_name);
- ch = gethostbyname(j);
- free(j);
- if (ch == NULL)
- goto bad_dns;
-
- /* check address for consistency */
- for (; *ch->h_addr_list; ch->h_addr_list++)
- if (!memcmp(*ch->h_addr_list, addr,
- sizeof *addr)) {
- safestrncpy(tbuf, ch->h_name, 63);
- goto end;
- }
- goto bad_dns; /* they were spoofing. report a numeric IP
- address. */
-
- end:
-
-#ifdef HAVE_NONREENTRANT_NETDB
- end_critical_section(S_NETDB);
-#endif
+ tbuf[0] = 0;
+ abuf[0] = 0;
- tbuf[63] = 0;
+ getpeername(client_socket, (struct sockaddr *)&clientaddr, &addrlen);
+ getnameinfo((struct sockaddr *)&clientaddr, addrlen, tbuf, n, NULL, 0, 0);
+ getnameinfo((struct sockaddr *)&clientaddr, addrlen, abuf, na, NULL, 0, NI_NUMERICHOST);
}
/* $Id$ */
-void locate_host(char *tbuf, size_t n,
- char *abuf, size_t na,
- const struct in_addr *addr);
+void locate_host(char *tbuf, size_t n, char *abuf, size_t na, int client_socket);
int rbl_check(char *message_to_spammer);
int hostname_to_dotted_quad(char *addr, char *host);
int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize);