From 7d23a5523670075f6077d94efc4e1a1d9a8ebedc Mon Sep 17 00:00:00 2001 From: Ruben van Staveren Date: Tue, 22 Jul 2014 19:36:40 +0200 Subject: [PATCH] When transparent, make sure both connections use the same address family --- common.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common.c b/common.c index 7af9ee1..139481e 100644 --- a/common.c +++ b/common.c @@ -139,11 +139,22 @@ int bind_peer(int fd, int fd_from) * of new file descriptor. */ int connect_addr(struct connection *cnx, int fd_from) { - struct addrinfo *a; + struct addrinfo *a, from; + struct sockaddr_storage ss; char buf[NI_MAXHOST]; int fd, res; + memset(&from, 0, sizeof(from)); + from.ai_addr = (struct sockaddr*)&ss; + from.ai_addrlen = sizeof(ss); + + res = getpeername(fd_from, from.ai_addr, &from.ai_addrlen); + CHECK_RES_RETURN(res, "getpeername"); + for (a = cnx->proto->saddr; a; a = a->ai_next) { + /* When transparent, make sure both connections use the same address family */ + if (transparent && a->ai_family != from.ai_addr->sa_family) + continue; if (verbose) fprintf(stderr, "connecting to %s family %d len %d\n", sprintaddr(buf, sizeof(buf), a),