Re: IP_TRANSPARENT_PROXY

Jos Vos (jos@xos.nl)
Tue, 1 Oct 1996 11:05:35 +0200 (MET DST)


Hi,

> I've been meaning to ask this for a while. When one uses ipfw(4) to
> forward ip traffic to a local socket using transparent proxying, this
> poses an interesting problem for the server tending that socket. How
> does one determine the original address to which that traffic was sent?
>
> In other words, I am a proxy. I do a recv() on a datagram socket, which
> I know has data redirected into it. I know who sent that data; recv
> tells me. How do I know to whom that data was addressed? I can't seem
> to find a suitable call to yield this information...

For TCP, you can just do a getsockname(). It will return the destination
address, not a local address. Note that you can also do a bind() for a
non-local address (being root).

For UDP using recvfrom(), there is a trick... ;-)
You can add MSG_PROXY to the flags, and you'll get the destination
address back in the unused part of the struct sockaddr. This _is_
dirty, but we intended to implement it without adding system calls,
so this was the way to go (at least, for the moment). And proxying
UDP might not be used that much anyway. For the UDP-part, we have
an extra include file providing the UDP-trick in an inline-function.

Hope this helps.

-- 
--    Jos Vos <jos@xos.nl>
--    X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--    Amsterdam, The Netherlands        |     Fax: +31 20 6948204