[tor-commits] [flashproxy/master] Add -4 and -6 options to flashproxy-reg-http.

dcf at torproject.org dcf at torproject.org
Fri Dec 21 03:54:38 UTC 2012


commit e8c946ac79759afe01f74705623e741561960d12
Author: David Fifield <david at bamsoftware.com>
Date:   Thu Dec 20 19:18:19 2012 -0800

    Add -4 and -6 options to flashproxy-reg-http.
    
    Cf. b9784a46, which was the same for flashproxy-reg-email. This patch is
    part of one by Jorge Couchet.
    https://github.com/uyjco0/flashproxy/commit/2afd2fd53e20b3dfb5bd2605ce74ba60a746f899
---
 flashproxy-reg-http |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/flashproxy-reg-http b/flashproxy-reg-http
index d137827..8c851bf 100755
--- a/flashproxy-reg-http
+++ b/flashproxy-reg-http
@@ -15,6 +15,7 @@ DEFAULT_FACILITATOR_URL = "https://tor-facilitator.bamsoftware.com/"
 class options(object):
     remote_addr = None
     facilitator_url = None
+    address_family = socket.AF_UNSPEC
 
 def usage(f = sys.stdout):
     print >> f, """\
@@ -22,6 +23,8 @@ Usage: %(progname)s [REMOTE][:PORT]
 Register with a flash proxy facilitator using an HTTP POST. By default the
 remote address registered is "%(remote_addr)s".
 
+  -4                     name lookups use only IPv4.
+  -6                     name lookups use only IPv6.
   -f, --facilitator=URL  register with the given facilitator
                            (by default "%(fac_url)s").
   -h, --help             show this help. \
@@ -84,9 +87,13 @@ def format_addr(addr):
 options.facilitator_url = DEFAULT_FACILITATOR_URL
 options.remote_addr = (DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT)
 
-opts, args = getopt.gnu_getopt(sys.argv[1:], "f:h", ["facilitator=", "help"])
+opts, args = getopt.gnu_getopt(sys.argv[1:], "46f:h", ["facilitator=", "help"])
 for o, a in opts:
-    if o == "-f" or o == "--facilitator":
+    if o == "-4":
+        options.address_family = socket.AF_INET
+    elif o == "-6":
+        options.address_family = socket.AF_INET6
+    elif o == "-f" or o == "--facilitator":
         options.facilitator_url = a
     elif o == "-h" or o == "--help":
         usage()
@@ -100,6 +107,12 @@ else:
     usage(sys.stderr)
     sys.exit(1)
 
+if options.address_family != socket.AF_UNSPEC:
+    getaddrinfo = socket.getaddrinfo
+    def getaddrinfo_replacement(host, port, family, *args, **kwargs):
+        return getaddrinfo(host, port, options.address_family, *args, **kwargs)
+    socket.getaddrinfo = getaddrinfo_replacement
+
 spec = format_addr(options.remote_addr)
 try:
     http = urllib2.urlopen(options.facilitator_url, urllib.urlencode({"client": spec}), 10)





More information about the tor-commits mailing list