summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-03-08 17:20:18 +0100
committerStefan Metzmacher <metze@samba.org>2009-03-08 17:22:26 +0100
commit3679e8243459f928b1a4d0998d47c6efdedd0301 (patch)
tree630f34689b79862ef27e942680d684f8db8065a5 /lib
parentf9156f6c77d9e87edc153b024a1d564b44eedd8f (diff)
downloadsamba-3679e8243459f928b1a4d0998d47c6efdedd0301.tar.gz
samba-3679e8243459f928b1a4d0998d47c6efdedd0301.tar.bz2
samba-3679e8243459f928b1a4d0998d47c6efdedd0301.zip
socket_wrapper: downgrade ipv6 sockets to ipv4 is in connect() if the dest is ipv4
We only do this if the socket isn't explicit bound yet. metze
Diffstat (limited to 'lib')
-rw-r--r--lib/socket_wrapper/socket_wrapper.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index b2d3a6b15d..733a33217c 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -1536,8 +1536,10 @@ static int autobind_start;
/* using sendto() or connect() on an unbound socket would give the
recipient no way to reply, as unlike UDP and TCP, a unix domain
socket can't auto-assign emphemeral port numbers, so we need to
- assign it here */
-static int swrap_auto_bind(struct socket_info *si)
+ assign it here.
+ Note: this might change the family from ipv6 to ipv4
+*/
+static int swrap_auto_bind(struct socket_info *si, int family)
{
struct sockaddr_un un_addr;
int i;
@@ -1555,7 +1557,7 @@ static int swrap_auto_bind(struct socket_info *si)
un_addr.sun_family = AF_UNIX;
- switch (si->family) {
+ switch (family) {
case AF_INET: {
struct sockaddr_in in;
@@ -1584,6 +1586,11 @@ static int swrap_auto_bind(struct socket_info *si)
case AF_INET6: {
struct sockaddr_in6 in6;
+ if (si->family != family) {
+ errno = ENETUNREACH;
+ return -1;
+ }
+
switch (si->type) {
case SOCK_STREAM:
type = SOCKET_TYPE_CHAR_TCP_V6;
@@ -1634,6 +1641,7 @@ static int swrap_auto_bind(struct socket_info *si)
return -1;
}
+ si->family = family;
set_port(si->family, port, si->myname);
return 0;
@@ -1651,7 +1659,7 @@ _PUBLIC_ int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t ad
}
if (si->bound == 0) {
- ret = swrap_auto_bind(si);
+ ret = swrap_auto_bind(si, serv_addr->sa_family);
if (ret == -1) return -1;
}
@@ -1872,7 +1880,7 @@ _PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, con
break;
case SOCK_DGRAM:
if (si->bound == 0) {
- ret = swrap_auto_bind(si);
+ ret = swrap_auto_bind(si, si->family);
if (ret == -1) return -1;
}