Skip to content

Commit 118171a

Browse files
committed
Fix get_tcp_dstip with MacOSX/Python3.5
1 parent 3367124 commit 118171a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

sshuttle/methods/pf.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ def get_tcp_dstip(self, sock):
156156
proxy = sock.getsockname()
157157

158158
argv = (sock.family, socket.IPPROTO_TCP,
159-
peer[0], peer[1], proxy[0], proxy[1])
160-
pfile.write("QUERY_PF_NAT %d,%d,%s,%d,%s,%d\n" % argv)
159+
peer[0].encode("ASCII"), peer[1],
160+
proxy[0].encode("ASCII"), proxy[1])
161+
pfile.write(b"QUERY_PF_NAT %d,%d,%s,%d,%s,%d\n" % argv)
161162
pfile.flush()
162163
line = pfile.readline()
163-
debug2("QUERY_PF_NAT %d,%d,%s,%d,%s,%d" % argv + ' > ' + line)
164-
if line.startswith('QUERY_PF_NAT_SUCCESS '):
165-
(ip, port) = line[21:].split(',')
166-
return (ip, int(port))
164+
debug2(b"QUERY_PF_NAT %d,%d,%s,%d,%s,%d" % argv + b' > ' + line)
165+
if line.startswith(b'QUERY_PF_NAT_SUCCESS '):
166+
(ip, port) = line[21:].split(b',')
167+
return (ip.decode("ASCII"), int(port))
167168

168169
return sock.getsockname()
169170

sshuttle/tests/test_methods_pf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_get_tcp_dstip():
2020

2121
firewall = Mock()
2222
firewall.pfile.readline.return_value = \
23-
"QUERY_PF_NAT_SUCCESS 127.0.0.3,1026\n"
23+
b"QUERY_PF_NAT_SUCCESS 127.0.0.3,1026\n"
2424

2525
method = get_method('pf')
2626
method.set_firewall(firewall)
@@ -31,7 +31,7 @@ def test_get_tcp_dstip():
3131
call.getsockname(),
3232
]
3333
assert firewall.mock_calls == [
34-
call.pfile.write('QUERY_PF_NAT 2,6,127.0.0.1,1024,127.0.0.2,1025\n'),
34+
call.pfile.write(b'QUERY_PF_NAT 2,6,127.0.0.1,1024,127.0.0.2,1025\n'),
3535
call.pfile.flush(),
3636
call.pfile.readline()
3737
]

0 commit comments

Comments
 (0)