mitmproxy/libmproxy/platform/linux.py

15 lines
395 B
Python
Raw Normal View History

2015-05-30 00:03:28 +00:00
import socket
import struct
# Python socket module does not have this constant
SO_ORIGINAL_DST = 80
2014-08-10 14:10:49 +00:00
class Resolver(object):
2016-01-27 09:12:18 +00:00
def original_addr(self, csock):
odestdata = csock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 16)
_, port, a1, a2, a3, a4 = struct.unpack("!HHBBBBxxxxxxxx", odestdata)
address = "%d.%d.%d.%d" % (a1, a2, a3, a4)
return address, port