[or-cvs] r14276: Make forwardPort method more robust (torbrowser/trunk/src/current-patches)

sjm217 at seul.org sjm217 at seul.org
Tue Apr 1 17:23:52 UTC 2008


Author: sjm217
Date: 2008-04-01 13:23:52 -0400 (Tue, 01 Apr 2008)
New Revision: 14276

Modified:
   torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch
Log:
Make forwardPort method more robust

Modified: torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch
===================================================================
--- torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch	2008-04-01 16:09:31 UTC (rev 14275)
+++ torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch	2008-04-01 17:23:52 UTC (rev 14276)
@@ -1,7 +1,20 @@
-Index: CMakeLists.txt
+Index: INSTALL
 ===================================================================
---- CMakeLists.txt	(revision 2473)
-+++ CMakeLists.txt	(working copy)
+--- INSTALL	(revision 2465)
++++ INSTALL	(working copy)
+@@ -206,3 +206,8 @@
+ 'cmake --help' or 'man cmake' (on non-Windows platforms) for more information
+ about supported generators and configuration options.
+ 
++Including UPnP support
++----------------------
++
++cmake -G "MSYS Makefiles" -DMINIUPNPC_LIBRARY_DIR="/usr/local/lib" -DMINIUPNPC_INCLUDE_DIR="/usr/local/include" .
++
+Index: src/vidalia/CMakeLists.txt
+===================================================================
+--- src/vidalia/CMakeLists.txt	(revision 2473)
++++ src/vidalia/CMakeLists.txt	(working copy)
 @@ -16,6 +16,7 @@
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/config
@@ -43,10 +56,10 @@
    torcontrol
    util
  )
-Index: config/serversettings.cpp
+Index: src/vidalia/config/serversettings.cpp
 ===================================================================
---- config/serversettings.cpp	(revision 2473)
-+++ config/serversettings.cpp	(working copy)
+--- src/vidalia/config/serversettings.cpp	(revision 2473)
++++ src/vidalia/config/serversettings.cpp	(working copy)
 @@ -20,6 +20,7 @@
  
  #include "serversettings.h"
@@ -83,10 +96,10 @@
  /** Virtual method called when we retrieve a server-related setting from Tor.
   * Currently this just translates BandwidthFoo to RelayBandwidthFoo when
   * appropriate. */
-Index: config/serversettings.h
+Index: src/vidalia/config/serversettings.h
 ===================================================================
---- config/serversettings.h	(revision 2473)
-+++ config/serversettings.h	(working copy)
+--- src/vidalia/config/serversettings.h	(revision 2473)
++++ src/vidalia/config/serversettings.h	(working copy)
 @@ -91,6 +91,9 @@
  private:
    /** Returns Tor-recognizable configuration keys and current values. */
@@ -97,11 +110,11 @@
  };
  
  #endif
-Index: config/upnpcontrol.cpp
+Index: src/vidalia/config/upnpcontrol.cpp
 ===================================================================
---- config/upnpcontrol.cpp	(revision 0)
-+++ config/upnpcontrol.cpp	(revision 0)
-@@ -0,0 +1,93 @@
+--- src/vidalia/config/upnpcontrol.cpp	(revision 0)
++++ src/vidalia/config/upnpcontrol.cpp	(revision 0)
+@@ -0,0 +1,129 @@
 +/*
 +**  This file is part of Vidalia, and is subject to the license terms in the
 +**  LICENSE file, found in the top level directory of this distribution. If 
@@ -133,10 +146,46 @@
 +  init_upnp();
 +}
 +
-+void
-+UPNPControl::forwardPort(int port)
++int
++UPNPControl::forwardPort(quint16 port)
 +{
-+  upnp_add_redir(lanaddr, port);
++  int retval;
++  
++  char sPort[6];
++  
++  char intClient[16];
++  char intPort[6];
++
++  // Convert the port number to a string
++  snprintf(sPort, sizeof(sPort), "%d", port);
++
++  // Add the port mapping of external:port -> internal:port
++  retval = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
++			       sPort, sPort, lanaddr, "Tor server", "TCP");
++  if(UPNPCOMMAND_SUCCESS != retval) {
++    printf("AddPortMapping(%s, %s, %s) failed with code %d\n",
++	   sPort, sPort, lanaddr, retval);
++    return 1;
++  }
++  
++  // Check if the port mapping was accepted
++  retval = UPNP_GetSpecificPortMappingEntry(urls.controlURL,
++					    data.servicetype,
++					    sPort, "TCP",
++					    intClient, intPort);
++  if(UPNPCOMMAND_SUCCESS != retval) {
++    printf("GetSpecificPortMappingEntry() failed with code %d\n", retval);
++    return 2;
++  }
++  
++  if(! intClient[0]) {
++    printf("GetSpecificPortMappingEntry failed.\n");
++    return 3;
++  }
++  
++  // Output the mapping
++  printf("(external):%s -> %s:%s\n", sPort, intClient, intPort);
++  return 0;
 +}
 +
 +/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
@@ -171,7 +220,7 @@
 +		fflush(stdout);
 +		return;
 +	}
-+	sprintf(port_str, "%d", port);
++	
 +	r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
 +	                        port_str, port_str, addr, 0, "TCP");
 +	if(r==0)
@@ -195,10 +244,10 @@
 +	sprintf(port_str, "%d", port);
 +	UPNP_DeletePortMapping(urls.controlURL, data.servicetype, port_str, "TCP");
 +}
-Index: config/upnpcontrol.h
+Index: src/vidalia/config/upnpcontrol.h
 ===================================================================
---- config/upnpcontrol.h	(revision 0)
-+++ config/upnpcontrol.h	(revision 0)
+--- src/vidalia/config/upnpcontrol.h	(revision 0)
++++ src/vidalia/config/upnpcontrol.h	(revision 0)
 @@ -0,0 +1,48 @@
 +/*
 +**  This file is part of Vidalia, and is subject to the license terms in the
@@ -232,7 +281,7 @@
 +
 +public:
 +  static UPNPControl* Instance();
-+  void forwardPort(int port);
++  int forwardPort(quint16 port);
 +protected:
 +  UPNPControl();
 +private:



More information about the tor-commits mailing list