Question

I am running a small java server through xinetd superserver. I'd like to get the originating client IP but I can't because streams are between xinetd and java (stin/stdout).

Does somebody know how to get the client IP, without looking to xinetd logfile ? (seems a bad solution to me)

Thanks !

Was it helpful?

Solution

Given the situation you have described, trawling the xinetd logfile is your only option.

If your Java application is talking to the client via its standard input and standard output, there is no way for the application to access the underlying socket. Indeed, I don't think you could do this in any language.

EDIT : actually, you probably could do this in C and C++ because they expose the file descriptors (fds) and have library APIs for doing socket operations using fds.

But it won't work in pure Java. Even if you could drill down to the fd inside the Stream objects associated with System.in or System.out, I don't think that the Java class libraries provide an API for turning the fd into a Socket object. To do socket operations on the fd's 0 and 1 you would need to resort to JNI and native code.

And as the commenter points out, if the real client is behind a proxy, the client IP that you get from the socket will be the IP of the proxy.

OTHER TIPS

I think you can call getpeername on TCP sockets (but not UDP), see Stevens chapter 4.10.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top