You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2007/04/20 14:50:54 UTC

svn commit: r530777 - /incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/Main.java

Author: rgreig
Date: Fri Apr 20 05:50:54 2007
New Revision: 530777

URL: http://svn.apache.org/viewvc?view=rev&rev=530777
Log:
Copied fix for invalid IP bytes greater than 127 from trunk.

Modified:
    incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/Main.java

Modified: incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/Main.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/Main.java?view=diff&rev=530777&r1=530776&r2=530777
==============================================================================
--- incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/Main.java (original)
+++ incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/Main.java Fri Apr 20 05:50:54 2007
@@ -71,6 +71,9 @@
 
     private static final String DEFAULT_LOG_CONFIG_FILENAME = "log4j.xml";
     public static final String QPID_HOME = "QPID_HOME";
+    private static final int IPV4_ADDRESS_LENGTH = 4;
+    
+    private static final char IPV4_LITERAL_SEPARATOR = '.';    
 
     protected static class InitException extends Exception
     {
@@ -395,28 +398,30 @@
 
     private byte[] parseIP(String address) throws Exception
     {
-        StringTokenizer tokenizer = new StringTokenizer(address, ".");
-        byte[] ip = new byte[4];
-        int index = 0;
-        while (tokenizer.hasMoreTokens())
+        char[] literalBuffer = address.toCharArray();    
+        int byteCount = 0;
+        int currByte = 0;
+        byte[] ip = new byte[IPV4_ADDRESS_LENGTH];
+        for (int i = 0 ; i < literalBuffer.length ; i++) 
         {
-            String token = tokenizer.nextToken();
-            try
+            char currChar = literalBuffer[i];
+            if ((currChar >= '0') && (currChar <= '9')) 
             {
-                ip[index++] = Byte.parseByte(token);
-            }
-            catch (NumberFormatException e)
+            	currByte = (currByte * 10) + (Character.digit(currChar, 10) & 0xFF);
+            } 
+
+            if (currChar == IPV4_LITERAL_SEPARATOR || (i + 1 == literalBuffer.length)) 
             {
-                throw new Exception("Error parsing IP address: " + address, e);
-            }
+                ip[byteCount++] = (byte)currByte;
+                currByte = 0;
+            } 
         }
 
-        if (index != 4)
+        if (byteCount != 4)
         {
             throw new Exception("Invalid IP address: " + address);
-        }
-
-        return ip;
+        }     
+        return ip;        
     }
 
     private void configureLogging(File logConfigFile, String logWatchConfig)