summaryrefslogtreecommitdiff
path: root/src/resolv
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2013-04-30 16:40:00 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-05-03 20:25:46 +0200
commita398adc5b40381fc567a2aee1841b26af78aea17 (patch)
tree4de66827028e07dd9faf66f605c83050ad23afd6 /src/resolv
parent5a4239490c7fb7d732180a9d40f27f0247c56631 (diff)
downloadsssd-a398adc5b40381fc567a2aee1841b26af78aea17.tar.gz
sssd-a398adc5b40381fc567a2aee1841b26af78aea17.tar.bz2
sssd-a398adc5b40381fc567a2aee1841b26af78aea17.zip
resolver: Return PTR record as string
This is a requirement to update the PTR records. Includes a unit test.
Diffstat (limited to 'src/resolv')
-rw-r--r--src/resolv/async_resolv.c36
-rw-r--r--src/resolv/async_resolv.h4
2 files changed, 40 insertions, 0 deletions
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c
index 60d9e05b..f673a25c 100644
--- a/src/resolv/async_resolv.c
+++ b/src/resolv/async_resolv.c
@@ -1416,6 +1416,42 @@ resolv_get_string_address_index(TALLOC_CTX *mem_ctx,
return address;
}
+char *
+resolv_get_string_ptr_address(TALLOC_CTX *mem_ctx,
+ int family, uint8_t *address)
+{
+ char *straddr;
+
+ if (family == AF_INET6) {
+ int i;
+ char hexbyte[3];
+
+ straddr = talloc_strdup(mem_ctx, "\0");
+ if (!straddr) {
+ return NULL;
+ }
+
+ for (i = 15; i >= 0; i--) {
+ snprintf(hexbyte, 3, "%02x", address[i]);
+ straddr = talloc_asprintf_append(straddr, "%c.%c.",
+ hexbyte[1], hexbyte[0]);
+ }
+ straddr = talloc_asprintf_append(straddr, "ip6.arpa.");
+ } else if (family == AF_INET) {
+ straddr = talloc_asprintf(mem_ctx,
+ "%u.%u.%u.%u.in-addr.arpa.",
+ (address[3]),
+ (address[2]),
+ (address[1]),
+ (address[0]));
+ } else {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Unknown address family\n"));
+ return NULL;
+ }
+
+ return straddr;
+}
+
struct sockaddr_storage *
resolv_get_sockaddr_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent,
int port)
diff --git a/src/resolv/async_resolv.h b/src/resolv/async_resolv.h
index 3a025588..d759a82f 100644
--- a/src/resolv/async_resolv.h
+++ b/src/resolv/async_resolv.h
@@ -121,6 +121,10 @@ resolv_get_string_address_index(TALLOC_CTX *mem_ctx,
struct resolv_hostent *hostent,
unsigned int addrindex);
+char *
+resolv_get_string_ptr_address(TALLOC_CTX *mem_ctx,
+ int family, uint8_t *address);
+
#define resolv_get_string_address(mem_ctx, hostent) \
resolv_get_string_address_index(mem_ctx, hostent, 0)