[lkml]   [1996]   [Oct]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread

> 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 <>
-- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
-- Amsterdam, The Netherlands | Fax: +31 20 6948204

 \ /
  Last update: 2005-03-22 13:37    [W:0.024 / U:0.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site