From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A4368138A1A for ; Sun, 25 Jan 2015 12:19:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C24D0E0849; Sun, 25 Jan 2015 12:19:50 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 60F76E0843 for ; Sun, 25 Jan 2015 12:19:50 +0000 (UTC) Received: from pomiot.lan (77-255-4-103.adsl.inetia.pl [77.255.4.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id CA08A3406D0; Sun, 25 Jan 2015 12:19:48 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-portage-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-portage-dev] [PATCH] SOCKSv5: report bound socket name Date: Sun, 25 Jan 2015 13:19:37 +0100 Message-Id: <1422188377-27703-1-git-send-email-mgorny@gentoo.org> X-Mailer: git-send-email 2.2.2 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 270ab393-56a2-4f34-a3a2-8364de92e2d1 X-Archives-Hash: 039c6a9a750d9397db51c5aadc815108 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