s4:lib/socket: add socket_get_{remote|local}_addr() to get a tsocket_address instead...
authorStefan Metzmacher <metze@samba.org>
Wed, 23 Dec 2009 09:43:05 +0000 (10:43 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 24 Dec 2009 16:38:33 +0000 (17:38 +0100)
metze

source4/lib/socket/socket.c
source4/lib/socket/socket.h

index 23eade7b53f0ad632f2eb889c42f31ad569466f3..30db03fd97cb0d4d6ad5484111283f3bc66b0081 100644 (file)
@@ -386,6 +386,36 @@ _PUBLIC_ struct socket_address *tsocket_address_to_socket_address(TALLOC_CTX *me
        return socket_address_from_sockaddr(mem_ctx, (struct sockaddr *)(void *)&ss, ret);
 }
 
+_PUBLIC_ struct tsocket_address *socket_get_remote_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
+{
+       struct socket_address *a;
+       struct tsocket_address *r;
+
+       a = socket_get_peer_addr(sock, mem_ctx);
+       if (a == NULL) {
+               return NULL;
+       }
+
+       r = socket_address_to_tsocket_address(mem_ctx, a);
+       talloc_free(a);
+       return r;
+}
+
+_PUBLIC_ struct tsocket_address *socket_get_local_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
+{
+       struct socket_address *a;
+       struct tsocket_address *r;
+
+       a = socket_get_my_addr(sock, mem_ctx);
+       if (a == NULL) {
+               return NULL;
+       }
+
+       r = socket_address_to_tsocket_address(mem_ctx, a);
+       talloc_free(a);
+       return r;
+}
+
 _PUBLIC_ int socket_get_fd(struct socket_context *sock)
 {
        if (!sock->ops->fn_get_fd) {
index 5f29618f141ba5f61e143eed82303b15cbb2a2dc..8f8922bcea42fd12e294341427d057978b944a3b 100644 (file)
@@ -163,6 +163,8 @@ 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);
+struct tsocket_address *socket_get_remote_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
+struct tsocket_address *socket_get_local_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
 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,