[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torsocks/master] Fix: use getsockname instead of getsockopt to get socket family



commit 8406ef884df2fb7dbdfd475ea7e548a40dcdce3f
Author: David Goulet <dgoulet@xxxxxxxxx>
Date:   Sat Oct 25 12:33:00 2014 -0400

    Fix: use getsockname instead of getsockopt to get socket family
    
    Seems that OS X 10.10 Yosemite does not support the SO_DOMAIN anymore so
    use a known compatible call to get the socket family in recv(2).
    
    Fixes #13571
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
 src/lib/recv.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/lib/recv.c b/src/lib/recv.c
index b034d72..6e8a20a 100644
--- a/src/lib/recv.c
+++ b/src/lib/recv.c
@@ -60,23 +60,23 @@ static void close_fds(int *fds, size_t count)
  */
 LIBC_RECVMSG_RET_TYPE tsocks_recvmsg(LIBC_RECVMSG_SIG)
 {
-	int sock_domain;
-	socklen_t optlen;
+	socklen_t addrlen;
 	ssize_t ret = 0;
 	char dummy, recv_fd[CMSG_SPACE(SCM_MAX_FD)];
 	struct iovec iov[1];
 	struct cmsghdr *cmsg;
 	struct msghdr msg_hdr;
+	struct sockaddr addr;
 
 	/* Don't bother if the socket family is NOT Unix. */
-	optlen = sizeof(sock_domain);
-	ret = getsockopt(sockfd, SOL_SOCKET, SO_DOMAIN, &sock_domain, &optlen);
+	addrlen = sizeof(addr);
+	ret = getsockname(sockfd, &addr, &addrlen);
 	if (ret < 0) {
-		DBG("[recvmsg] Fail getsockopt() on sock %d", sockfd);
+		DBG("[recvmsg] Fail getsockname() on sock %d", sockfd);
 		errno = EBADF;
 		goto error;
 	}
-	if (sock_domain != AF_UNIX) {
+	if (addr.sa_family != AF_UNIX) {
 		goto libc;
 	}
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits