commit f19b2e805638478812ce0102f8c2027701183eb2 Author: Linus Nordberg linus@nordberg.se Date: Sun Aug 25 10:29:52 2013 +0200
Use getsockname(2) for finding out socket address family
Use this for portability. SO_DOMAIN seems to be a Linuxism.
Signed-off-by: David Goulet dgoulet@ev0ke.net --- src/lib/recv.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/lib/recv.c b/src/lib/recv.c index 9a70dd3..895892d 100644 --- a/src/lib/recv.c +++ b/src/lib/recv.c @@ -64,20 +64,23 @@ LIBC_RECVMSG_RET_TYPE tsocks_recvmsg(LIBC_RECVMSG_SIG) * further. */ if (cmsg->cmsg_type == SCM_RIGHTS || cmsg->cmsg_level == SOL_SOCKET) { - socklen_t optlen; - int sock_dom; + struct sockaddr_storage addr; + socklen_t addrlen; + sa_family_t family = AF_UNSPEC;
memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd));
- /* Get socket domain. */ - optlen = sizeof(sock_dom); - ret = getsockopt(fd, SOL_SOCKET, SO_DOMAIN, &sock_dom, &optlen); + /* Get socket protocol family. */ + addrlen = sizeof(addr); + ret = getsockname(fd, (struct sockaddr *) &addr, &addrlen); if (ret < 0) { - /* Use the getsockopt() errno value. */ + /* Use the getsockname() errno value. */ goto end; }
- if (sock_dom == AF_INET || sock_dom == AF_INET6) { + family = ((struct sockaddr *) &addr)->sa_family; + + if (family == AF_INET || family == AF_INET6) { ERR("[recvmsg] Inet socket passing detected. Aborting everything! " "A non Tor socket could be used thus leaking information."); exit(EXIT_FAILURE);
tor-commits@lists.torproject.org