aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/platform/linux.py
blob: 8dfd2f81944e8094b3898e17ad3a33e2d9a05fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import socket
import struct

# Python socket module does not have this constant
SO_ORIGINAL_DST = 80


class Resolver:

    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