+ public SocketAddress remoteaddr() {
+ try {
+ /* Apparently getRemotePort returns -1 when running on Tomcat over AJP. */
+ int port = req.getRemotePort();
+ if(port < 0)
+ port = 0;
+ return(new InetSocketAddress(InetAddress.getByName(req.getRemoteAddr()), port));
+ } catch(UnknownHostException e) {
+ /* req.getRemoteAddr should always be a valid IP address,
+ * so this should never happen. */
+ throw(new Error(e));
+ }
+ }
+
+ public SocketAddress localaddr() {
+ try {
+ return(new InetSocketAddress(InetAddress.getByName(req.getLocalAddr()), req.getLocalPort()));
+ } catch(UnknownHostException e) {
+ /* req.getRemoteAddr should always be a valid IP address,
+ * so this should never happen. */
+ throw(new Error(e));
+ }