--- JBPAPP_4_2_0_GA_CP/naming/src/main/org/jnp/interfaces/NamingContext.java	2009-10-21 17:17:47.000000000 -0400
+++ /tmp/jboss-eap-4.2-src-cp/naming/src/main/org/jnp/interfaces/NamingContext.java	2009-10-21 17:41:07.000000000 -0400
@@ -334,34 +334,61 @@
 
             try
             {
-               // Parse the url into a host:port form, stripping any protocol
-               Name urlAsName = new NamingParser().parse(url);
-               String server = parseNameForScheme(urlAsName, null);
-               if (server != null)
-                  url = server;
-               int colon = url.indexOf(':');
-               if (colon < 0)
-               {
-                  host = url.trim();
-               }
-               else
-               {
-                  host = url.substring(0, colon).trim();
-                  try
-                  {
-                     port = Integer.parseInt(url.substring(colon + 1).trim());
-                  }
-                  catch (Exception ex)
-                  {
-                     // Use default;
-                  }
-               }
-
-               // Remove server from map
-               synchronized (NamingContext.class)
-               {
-                  cachedServers.remove(host + ":" + port);
-               }
+            	// Parse the url into a host:port form, stripping any protocol
+            	Name urlAsName = new NamingParser().parse(url);
+            	String server = parseNameForScheme(urlAsName, null);
+            	if (server != null)
+            		url = server;
+
+            	// assume host port combinations <IPv4>, <IPv4>:port, [<IPv6>] or [<IPv6>]:port
+            	int colon = url.indexOf(':');
+            	int rightbracket = url.indexOf(']') ;
+            	int lastcolon = url.lastIndexOf(':') ;
+
+            	if (rightbracket < 0) {
+            		// assume IPv4 host port combination
+            		if (colon < 0)
+            		{
+            			host = url.trim();
+            		}
+            		else
+            		{
+            			host = url.substring(0, colon).trim();
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(colon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+            	else {
+            		// assume IPv6 host port combination
+            		if (lastcolon < rightbracket)
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            		}
+            		else
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(lastcolon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+
+            	// Remove server from map
+            	synchronized (NamingContext.class)
+            	{
+            		cachedServers.remove(host + ":" + port);
+            	}
             }
             catch (NamingException ignored)
             {
@@ -1429,6 +1456,7 @@
          s.send(packet);
          // Look for a reply
          // IP address + port number = 128.128.128.128:65535 => (12+3) + 1 + (5) = 21
+         // IP address + port number = ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:65535 => (8*4+7) + 1 + (5) = 45
 
          buf = new byte[50];
          packet = new DatagramPacket(buf, buf.length);
@@ -1449,7 +1477,8 @@
          String serverHost;
          int serverPort;
 
-         int colon = myServer.indexOf(':');
+         // the last colon always precedes the port, whether IPv4 or IPv6
+         int colon = myServer.lastIndexOf(':');
          if (colon >= 0)
          {
             serverHost = myServer.substring(0, colon);
@@ -1504,39 +1533,67 @@
 
             while (naming == null && tokenizer.hasMoreElements())
             {
-               String url = tokenizer.nextToken();
-               // Parse the url into a host:port form, stripping any protocol
-               Name urlAsName = getNameParser("").parse(url);
-               String server = parseNameForScheme(urlAsName, null);
-               if (server != null)
-                  url = server;
-               int colon = url.indexOf(':');
-               if (colon < 0)
-               {
-                  host = url;
-               }
-               else
-               {
-                  host = url.substring(0, colon).trim();
-                  try
-                  {
-                     port = Integer.parseInt(url.substring(colon + 1).trim());
-                  }
-                  catch (Exception ex)
-                  {
-                     // Use default;
-                  }
-               }
-               try
-               {
-                  // Get server from cache
-                  naming = getServer(host, port, refEnv);
-               }
-               catch (Exception e)
-               {
-                  serverEx = e;
-                  log.debug("Failed to connect to " + host + ":" + port, e);
-               }
+            	String url = tokenizer.nextToken();
+            	// Parse the url into a host:port form, stripping any protocol
+            	Name urlAsName = getNameParser("").parse(url);
+            	String server = parseNameForScheme(urlAsName, null);
+            	if (server != null)
+            		url = server;
+
+            	// assume host port combinations <IPv4>, <IPv4>:port, [<IPv6>] or [<IPv6>]:port
+            	int colon = url.indexOf(':');
+            	int rightbracket = url.indexOf(']') ;
+            	int lastcolon = url.lastIndexOf(':') ;
+
+            	if (rightbracket < 0) {
+            		// assume IPv4 host port combination
+            		if (colon < 0)
+            		{
+            			host = url.trim();
+            		}
+            		else
+            		{
+            			host = url.substring(0, colon).trim();
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(colon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+            	else {
+            		// assume IPv6 host port combination
+            		if (lastcolon < rightbracket)
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            		}
+            		else
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(lastcolon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+
+            	try
+            	{
+            		// Get server from cache
+            		naming = getServer(host, port, refEnv);
+            	}
+            	catch (Exception e)
+            	{
+            		serverEx = e;
+            		log.debug("Failed to connect to " + host + ":" + port, e);
+            	}
             }
 
             // If there is still no
