2

Does anyone know if there's an existing library out there that will allow me to make a call to getsockopt to get the destination IP for a socket that iptables has rerouted through my Java application?

Here's a similar question on the Netty mailing list that went unanswered.

The call in c would look something like:

getsockopt(ctx->client.fd, SOL_IP, 
    SO_ORIGINAL_DST, &SANY_ADDR(addr), &SANY_LEN(addr))

Example of how to do it with JNI also welcome.

Jamie McCrindle
  • 9,114
  • 6
  • 43
  • 48

2 Answers2

1

You can't do it in Java. You could do it in JNI exactly as you have written, if you can get the socket FD, which is in the SocketImpl of the Socket.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • @downvoter If you think it can be done in Java with no JNI please share your solution with us, so it can be commented on, voted on, etc. – user207421 Mar 21 '14 at 07:15
0

You can't do it in Java . However you can add a request header param which store the original_dst. So you can use it from http header when you need.

QiZeng
  • 1
  • 1