diff options
author | Andrew Tridgell <tridge@samba.org> | 2011-05-12 12:29:21 +0200 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-06-06 12:26:09 +1000 |
commit | 244137b10d511dedb1798b90aa2f4c354c50a44e (patch) | |
tree | 36925b0b6c3834aecccaf744741331a8266b232b /source4/lib/socket | |
parent | d8d63b53b7beed80e9224ce8079c18da95b28247 (diff) | |
download | samba-244137b10d511dedb1798b90aa2f4c354c50a44e.tar.gz |
s4-ipv6: added socket_address_from_sockaddr_storage()
this converts a struct sockaddr_storage to a struct socket_address
Diffstat (limited to 'source4/lib/socket')
-rw-r--r-- | source4/lib/socket/socket.c | 44 | ||||
-rw-r--r-- | source4/lib/socket/socket.h | 4 |
2 files changed, 48 insertions, 0 deletions
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index cecd1026d5..41638b3d72 100644 --- a/source4/lib/socket/socket.c +++ b/source4/lib/socket/socket.c @@ -510,6 +510,50 @@ _PUBLIC_ struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx return addr; } + +/* + Create a new socket_address from sockaddr_storage + */ +_PUBLIC_ struct socket_address *socket_address_from_sockaddr_storage(TALLOC_CTX *mem_ctx, + const struct sockaddr_storage *sockaddr, + uint16_t port) +{ + struct socket_address *addr = talloc_zero(mem_ctx, struct socket_address); + char addr_str[INET6_ADDRSTRLEN+1]; + const char *str; + + if (!addr) { + return NULL; + } + addr->port = port; + switch (sockaddr->ss_family) { + case AF_INET: + addr->family = "ipv4"; + break; +#ifdef HAVE_IPV6 + case AF_INET6: + addr->family = "ipv6"; + break; +#endif + default: + talloc_free(addr); + return NULL; + } + + str = print_sockaddr(addr_str, sizeof(addr_str), sockaddr); + if (str == NULL) { + talloc_free(addr); + return NULL; + } + addr->addr = talloc_strdup(addr, str); + if (addr->addr == NULL) { + talloc_free(addr); + return NULL; + } + + return addr; +} + /* Copy a socket_address structure */ struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx, const struct socket_address *oaddr) diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h index 88360ac8f3..e00b61ba6c 100644 --- a/source4/lib/socket/socket.h +++ b/source4/lib/socket/socket.h @@ -174,6 +174,10 @@ struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx, struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx, struct sockaddr *sockaddr, size_t addrlen); +struct sockaddr_storage; +struct socket_address *socket_address_from_sockaddr_storage(TALLOC_CTX *mem_ctx, + const struct sockaddr_storage *sockaddr, + uint16_t port); _PUBLIC_ void socket_address_set_port(struct socket_address *a, uint16_t port); struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx, |