From cc75ff1a37b1e7d9e75e718731fa30e4901850c7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 6 Apr 2009 14:29:24 +0200 Subject: tsocket: for unix domain sockets we need to use sizeof(struct sockaddr_un) sizeof(struct sockaddr_storage) generates EINVAL. metze --- lib/tsocket/tsocket_bsd.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index e260b1fa25..52cc5cc1cf 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -812,6 +812,13 @@ static void tdgram_bsd_recvfrom_handler(void *private_data) sa = &bsda->u.sa; sa_len = sizeof(bsda->u.ss); + /* + * for unix sockets we can't use the size of sockaddr_storage + * we would get EINVAL + */ + if (bsda->u.sa.sa_family == AF_UNIX) { + sa_len = sizeof(bsda->u.un); + } ret = recvfrom(bsds->fd, state->buf, state->len, 0, sa, &sa_len); err = tsocket_bsd_error_from_errno(ret, errno, &retry); @@ -959,6 +966,13 @@ static void tdgram_bsd_sendto_handler(void *private_data) sa = &bsda->u.sa; sa_len = sizeof(bsda->u.ss); + /* + * for unix sockets we can't use the size of sockaddr_storage + * we would get EINVAL + */ + if (bsda->u.sa.sa_family == AF_UNIX) { + sa_len = sizeof(bsda->u.un); + } } ret = sendto(bsds->fd, state->buf, state->len, 0, sa, sa_len); @@ -1086,6 +1100,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, int ret; bool do_bind = false; bool do_reuseaddr = false; + socklen_t sa_len = sizeof(lbsda->u.ss); if (remote) { rbsda = talloc_get_type_abort(remote->private_data, @@ -1102,6 +1117,11 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, do_reuseaddr = true; do_bind = true; } + /* + * for unix sockets we can't use the size of sockaddr_storage + * we would get EINVAL + */ + sa_len = sizeof(lbsda->u.un); break; case AF_INET: if (lbsda->u.in.sin_port != 0) { @@ -1182,7 +1202,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, } if (do_bind) { - ret = bind(fd, &lbsda->u.sa, sizeof(lbsda->u.ss)); + ret = bind(fd, &lbsda->u.sa, sa_len); if (ret == -1) { int saved_errno = errno; talloc_free(dgram); @@ -1192,7 +1212,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, } if (rbsda) { - ret = connect(fd, &rbsda->u.sa, sizeof(rbsda->u.ss)); + ret = connect(fd, &rbsda->u.sa, sa_len); if (ret == -1) { int saved_errno = errno; talloc_free(dgram); -- cgit