dovecot-2.2: Added net_gethostbyaddr() for DNS PTR lookups.

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 28 19:48:48 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/eaa712530f3f
changeset: 16575:eaa712530f3f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 28 19:48:15 2013 +0300
description:
Added net_gethostbyaddr() for DNS PTR lookups.
This code assumes we have IPv6 capability. Perhaps we should just require it
everywhere already..

diffstat:

 src/lib/net.c |  18 ++++++++++++++++++
 src/lib/net.h |   3 +++
 2 files changed, 21 insertions(+), 0 deletions(-)

diffs (41 lines):

diff -r a6b00756ab2c -r eaa712530f3f src/lib/net.c
--- a/src/lib/net.c	Thu Jun 27 23:07:20 2013 +0300
+++ b/src/lib/net.c	Fri Jun 28 19:48:15 2013 +0300
@@ -663,6 +663,24 @@
 	return 0;
 }
 
+int net_gethostbyaddr(const struct ip_addr *ip, const char **name_r)
+{
+	union sockaddr_union so;
+	socklen_t addrlen = sizeof(so);
+	char hbuf[NI_MAXHOST];
+	int ret;
+
+	memset(&so, 0, sizeof(so));
+	sin_set_ip(&so, ip);
+	ret = getnameinfo(&so.sa, addrlen, hbuf, sizeof(hbuf), NULL, 0,
+			  NI_NAMEREQD);
+	if (ret != 0)
+		return ret;
+
+	*name_r = t_strdup(hbuf);
+	return 0;
+}
+
 int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
 {
 	union sockaddr_union so;
diff -r a6b00756ab2c -r eaa712530f3f src/lib/net.h
--- a/src/lib/net.h	Thu Jun 27 23:07:20 2013 +0300
+++ b/src/lib/net.h	Fri Jun 28 19:48:15 2013 +0300
@@ -105,6 +105,9 @@
    to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */
 int net_gethostbyname(const char *addr, struct ip_addr **ips,
 		      unsigned int *ips_count);
+/* Return host for the IP address. Returns 0 = ok, others = error code for
+   net_gethosterror(). */
+int net_gethostbyaddr(const struct ip_addr *ip, const char **name_r);
 /* get error of net_gethostname() */
 const char *net_gethosterror(int error) ATTR_CONST;
 /* return TRUE if host lookup failed because it didn't exist (ie. not


More information about the dovecot-cvs mailing list