Skip to content

Commit

Permalink
Support IPv6 in redir:// proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
klzgrad committed Aug 13, 2022
1 parent 3555c20 commit fb63815
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/net/tools/naive/naive_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,20 @@ int NaiveConnection::DoConnectServer() {
#if defined(OS_LINUX)
const auto* socket =
static_cast<const TCPClientSocket*>(client_socket_.get());
IPEndPoint local_address;
int rv;
rv = socket->GetLocalAddress(&local_address);
if (rv != OK) {
LOG(ERROR) << "Connection " << id_ << " cannot get local address";
return rv;
}
int sd = socket->SocketDescriptorForTesting();
SockaddrStorage dst;
int rv;
rv = getsockopt(sd, SOL_IP, SO_ORIGINAL_DST, dst.addr, &dst.addr_len);
if (local_address.GetFamily() == ADDRESS_FAMILY_IPV4) {
rv = getsockopt(sd, SOL_IP, SO_ORIGINAL_DST, dst.addr, &dst.addr_len);
} else {
rv = getsockopt(sd, SOL_IPV6, SO_ORIGINAL_DST, dst.addr, &dst.addr_len);
}
if (rv == 0) {
IPEndPoint ipe;
if (ipe.FromSockAddr(dst.addr, dst.addr_len)) {
Expand Down

0 comments on commit fb63815

Please sign in to comment.