File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed
Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change 11import socket
22import struct
33import typing
4+ import os
45
56# Python's socket module does not have these constants
67SO_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 )
You can’t perform that action at this time.
0 commit comments