diff src/lib/net.c @ 16575:eaa712530f3f

Added net_gethostbyaddr() for DNS PTR lookups. This code assumes we have IPv6 capability. Perhaps we should just require it everywhere already..
author Timo Sirainen <tss@iki.fi>
date Fri, 28 Jun 2013 19:48:15 +0300
parents c802c0b960e2
children dc60e46f0cb5
line wrap: on
line diff
--- 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;