diff options
author | Sumit Bose <sbose@redhat.com> | 2011-06-27 10:03:03 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-06-30 14:09:10 -0400 |
commit | 7087d51975f4059591c04718def24ba7b753644c (patch) | |
tree | 3e0e03d57143394ceff8f059568a34237416af8a /src/resolv/async_resolv.c | |
parent | ec425320a9bf42954a5a28b79cb567e3a9a58ecc (diff) | |
download | sssd-7087d51975f4059591c04718def24ba7b753644c.tar.gz sssd-7087d51975f4059591c04718def24ba7b753644c.tar.xz sssd-7087d51975f4059591c04718def24ba7b753644c.zip |
Add sockaddr_storage to sdap_service
Diffstat (limited to 'src/resolv/async_resolv.c')
-rw-r--r-- | src/resolv/async_resolv.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c index 1f8056722..9b9b0538e 100644 --- a/src/resolv/async_resolv.c +++ b/src/resolv/async_resolv.c @@ -1296,6 +1296,42 @@ resolv_get_string_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent) return address; } +struct sockaddr_storage * +resolv_get_sockaddr_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent, + int port) +{ + struct sockaddr_storage *sockaddr; + + if (!hostent) return NULL; + + sockaddr = talloc_zero(mem_ctx, struct sockaddr_storage); + if (sockaddr == NULL) { + DEBUG(1, ("talloc_zero failed.\n")); + return NULL; + } + + switch(hostent->family) { + case AF_INET: + sockaddr->ss_family = AF_INET; + memcpy(&((struct sockaddr_in *) sockaddr)->sin_addr, + hostent->addr_list[0]->ipaddr, sizeof(struct in_addr)); + ((struct sockaddr_in *) sockaddr)->sin_port = (in_port_t) htons(port); + + break; + case AF_INET6: + sockaddr->ss_family = AF_INET6; + memcpy(&((struct sockaddr_in6 *) sockaddr)->sin6_addr, + hostent->addr_list[0]->ipaddr, sizeof(struct in6_addr)); + ((struct sockaddr_in6 *) sockaddr)->sin6_port = (in_port_t) htons(port); + break; + default: + DEBUG(1, ("Unknown address family %d\n")); + return NULL; + } + + return sockaddr; +} + /* * A simple helper function that will take an array of struct ares_srv_reply that * was allocated by malloc() in c-ares and copies it using talloc. The old one |