I have a jsp that uses the getLocalAddr() method for some ssl certificate generation utility and it's currently returning the hostname instaed of the IP. After much digging through the Tomcat source I found the snippet below: org\apache\coyote\http11\Http11AprProcessor.java } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) { // Get local host address if (localAddr == null) { try { long sa = Address.get(Socket.APR_LOCAL, socket); remoteAddr = Address.getip(sa); if (Address.fill(addr, sa)) { localAddr = addr.hostname; localPort = addr.port; } } catch (Exception e) { log.warn(sm.getString("http11processor.socket.info"), e); } } request.localAddr().setString(localAddr); } Should the code above be changed to the snipit below so that the ip address is coming back instead of the hostname as expected? } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) { // Get local host address if (localAddr == null) { try { long sa = Address.get(Socket.APR_LOCAL, socket); localAddr = Address.getip(sa); } catch (Exception e) { log.warn(sm.getString("http11processor.socket.info"), e); } } request.localAddr().setString(localAddr); } If not I would love to know why the hostName/port are being returned instead of the IP thanx!
First, the current code is: } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) { // Get local host address if (localAddr == null && (socket != 0)) { try { long sa = Address.get(Socket.APR_LOCAL, socket); Sockaddr addr = new Sockaddr(); if (Address.fill(addr, sa)) { localAddr = addr.hostname; localPort = addr.port; } } catch (Exception e) { log.warn(sm.getString("http11processor.socket.info"), e); } } request.localAddr().setString(localAddr); Then, I don't really care about this issue, so please stop spamming me about it.
The issue is now fixed.
*** Bug 37693 has been marked as a duplicate of this bug. ***
Remy you do not care if your code is up to servlet 2.4 specification? Trust me, I am not doing this to waste your or my time... I am a professional Java developer using Tomcat in a production evironment. We want to use the APR connector, but this bug is forcing me to recommend we NOT use it. If you won't fix it I can look into fixing it myself.
Created attachment 17077 [details] JSP example demonstrating the bug Simple JSP demonstrating the bug This JSP demonstrates the bug clearly. It has both request.getLocalName() which should return the local server's hostname. It also has request.getLocalAddr() which returns the machines hostname, it should return the local server's IP address. Open the .jsp in Tomcat 5.5.12 using the APR native connector.
Looks like it's been resolved and fixed! Remy is the MAN!!!! /bow http://svn.apache.org/viewcvs.cgi/tomcat/connectors/trunk/http11/src/java/org/ap ache/coyote/http11/Http11AprProcessor.java?rev=349715&view=markup My bad Remy, didn't see your fixed post above... I was too busy creating the duplicate bug 37693... still learning about the whole apache dev process sorry for any inconvenience it might have caused you.