aboutsummaryrefslogtreecommitdiff
path: root/networking/tcpudp.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--networking/tcpudp.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index b532e43cd..a2b8c958c 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -29,6 +29,43 @@
29 * - don't know how to retrieve ORIGDST for udp. 29 * - don't know how to retrieve ORIGDST for udp.
30 */ 30 */
31 31
32//usage:#define tcpsvd_trivial_usage
33//usage: "[-hEv] [-c N] [-C N[:MSG]] [-b N] [-u USER] [-l NAME] IP PORT PROG"
34/* with not-implemented options: */
35/* //usage: "[-hpEvv] [-c N] [-C N[:MSG]] [-b N] [-u USER] [-l NAME] [-i DIR|-x CDB] [-t SEC] IP PORT PROG" */
36//usage:#define tcpsvd_full_usage "\n\n"
37//usage: "Create TCP socket, bind to IP:PORT and listen\n"
38//usage: "for incoming connection. Run PROG for each connection.\n"
39//usage: "\n IP IP to listen on. '0' = all"
40//usage: "\n PORT Port to listen on"
41//usage: "\n PROG ARGS Program to run"
42//usage: "\n -l NAME Local hostname (else looks up local hostname in DNS)"
43//usage: "\n -u USER[:GRP] Change to user/group after bind"
44//usage: "\n -c N Handle up to N connections simultaneously"
45//usage: "\n -b N Allow a backlog of approximately N TCP SYNs"
46//usage: "\n -C N[:MSG] Allow only up to N connections from the same IP."
47//usage: "\n New connections from this IP address are closed"
48//usage: "\n immediately. MSG is written to the peer before close"
49//usage: "\n -h Look up peer's hostname"
50//usage: "\n -E Don't set up environment variables"
51//usage: "\n -v Verbose"
52//usage:
53//usage:#define udpsvd_trivial_usage
54//usage: "[-hEv] [-c N] [-u USER] [-l NAME] IP PORT PROG"
55//usage:#define udpsvd_full_usage "\n\n"
56//usage: "Create UDP socket, bind to IP:PORT and wait\n"
57//usage: "for incoming packets. Run PROG for each packet,\n"
58//usage: "redirecting all further packets with same peer ip:port to it.\n"
59//usage: "\n IP IP to listen on. '0' = all"
60//usage: "\n PORT Port to listen on"
61//usage: "\n PROG ARGS Program to run"
62//usage: "\n -l NAME Local hostname (else looks up local hostname in DNS)"
63//usage: "\n -u USER[:GRP] Change to user/group after bind"
64//usage: "\n -c N Handle up to N connections simultaneously"
65//usage: "\n -h Look up peer's hostname"
66//usage: "\n -E Don't set up environment variables"
67//usage: "\n -v Verbose"
68
32#include "libbb.h" 69#include "libbb.h"
33 70
34/* Wants <limits.h> etc, thus included after libbb.h: */ 71/* Wants <limits.h> etc, thus included after libbb.h: */
@@ -387,7 +424,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
387 * already bound in parent! This seems to work in Linux. 424 * already bound in parent! This seems to work in Linux.
388 * (otherwise we can move socket to fd #0 only if bind succeeds) */ 425 * (otherwise we can move socket to fd #0 only if bind succeeds) */
389 close(0); 426 close(0);
390 set_nport(localp, htons(local_port)); 427 set_nport(&localp->u.sa, htons(local_port));
391 xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0); 428 xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0);
392 setsockopt_reuseaddr(0); /* crucial */ 429 setsockopt_reuseaddr(0); /* crucial */
393 xbind(0, &localp->u.sa, localp->len); 430 xbind(0, &localp->u.sa, localp->len);