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 | |
parent | ec425320a9bf42954a5a28b79cb567e3a9a58ecc (diff) | |
download | sssd-7087d51975f4059591c04718def24ba7b753644c.tar.gz sssd-7087d51975f4059591c04718def24ba7b753644c.tar.bz2 sssd-7087d51975f4059591c04718def24ba7b753644c.zip |
Add sockaddr_storage to sdap_service
Diffstat (limited to 'src/resolv')
-rw-r--r-- | src/resolv/async_resolv.c | 36 | ||||
-rw-r--r-- | src/resolv/async_resolv.h | 4 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c index 1f805672..9b9b0538 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 diff --git a/src/resolv/async_resolv.h b/src/resolv/async_resolv.h index 907865f7..b5547e5d 100644 --- a/src/resolv/async_resolv.h +++ b/src/resolv/async_resolv.h @@ -114,6 +114,10 @@ int resolv_gethostbyname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, char * resolv_get_string_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent); +struct sockaddr_storage * +resolv_get_sockaddr_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent, + int port); + /** Get SRV record **/ struct tevent_req *resolv_getsrv_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, |