Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #115 from google/ipv6_fix
Browse files Browse the repository at this point in the history
Fix issue with ipv6 sockets and SO_ORIGINAL_DST
  • Loading branch information
klyubin authored Jul 18, 2017
2 parents 8a15e17 + c73070c commit 810f476
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nogotofail/mitm/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,16 @@ def start(self):
return True

def _get_original_dest(self, sock):
family = sock.family
SO_ORIGINAL_DST = 80
dst = sock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 28)
family = struct.unpack_from("H", dst)[0]
# Parse the raw_ip and raw port from the struct sockaddr_in/in6
if family == socket.AF_INET:
dst = sock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 28)
raw_port, raw_ip = struct.unpack_from("!2xH4s", dst)
elif family == socket.AF_INET6:
# From socket.h
SOL_IPV6 = 41
dst = sock.getsockopt(SOL_IPV6, SO_ORIGINAL_DST, 64)
raw_port, raw_ip = struct.unpack_from("!2xH4x16s", dst)
else:
raise ValueError("Unsupported sa_family_t %d" % family)
Expand Down

1 comment on commit 810f476

@greeneterran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hggf

Please sign in to comment.