From b158bfa4ef5ae91bfe503c9d0ba775065fbe688f Mon Sep 17 00:00:00 2001 From: Martin Raiber Date: Sun, 23 Jun 2019 23:07:29 +0200 Subject: [PATCH] Return ipv6 zone in lookup --- LookupService.cpp | 8 ++------ LookupService.h | 1 + Server.cpp | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/LookupService.cpp b/LookupService.cpp index d58e9749..9a889958 100644 --- a/LookupService.cpp +++ b/LookupService.cpp @@ -26,6 +26,7 @@ bool LookupBlocking(std::string pServer, SLookupBlockingResult& dest) { + dest.zone = 0; const char* host = pServer.c_str(); unsigned int addr = inet_addr(host); if (addr != INADDR_NONE) @@ -34,12 +35,6 @@ bool LookupBlocking(std::string pServer, SLookupBlockingResult& dest) dest.addr_v4 = addr; return true; } - int rc = inet_pton(AF_INET6, host, dest.addr_v6); - if (rc == 1) - { - dest.is_ipv6 = true; - return true; - } addrinfo hints; memset(&hints, 0, sizeof(hints)); @@ -66,6 +61,7 @@ bool LookupBlocking(std::string pServer, SLookupBlockingResult& dest) { dest.is_ipv6 = true; memcpy(dest.addr_v6, &reinterpret_cast(h->ai_addr)->sin6_addr, 16); + dest.zone = reinterpret_cast(h->ai_addr)->sin6_scope_id; freeaddrinfo(orig_h); return true; } diff --git a/LookupService.h b/LookupService.h index 77431de4..c229a628 100644 --- a/LookupService.h +++ b/LookupService.h @@ -10,6 +10,7 @@ struct SLookupBlockingResult unsigned int addr_v4; char addr_v6[16]; }; + unsigned int zone; }; bool LookupBlocking(std::string pServer, SLookupBlockingResult& dest); diff --git a/Server.cpp b/Server.cpp index 5f64fe56..fbce6506 100644 --- a/Server.cpp +++ b/Server.cpp @@ -1036,6 +1036,7 @@ IPipe* CServer::ConnectStream(std::string pServer, unsigned short pPort, unsigne memcpy(&addr.addr_v6.sin6_addr, lookup_result.addr_v6, sizeof(addr.addr_v6.sin6_addr)); addr.addr_v6.sin6_port = htons(pPort); addr.addr_v6.sin6_family = AF_INET6; + addr.addr_v6.sin6_scope_id = lookup_result.zone; } else {