From 794687947fe9eb15b2512a0d9645d827348c5f6f Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Wed, 4 Apr 2007 11:02:55 +0000 Subject: Add/improve comment, shorten some usage texts. No code changes. --- ipsvd/tcpudp.c | 21 ++++++++++++++++++++- ipsvd/udp_io.c | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'ipsvd') diff --git a/ipsvd/tcpudp.c b/ipsvd/tcpudp.c index 9f098c32e..66f44e9a6 100644 --- a/ipsvd/tcpudp.c +++ b/ipsvd/tcpudp.c @@ -331,12 +331,31 @@ int tcpudpsvd_main(int argc, char **argv) * to ones coming from this remote IP. */ xconnect(0, &remote.sa, sa_len); /* hole? at this point we have no wildcard udp socket... - * can this cause clients to get "port unreachable" icmp? */ + * can this cause clients to get "port unreachable" icmp? + * Yup, time window is very small, but it exists (is it?) */ /* Open new non-connected UDP socket for further clients */ sock = xsocket(lsa->sa.sa_family, tcp ? SOCK_STREAM : SOCK_DGRAM, 0); setsockopt_reuseaddr(sock); xbind(sock, &lsa->sa, sa_len); socket_want_pktinfo(sock); + + /* Doesn't work: + * we cannot replace fd #0 - we will lose pending packet + * which is already buffered for us! And we cannot use fd #1 + * instead - it will "intercept" all following packets, but child + * do not expect data coming *from fd #1*! */ +#if 0 + /* Make it so that local addr is fixed to localp->sa + * and we don't accidentally accept packets to other local IPs. */ + /* NB: we possibly bind to the _very_ same_ address & port as the one + * already bound in parent! This seems to work in Linux. + * (otherwise we can move socket to fd #0 only if bind succeeds) */ + close(0); + set_nport(localp, htons(local_port)); + xmove_fd(xsocket(localp->sa.sa_family, SOCK_DGRAM, 0), 0); + setsockopt_reuseaddr(0); /* crucial */ + xbind(0, &localp->sa, localp->len); +#endif } pid = fork(); diff --git a/ipsvd/udp_io.c b/ipsvd/udp_io.c index 2efc15913..592d98b58 100644 --- a/ipsvd/udp_io.c +++ b/ipsvd/udp_io.c @@ -95,7 +95,7 @@ send_to_from(int fd, void *buf, size_t len, int flags, /* NB: this will never set port# in 'to'! * _Only_ IP/IPv6 address part of 'to' is _maybe_ modified. - * Typical usage is to preinit it with "default" value + * Typical usage is to preinit 'to' with "default" value * before calling recv_from_to(). */ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags, -- cgit v1.2.3