summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-10-06 21:31:00 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 15:07:51 -0500
commit6bc52259aa668666f2f40abfd8da181d5aaf8b6e (patch)
tree914fd74e1b817f9986810b872883188908f68c3e
parentcc8f4eb3cd9b3bc4e3f3d61bfad240147e8a4e5e (diff)
downloadsamba-6bc52259aa668666f2f40abfd8da181d5aaf8b6e.tar.gz
samba-6bc52259aa668666f2f40abfd8da181d5aaf8b6e.tar.bz2
samba-6bc52259aa668666f2f40abfd8da181d5aaf8b6e.zip
r25545: Use inet_ntop for ipv4 code as well - should make it easier to share code between IPv4 and IPv6 later on.
(This used to be commit e3df90927b2878917f0f555772a875f05bf609e8)
-rw-r--r--source4/lib/socket/socket.h3
-rw-r--r--source4/lib/socket/socket_ip.c26
2 files changed, 17 insertions, 12 deletions
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index 0c4fc0bb95..7679db08a1 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -121,6 +121,9 @@ struct socket_context {
void *private_data;
const struct socket_ops *ops;
const char *backend_name;
+
+ /* specific to the ip backend */
+ int family;
};
diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c
index 3ab6f07b22..499dc93d7b 100644
--- a/source4/lib/socket/socket_ip.c
+++ b/source4/lib/socket/socket_ip.c
@@ -47,6 +47,7 @@ static NTSTATUS ipv4_init(struct socket_context *sock)
}
sock->backend_name = "ipv4";
+ sock->family = AF_INET;
return NT_STATUS_OK;
}
@@ -278,7 +279,7 @@ static NTSTATUS ipv4_recvfrom(struct socket_context *sock, void *buf,
struct sockaddr_in *from_addr;
socklen_t from_len = sizeof(*from_addr);
struct socket_address *src;
- const char *addr;
+ char addrstring[INET_ADDRSTRLEN];
src = talloc(addr_ctx, struct socket_address);
if (!src) {
@@ -309,12 +310,12 @@ static NTSTATUS ipv4_recvfrom(struct socket_context *sock, void *buf,
src->sockaddrlen = from_len;
- addr = inet_ntoa(from_addr->sin_addr);
- if (addr == NULL) {
+ if (inet_ntop(AF_INET, &from_addr->sin_addr, addrstring,
+ sizeof(addrstring)) == NULL) {
talloc_free(src);
return NT_STATUS_INTERNAL_ERROR;
}
- src->addr = talloc_strdup(src, addr);
+ src->addr = talloc_strdup(src, addrstring);
if (src->addr == NULL) {
talloc_free(src);
return NT_STATUS_NO_MEMORY;
@@ -412,8 +413,8 @@ static struct socket_address *ipv4_get_peer_addr(struct socket_context *sock, TA
{
struct sockaddr_in *peer_addr;
socklen_t len = sizeof(*peer_addr);
- const char *addr;
struct socket_address *peer;
+ char addrstring[INET_ADDRSTRLEN];
int ret;
peer = talloc(mem_ctx, struct socket_address);
@@ -438,12 +439,12 @@ static struct socket_address *ipv4_get_peer_addr(struct socket_context *sock, TA
peer->sockaddrlen = len;
- addr = inet_ntoa(peer_addr->sin_addr);
- if (addr == NULL) {
+ if (inet_ntop(AF_INET, &peer_addr->sin_addr, addrstring,
+ sizeof(addrstring)) == NULL) {
talloc_free(peer);
return NULL;
}
- peer->addr = talloc_strdup(peer, addr);
+ peer->addr = talloc_strdup(peer, addrstring);
if (!peer->addr) {
talloc_free(peer);
return NULL;
@@ -457,8 +458,8 @@ static struct socket_address *ipv4_get_my_addr(struct socket_context *sock, TALL
{
struct sockaddr_in *local_addr;
socklen_t len = sizeof(*local_addr);
- const char *addr;
struct socket_address *local;
+ char addrstring[INET_ADDRSTRLEN];
int ret;
local = talloc(mem_ctx, struct socket_address);
@@ -483,12 +484,12 @@ static struct socket_address *ipv4_get_my_addr(struct socket_context *sock, TALL
local->sockaddrlen = len;
- addr = inet_ntoa(local_addr->sin_addr);
- if (addr == NULL) {
+ if (inet_ntop(AF_INET, &local_addr->sin_addr, addrstring,
+ sizeof(addrstring)) == NULL) {
talloc_free(local);
return NULL;
}
- local->addr = talloc_strdup(local, addr);
+ local->addr = talloc_strdup(local, addrstring);
if (!local->addr) {
talloc_free(local);
return NULL;
@@ -580,6 +581,7 @@ static NTSTATUS ipv6_init(struct socket_context *sock)
}
sock->backend_name = "ipv6";
+ sock->family = AF_INET6;
return NT_STATUS_OK;
}