diff --git a/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java b/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
index 0a61335a930bb83fc2c39862ad606a222bbd2ca7..569fe786a38cf8e02cb0e668bb5a3b9ef5bc529c 100644
--- a/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
+++ b/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
@@ -163,7 +163,24 @@ class PeerTestManager {
         if (_currentTestComplete)
             return;
         if ( (DataHelper.eq(from.getIP(), test.getBobIP().getAddress())) && (from.getPort() == test.getBobPort()) ) {
-            byte ip[] = new byte[testInfo.readIPSize()];
+            // The reply is from Bob
+
+            int ipSize = testInfo.readIPSize();
+            if (ipSize != 4 && ipSize != 16) {
+                // There appears to be a bug where Bob is sending us a zero-length IP.
+                // We could proceed without setting the IP, but then when Charlie
+                // sends us his message, we will think we are behind a symmetric NAT
+                // because the Bob and Charlie IPs won't match.
+                // So for now we just return and pretend we didn't hear from Bob at all.
+                // Which is essentially what catching the uhe below did,
+                // but without the error message to the log.
+                // To do: fix the bug.
+                if (_log.shouldLog(Log.WARN))
+                    _log.warn("Bad IP length " + ipSize +
+                               " from bob's reply: " + from + ", " + testInfo);
+                return;
+            }
+            byte ip[] = new byte[ipSize];
             testInfo.readIP(ip, 0);
             try {
                 InetAddress addr = InetAddress.getByAddress(ip);
@@ -177,10 +194,12 @@ class PeerTestManager {
                     testComplete(false);
             } catch (UnknownHostException uhe) {
                 if (_log.shouldLog(Log.ERROR))
-                    _log.error("Unable to get our IP (length " + ip.length +
+                    _log.error("Unable to get our IP (length " + ipSize +
                                ") from bob's reply: " + from + ", " + testInfo, uhe);
             }
         } else {
+            // The reply is from Charlie
+
             PeerState charlieSession = _transport.getPeerState(from);
             long recentBegin = _context.clock().now() - CHARLIE_RECENT_PERIOD;
             if ( (charlieSession != null) && 
diff --git a/router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java b/router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java
index cffb8fd8bdb931bec3733689fb0c8d22b6240b19..26563c210f8997f9b82ab15fa691da4392ef9cef 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java
@@ -82,6 +82,8 @@ public class UDPEndpoint {
 ********/
     
     /** 8998 is monotone, and 32000 is the wrapper, so let's stay between those */
+    public static final String PROP_MIN_PORT = "i2np.udp.minPort";
+    public static final String PROP_MAX_PORT = "i2np.udp.maxPort";
     private static final int MIN_RANDOM_PORT = 9111;
     private static final int MAX_RANDOM_PORT = 31777;
     private static final int MAX_PORT_RETRIES = 20;
@@ -100,7 +102,9 @@ public class UDPEndpoint {
              if (port <= 0) {
                  // try random ports rather than just do new DatagramSocket()
                  // so we stay out of the way of other I2P stuff
-                 port = MIN_RANDOM_PORT + _context.random().nextInt(MAX_RANDOM_PORT - MIN_RANDOM_PORT);
+                 int minPort = _context.getProperty(PROP_MIN_PORT, MIN_RANDOM_PORT);
+                 int maxPort = _context.getProperty(PROP_MAX_PORT, MAX_RANDOM_PORT);
+                 port = minPort + _context.random().nextInt(maxPort - minPort);
              }
              try {
                  if (_bindAddress == null)