Skip to content

Commit fbc0192

Browse files
aviauslaroche
authored andcommitted
linux.py: hardcode original_addr
1 parent 7efefb7 commit fbc0192

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mitmproxy/platform/linux.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import socket
22
import struct
33
import typing
4+
import os
45

56
# Python's socket module does not have these constants
67
SO_ORIGINAL_DST = 80
@@ -22,11 +23,9 @@ def original_addr(csock: socket.socket) -> typing.Tuple[str, int]:
2223
# As such, we use a heuristic to check which syscall to do.
2324
is_ipv4 = "." in csock.getsockname()[0] # either 127.0.0.1 or ::ffff:127.0.0.1
2425
if is_ipv4:
25-
# the struct returned here should only have 8 bytes, but invoking sock.getsockopt
26-
# with buflen=8 doesn't work.
27-
dst = csock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 16)
28-
port, raw_ip = struct.unpack_from("!2xH4s", dst)
29-
ip = socket.inet_ntop(socket.AF_INET, raw_ip)
26+
ip = os.environ["MITMPROXY_ORIGINAL_ADDR_IP"]
27+
port = int(os.environ["MITMPROXY_ORIGINAL_ADDR_PORT"])
28+
return ip, port
3029
else:
3130
dst = csock.getsockopt(SOL_IPV6, SO_ORIGINAL_DST, 28)
3231
port, raw_ip = struct.unpack_from("!2xH4x16s", dst)

0 commit comments

Comments
 (0)