aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/platform/osx.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-09-17 11:05:20 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-09-17 11:05:20 +1200
commit21f74efa10374d99df29a3eb666370b28b30d5b3 (patch)
tree7638b0fa90c9a0029ed1034fbb9c22fbf6ca5426 /libmproxy/platform/osx.py
parente039940f49aa057903c50aa9e0feb13da9990820 (diff)
downloadmitmproxy-21f74efa10374d99df29a3eb666370b28b30d5b3.tar.gz
mitmproxy-21f74efa10374d99df29a3eb666370b28b30d5b3.tar.bz2
mitmproxy-21f74efa10374d99df29a3eb666370b28b30d5b3.zip
Stub out ctypes structures for OSX transparent mode.
Diffstat (limited to 'libmproxy/platform/osx.py')
-rw-r--r--libmproxy/platform/osx.py119
1 files changed, 84 insertions, 35 deletions
diff --git a/libmproxy/platform/osx.py b/libmproxy/platform/osx.py
index fa51a2db..a66c03ed 100644
--- a/libmproxy/platform/osx.py
+++ b/libmproxy/platform/osx.py
@@ -1,9 +1,92 @@
-import socket, struct
+import socket, ctypes
# Python socket module does not have this constant
DIOCNATLOOK = 23
+PFDEV = "/dev/pf"
+
+
+class PF_STATE_XPORT(ctypes.Union):
+ """
+ union pf_state_xport {
+ u_int16_t port;
+ u_int16_t call_id;
+ u_int32_t spi;
+ };
+ """
+ _fields_ = [
+ ("port", ctypes.c_uint),
+ ("call_id", ctypes.c_uint),
+ ("spi", ctypes.c_ulong),
+ ]
+
+
+class PF_ADDR(ctypes.Union):
+ """
+ struct pf_addr {
+ union {
+ struct in_addr v4;
+ struct in6_addr v6;
+ u_int8_t addr8[16];
+ u_int16_t addr16[8];
+ u_int32_t addr32[4];
+ } pfa;
+ }
+ """
+ _fields_ = [
+ ("addr8", ctypes.c_byte * 2),
+ ("addr16", ctypes.c_byte * 4),
+ ("addr32", ctypes.c_byte * 8),
+ ]
+
+
+class PFIOC_NATLOOK(ctypes.Structure):
+ """
+ struct pfioc_natlook {
+ struct pf_addr saddr;
+ struct pf_addr daddr;
+ struct pf_addr rsaddr;
+ struct pf_addr rdaddr;
+ #ifndef NO_APPLE_EXTENSIONS
+ union pf_state_xport sxport;
+ union pf_state_xport dxport;
+ union pf_state_xport rsxport;
+ union pf_state_xport rdxport;
+ sa_family_t af;
+ u_int8_t proto;
+ u_int8_t proto_variant;
+ u_int8_t direction;
+ #else
+ u_int16_t sport;
+ u_int16_t dport;
+ u_int16_t rsport;
+ u_int16_t rdport;
+ sa_family_t af;
+ u_int8_t proto;
+ u_int8_t direction;
+ #endif
+ };
+ """
+ _fields_ = [
+ ("saddr", PF_ADDR),
+ ("daddr", PF_ADDR),
+ ("rsaddr", PF_ADDR),
+ ("rdaddr", PF_ADDR),
+
+ ("sxport", PF_STATE_XPORT),
+ ("dxport", PF_STATE_XPORT),
+ ("rsxport", PF_STATE_XPORT),
+ ("rdxport", PF_STATE_XPORT),
+ ("af", ctypes.c_uint),
+ ("proto", ctypes.c_ushort),
+ ("proto_variant", ctypes.c_ushort),
+ ("direction", ctypes.c_ushort),
+ ]
+
class Resolver:
+ def __init__(self):
+ self.pfdev = open(PFDEV, "r")
+
def original_addr(self, csock):
"""
The following sttruct defintions are plucked from the current XNU source, found here:
@@ -16,39 +99,5 @@ class Resolver:
u_int16_t call_id;
u_int32_t spi;
};
-
- struct pf_addr {
- union {
- struct in_addr v4;
- struct in6_addr v6;
- u_int8_t addr8[16];
- u_int16_t addr16[8];
- u_int32_t addr32[4];
- } pfa;
-
- struct pfioc_natlook {
- struct pf_addr saddr;
- struct pf_addr daddr;
- struct pf_addr rsaddr;
- struct pf_addr rdaddr;
- #ifndef NO_APPLE_EXTENSIONS
- union pf_state_xport sxport;
- union pf_state_xport dxport;
- union pf_state_xport rsxport;
- union pf_state_xport rdxport;
- sa_family_t af;
- u_int8_t proto;
- u_int8_t proto_variant;
- u_int8_t direction;
- #else
- u_int16_t sport;
- u_int16_t dport;
- u_int16_t rsport;
- u_int16_t rdport;
- sa_family_t af;
- u_int8_t proto;
- u_int8_t direction;
- #endif
- };
"""
pass