]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added net_gethostbyaddr() for DNS PTR lookups.
authorTimo Sirainen <tss@iki.fi>
Fri, 28 Jun 2013 16:48:15 +0000 (19:48 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 28 Jun 2013 16:48:15 +0000 (19:48 +0300)
This code assumes we have IPv6 capability. Perhaps we should just require it
everywhere already..

src/lib/net.c
src/lib/net.h

index 4162bf1f1d588fef977669df3bae8bbd2c42aaf3..b78657b34f0b5bdee6c8130ff2797a24f189523a 100644 (file)
@@ -663,6 +663,24 @@ int net_gethostbyname(const char *addr, struct ip_addr **ips,
        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;
index ed084e0fee706ffe6ece52c612d97b1f6be28e3a..6248733576d259587b16110c5a2aa1678599fbff 100644 (file)
@@ -105,6 +105,9 @@ ssize_t net_transmit(int fd, const void *data, size_t len);
    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