summaryrefslogtreecommitdiff
path: root/source4/lib/socket
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-02-13 13:07:58 +0100
committerStefan Metzmacher <metze@samba.org>2009-02-13 13:44:38 +0100
commitf131718c607eba5e94e32ae6c4ce81d65ec98718 (patch)
treea92f83f9e9d769c3b8587c4e6bb3d8afa286d4bf /source4/lib/socket
parentf3c5bd9b776def71517a6395c595f3bd941434eb (diff)
downloadsamba-f131718c607eba5e94e32ae6c4ce81d65ec98718.tar.gz
samba-f131718c607eba5e94e32ae6c4ce81d65ec98718.tar.bz2
samba-f131718c607eba5e94e32ae6c4ce81d65ec98718.zip
s4:lib/socket: add socket_address_copy()
metze
Diffstat (limited to 'source4/lib/socket')
-rw-r--r--source4/lib/socket/socket.c33
-rw-r--r--source4/lib/socket/socket.h2
2 files changed, 35 insertions, 0 deletions
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 9d30e0a77e..8e2f1683f2 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -426,6 +426,39 @@ _PUBLIC_ struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx
return addr;
}
+/* Copy a socket_address structure */
+struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
+ const struct socket_address *oaddr)
+{
+ struct socket_address *addr = talloc_zero(mem_ctx, struct socket_address);
+ if (!addr) {
+ return NULL;
+ }
+ addr->family = oaddr->family;
+ if (oaddr->addr) {
+ addr->addr = talloc_strdup(addr, oaddr->addr);
+ if (!addr->addr) {
+ goto nomem;
+ }
+ }
+ addr->port = oaddr->port;
+ if (oaddr->sockaddr) {
+ addr->sockaddr = (struct sockaddr *)talloc_memdup(addr,
+ oaddr->sockaddr,
+ oaddr->sockaddrlen);
+ if (!addr->sockaddr) {
+ goto nomem;
+ }
+ addr->sockaddrlen = oaddr->sockaddrlen;
+ }
+
+ return addr;
+
+nomem:
+ talloc_free(addr);
+ return NULL;
+}
+
_PUBLIC_ const struct socket_ops *socket_getops_byname(const char *family, enum socket_type type)
{
extern const struct socket_ops *socket_ipv4_ops(enum socket_type);
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index e9338127c4..0f469e5ceb 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -167,6 +167,8 @@ 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 socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
+ const struct socket_address *oaddr);
const struct socket_ops *socket_getops_byname(const char *name, enum socket_type type);
bool allow_access(TALLOC_CTX *mem_ctx,
const char **deny_list, const char **allow_list,