summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-12-23 09:38:21 +0100
committerStefan Metzmacher <metze@samba.org>2009-12-24 17:38:32 +0100
commit445baf53a9c0c65dafd8558c2b3ec877c3c5fdc8 (patch)
tree881e3d048881749c1ecc470ca61d7192c6082bb6
parent17c804a67593cdb4d8646b5be6b50fddf56b3e27 (diff)
downloadsamba-445baf53a9c0c65dafd8558c2b3ec877c3c5fdc8.tar.gz
samba-445baf53a9c0c65dafd8558c2b3ec877c3c5fdc8.tar.bz2
samba-445baf53a9c0c65dafd8558c2b3ec877c3c5fdc8.zip
s4:lib/socket: add helpers functions to convert between socket_address and tsocket_address
metze
-rw-r--r--source4/lib/socket/config.mk2
-rw-r--r--source4/lib/socket/socket.c42
-rw-r--r--source4/lib/socket/socket.h5
3 files changed, 48 insertions, 1 deletions
diff --git a/source4/lib/socket/config.mk b/source4/lib/socket/config.mk
index ac515c8f6d..07491e115a 100644
--- a/source4/lib/socket/config.mk
+++ b/source4/lib/socket/config.mk
@@ -34,7 +34,7 @@ socket_unix_OBJ_FILES = $(libsocketsrcdir)/socket_unix.o
################################################
# Start SUBSYSTEM SOCKET
[SUBSYSTEM::samba_socket]
-PUBLIC_DEPENDENCIES = LIBTALLOC
+PUBLIC_DEPENDENCIES = LIBTALLOC LIBTSOCKET
PRIVATE_DEPENDENCIES = SOCKET_WRAPPER LIBCLI_COMPOSITE LIBCLI_RESOLVE
# End SUBSYSTEM SOCKET
################################################
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 8e2f1683f2..23eade7b53 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -24,6 +24,7 @@
#include "system/filesys.h"
#include "system/network.h"
#include "param/param.h"
+#include "../lib/tsocket/tsocket.h"
/*
auto-close sockets on free
@@ -344,6 +345,47 @@ _PUBLIC_ struct socket_address *socket_get_my_addr(struct socket_context *sock,
return sock->ops->fn_get_my_addr(sock, mem_ctx);
}
+_PUBLIC_ struct tsocket_address *socket_address_to_tsocket_address(TALLOC_CTX *mem_ctx,
+ const struct socket_address *a)
+{
+ struct tsocket_address *r;
+ int ret;
+
+ if (a->sockaddr) {
+ ret = tsocket_address_bsd_from_sockaddr(mem_ctx,
+ a->sockaddr,
+ a->sockaddrlen,
+ &r);
+ } else {
+ ret = tsocket_address_inet_from_strings(mem_ctx,
+ a->family,
+ a->addr,
+ a->port,
+ &r);
+ }
+
+ if (ret != 0) {
+ return NULL;
+ }
+
+ return r;
+}
+
+_PUBLIC_ struct socket_address *tsocket_address_to_socket_address(TALLOC_CTX *mem_ctx,
+ const struct tsocket_address *a)
+{
+ ssize_t ret;
+ struct sockaddr_storage ss;
+ size_t sslen = sizeof(ss);
+
+ ret = tsocket_address_bsd_sockaddr(a, (struct sockaddr *)(void *)&ss, sslen);
+ if (ret < 0) {
+ return NULL;
+ }
+
+ return socket_address_from_sockaddr(mem_ctx, (struct sockaddr *)(void *)&ss, ret);
+}
+
_PUBLIC_ int socket_get_fd(struct socket_context *sock)
{
if (!sock->ops->fn_get_fd) {
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index 02872457b5..5f29618f14 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -127,6 +127,7 @@ struct socket_context {
};
struct resolve_context;
+struct tsocket_address;
/* prototypes */
NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops,
@@ -158,6 +159,10 @@ NTSTATUS socket_set_option(struct socket_context *sock, const char *option, cons
char *socket_get_peer_name(struct socket_context *sock, TALLOC_CTX *mem_ctx);
struct socket_address *socket_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
struct socket_address *socket_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
+struct tsocket_address *socket_address_to_tsocket_address(TALLOC_CTX *mem_ctx,
+ const struct socket_address *a);
+struct socket_address *tsocket_address_to_socket_address(TALLOC_CTX *mem_ctx,
+ const struct tsocket_address *a);
int socket_get_fd(struct socket_context *sock);
NTSTATUS socket_dup(struct socket_context *sock);
struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,