* [gentoo-portage-dev] [PATCH] SOCKSv5: report bound socket name
@ 2015-01-25 12:19 Michał Górny
2015-01-25 14:01 ` Michał Górny
0 siblings, 1 reply; 2+ messages in thread
From: Michał Górny @ 2015-01-25 12:19 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Michał Górny
Report bound socket name as requested by the protocol. Supports both
IPv4 and IPv6 sockets.
---
bin/socks5-server.py | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/bin/socks5-server.py b/bin/socks5-server.py
index 4795dcc..78a6751 100644
--- a/bin/socks5-server.py
+++ b/bin/socks5-server.py
@@ -11,6 +11,7 @@ import sys
class ProxyConnection(asyncore.dispatcher_with_send):
+ _family = None
_proxy_conn = None
def __init__(self, host, port, proxy_conn):
@@ -18,6 +19,7 @@ class ProxyConnection(asyncore.dispatcher_with_send):
asyncore.dispatcher_with_send.__init__(self)
# TODO: how to support IPv6? ugly fail-then-reinit?
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+ self._family = socket.AF_INET
self.connect((host, port))
def handle_read(self):
@@ -25,7 +27,7 @@ class ProxyConnection(asyncore.dispatcher_with_send):
self._proxy_conn.send(buf)
def handle_connect(self):
- self._proxy_conn.send_connected()
+ self._proxy_conn.send_connected(self._family, self.getsockname())
def handle_close(self):
self._proxy_conn.close()
@@ -126,9 +128,20 @@ class ProxyHandler(asyncore.dispatcher_with_send):
if self._my_conn is not None:
self._my_conn.close()
- def send_connected(self):
- repl = struct.pack('!BBBBLH', 0x05, 0x00, 0x00, 0x01,
- 0x00000000, 0x0000)
+ def send_connected(self, family, addr):
+ if family == socket.AF_INET:
+ host, port = addr
+ bin_host = socket.inet_aton(host)
+
+ repl = struct.pack('!BBBB4sH', 0x05, 0x00, 0x00, 0x01,
+ bin_host, port)
+ elif family == socket.AF_INET6:
+ host, port = addr
+ bin_host = socket.inet_pton(family, host)
+
+ repl = struct.pack('!BBBB16sH', 0x05, 0x00, 0x00, 0x04,
+ bin_host, port)
+
self.send(repl)
self._my_state = 3
--
2.2.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] SOCKSv5: report bound socket name
2015-01-25 12:19 [gentoo-portage-dev] [PATCH] SOCKSv5: report bound socket name Michał Górny
@ 2015-01-25 14:01 ` Michał Górny
0 siblings, 0 replies; 2+ messages in thread
From: Michał Górny @ 2015-01-25 14:01 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 326 bytes --]
Dnia 2015-01-25, o godz. 13:19:37
Michał Górny <mgorny@gentoo.org> napisał(a):
> Report bound socket name as requested by the protocol. Supports both
> IPv4 and IPv6 sockets.
Now included (with fixes) in:
[PATCH v2] Support escaping network-sandbox through SOCKSv5 proxy
--
Best regards,
Michał Górny
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 949 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-01-25 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-25 12:19 [gentoo-portage-dev] [PATCH] SOCKSv5: report bound socket name Michał Górny
2015-01-25 14:01 ` Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox