1
--- a/package/busybox/busybox-02-nc-ll.patch 1970-01-01 00:00:00.000000000 +0000
2
+++ b/package/busybox/busybox-02-nc-ll.patch 2015-04-21 10:58:50.000000000 +0000
4
+From de6f14800675cd0401106876da81da7618de71c6 Mon Sep 17 00:00:00 2001
5
+From: Denys Vlasenko <vda.linux@googlemail.com>
6
+Date: Thu, 28 Feb 2013 11:20:06 +0000
7
+Subject: nc_bloaty: support -ll and -lk. Closes 2245
9
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11
+diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
12
+index 62a0251..00ba6f1 100644
13
+--- a/networking/nc_bloaty.c
14
++++ b/networking/nc_bloaty.c
16
+ //usage: " -e PROG Run PROG after connect (must be last)"
17
+ //usage: IF_NC_SERVER(
18
+ //usage: "\n -l Listen mode, for inbound connects"
19
++//usage: "\n -lk With -e, provides persistent server"
20
++/* -ll does the same as -lk, but its our extension, while -k is BSD'd,
22
+ //usage: "\n -p PORT Local port"
23
+ //usage: "\n -s ADDR Local address"
24
+@@ -166,18 +172,14 @@ enum {
27
+ OPT_l = (1 << 6) * ENABLE_NC_SERVER,
28
+- OPT_i = (1 << (6+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
29
+- OPT_o = (1 << (7+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
30
+- OPT_z = (1 << (8+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
31
++ OPT_k = (1 << 7) * ENABLE_NC_SERVER,
32
++ OPT_i = (1 << (7+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
33
++ OPT_o = (1 << (8+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
34
++ OPT_z = (1 << (9+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
37
+ #define o_nflag (option_mask32 & OPT_n)
38
+ #define o_udpmode (option_mask32 & OPT_u)
39
+-#if ENABLE_NC_SERVER
40
+-#define o_listen (option_mask32 & OPT_l)
45
+ #define o_ofile (option_mask32 & OPT_o)
46
+ #define o_zero (option_mask32 & OPT_z)
47
+@@ -298,7 +300,7 @@ static int connect_w_timeout(int fd)
48
+ incoming and returns an open connection *from* someplace. If we were
49
+ given host/port args, any connections from elsewhere are rejected. This
50
+ in conjunction with local-address binding should limit things nicely... */
51
+-static void dolisten(void)
52
++static void dolisten(int is_persistent, char **proggie)
56
+@@ -371,6 +373,7 @@ create new one, and bind() it. TODO */
57
+ xconnect(netfd, &remend.u.sa, ouraddr->len);
60
+ arm(o_wait); /* wrap this in a timer, too; 0 = forever */
61
+ if (setjmp(jbuf) == 0) {
63
+@@ -405,6 +408,19 @@ create new one, and bind() it. TODO */
66
+ bb_error_msg_and_die("timeout");
68
++ if (is_persistent && proggie) {
69
++ /* -l -k -e PROG */
70
++ signal(SIGCHLD, SIG_IGN); /* no zombies please */
71
++ if (xvfork() != 0) {
72
++ /* parent: go back and accept more connections */
77
++ signal(SIGCHLD, SIG_DFL);
80
+ xmove_fd(rr, netfd); /* dump the old socket, here's our new one */
81
+ /* find out what address the connection was *to* on our end, in case we're
82
+ doing a listen-on-any on a multihomed machine. This allows one to
83
+@@ -454,6 +470,9 @@ create new one, and bind() it. TODO */
93
+@@ -730,6 +749,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
94
+ char *themdotted = themdotted; /* for compiler */
97
++ unsigned cnt_l = 0;
98
+ unsigned o_lport = 0;
101
+@@ -760,7 +780,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
102
+ if (proggie[0][0] == '-') {
103
+ char *optpos = *proggie + 1;
104
+ /* Skip all valid opts w/o params */
105
+- optpos = optpos + strspn(optpos, "nuv"IF_NC_SERVER("l")IF_NC_EXTRA("z"));
106
++ optpos = optpos + strspn(optpos, "nuv"IF_NC_SERVER("lk")IF_NC_EXTRA("z"));
107
+ if (*optpos == 'e' && !optpos[1]) {
110
+@@ -774,17 +794,21 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
113
+ // -g -G -t -r deleted, unimplemented -a deleted too
114
+- opt_complementary = "?2:vv:w+"; /* max 2 params; -v is a counter; -w N */
115
+- getopt32(argv, "np:s:uvw:" IF_NC_SERVER("l")
116
++ opt_complementary = "?2:vv:ll:w+"; /* max 2 params; -v and -l are counters; -w N */
117
++ getopt32(argv, "np:s:uvw:" IF_NC_SERVER("lk")
118
+ IF_NC_EXTRA("i:o:z"),
119
+ &str_p, &str_s, &o_wait
120
+- IF_NC_EXTRA(, &str_i, &str_o), &o_verbose);
121
++ IF_NC_EXTRA(, &str_i, &str_o), &o_verbose IF_NC_SERVER(, &cnt_l));
123
+ #if ENABLE_NC_EXTRA
124
+ if (option_mask32 & OPT_i) /* line-interval time */
125
+ o_interval = xatou_range(str_i, 1, 0xffff);
127
++#if ENABLE_NC_SERVER
128
+ //if (option_mask32 & OPT_l) /* listen mode */
129
++ if (option_mask32 & OPT_k) /* persistent server mode */
132
+ //if (option_mask32 & OPT_n) /* numeric-only, no DNS lookups */
133
+ //if (option_mask32 & OPT_o) /* hexdump log */
134
+ if (option_mask32 & OPT_p) { /* local source port */
135
+@@ -833,7 +857,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
137
+ socket_want_pktinfo(netfd);
138
+ if (!ENABLE_FEATURE_UNIX_LOCAL
140
++ || cnt_l != 0 /* listen */
141
+ || ouraddr->u.sa.sa_family != AF_UNIX
143
+ xbind(netfd, &ouraddr->u.sa, ouraddr->len);
144
+@@ -862,11 +886,9 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
145
+ xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), ofd);
151
++ dolisten((cnt_l - 1), proggie);
152
+ /* dolisten does its own connect reporting */
153
+- if (proggie) /* -e given? */
155
+ x = readwrite(); /* it even works with UDP! */
157
+ /* Outbound connects. Now we're more picky about args... */