summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-09-20 12:03:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:54 -0500
commite8d244251732cd744c2c69e3e7bd7a875e704a60 (patch)
tree3c7c0997881f662f4dfa978122b41ebdbd505dd4
parent6b9b169c2746c0223f249700d7ff8a70feb8da62 (diff)
downloadsamba-e8d244251732cd744c2c69e3e7bd7a875e704a60.tar.gz
samba-e8d244251732cd744c2c69e3e7bd7a875e704a60.tar.bz2
samba-e8d244251732cd744c2c69e3e7bd7a875e704a60.zip
r2446: implement socket_get_<peer|my>_<addr|port>() for ipv4
metze (This used to be commit a8ebb5c5bc6a8651867b46e87cf223cddf444e89)
-rw-r--r--source4/lib/socket/socket_ipv4.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/source4/lib/socket/socket_ipv4.c b/source4/lib/socket/socket_ipv4.c
index f423ded302..9a1e7e43f6 100644
--- a/source4/lib/socket/socket_ipv4.c
+++ b/source4/lib/socket/socket_ipv4.c
@@ -89,7 +89,6 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock,
}
}
-
ret = connect(sock->fd, (const struct sockaddr *)&srv_addr, sizeof(srv_addr));
if (ret == -1) {
/* TODO: we need to map from errno to NTSTATUS here! */
@@ -296,22 +295,58 @@ static NTSTATUS ipv4_tcp_set_option(struct socket_context *sock, const char *opt
static char *ipv4_tcp_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
{
- return NULL;
+ struct sockaddr_in peer_addr;
+ socklen_t len = sizeof(peer_addr);
+ int ret;
+
+ ret = getpeername(sock->fd, (struct sockaddr *)&peer_addr, &len);
+ if (ret == -1) {
+ return NULL;
+ }
+
+ return talloc_strdup(mem_ctx, inet_ntoa(peer_addr.sin_addr));
}
static int ipv4_tcp_get_peer_port(struct socket_context *sock)
{
- return -1;
+ struct sockaddr_in peer_addr;
+ socklen_t len = sizeof(peer_addr);
+ int ret;
+
+ ret = getpeername(sock->fd, (struct sockaddr *)&peer_addr, &len);
+ if (ret == -1) {
+ return -1;
+ }
+
+ return ntohs(peer_addr.sin_port);
}
static char *ipv4_tcp_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
{
- return NULL;
+ struct sockaddr_in my_addr;
+ socklen_t len = sizeof(my_addr);
+ int ret;
+
+ ret = getsockname(sock->fd, (struct sockaddr *)&my_addr, &len);
+ if (ret == -1) {
+ return NULL;
+ }
+
+ return talloc_strdup(mem_ctx, inet_ntoa(my_addr.sin_addr));
}
static int ipv4_tcp_get_my_port(struct socket_context *sock)
{
- return -1;
+ struct sockaddr_in my_addr;
+ socklen_t len = sizeof(my_addr);
+ int ret;
+
+ ret = getsockname(sock->fd, (struct sockaddr *)&my_addr, &len);
+ if (ret == -1) {
+ return -1;
+ }
+
+ return ntohs(my_addr.sin_port);
}
static int ipv4_tcp_get_fd(struct socket_context *sock)