Mercurial > dovecot > core-2.2
changeset 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 | a6b00756ab2c |
children | 1fbac590b9d4 |
files | src/lib/net.c src/lib/net.h |
diffstat | 2 files changed, 21 insertions(+), 0 deletions(-) [+] |
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;
--- 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