I have code running on the server in a login servlet - in the case which is causing concern we're using a clustering solution which results in multiple IP addresses being active (on different interfaces) for the same machine. One is the 'normal' address and one is the 'cluster'. (i.e. one machine at a time 'owns' the cluster address).
For various reasons, I need to know which IP address is being used on a given servlet call. (i.e. the machine's normal eth0 address is 188.8.131.52, and it also has an eth0:0 address of 184.108.40.206 (cluster); the servlet needs to know which one is being used for the current HTTP activity so I can potentially tell them "don't log in here; log in there instead").
getServerName() works somewhat - but provides a hostname if the user had connected that way from the client. That makes me unsure that this is even going to work for the case I'm concerned about. Basically we used to do this on the client side but discovered that the NAT case doesn't work with this (where the servers are behind a NAT and thus the client can't compare what it sees in a well-known spot on the server against its own settings, since the client's versions of the addresses aren't the same).
followup: I now see the method getLocalAddr() was added in Servlet 2.4. Unfortunately, I'm stuck for now with Servlet 2.3 (can't afford to upgrade our embedded Tomcat to 5 at this point - way too risky). Any hacks which can get me there on 2.3?