diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-19 01:17:36 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-19 01:17:36 +0100 |
commit | 5e896481eb20b5a9738cf5f2e390b63574be28a2 (patch) | |
tree | 49fa3951cae92d7f9bc64a32fe84aeb7b3bc74ba /networking/nc_bloaty.c | |
parent | 7fe1e3f1612f6eb220d6a9796edacf24b7706876 (diff) | |
download | busybox-w32-5e896481eb20b5a9738cf5f2e390b63574be28a2.tar.gz busybox-w32-5e896481eb20b5a9738cf5f2e390b63574be28a2.tar.bz2 busybox-w32-5e896481eb20b5a9738cf5f2e390b63574be28a2.zip |
nc: support "-<other_opts>e PROG" form of -e option
function old new delta
nc_main 975 1033 +58
doexec 31 45 +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 72/0) Total: 72 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/nc_bloaty.c')
-rw-r--r-- | networking/nc_bloaty.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index d184f689b..62a025116 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -115,6 +115,7 @@ struct globals { | |||
115 | unsigned wrote_out; /* total stdout bytes */ | 115 | unsigned wrote_out; /* total stdout bytes */ |
116 | unsigned wrote_net; /* total net bytes */ | 116 | unsigned wrote_net; /* total net bytes */ |
117 | #endif | 117 | #endif |
118 | char *proggie0saved; | ||
118 | /* ouraddr is never NULL and goes through three states as we progress: | 119 | /* ouraddr is never NULL and goes through three states as we progress: |
119 | 1 - local address before bind (IP/port possibly zero) | 120 | 1 - local address before bind (IP/port possibly zero) |
120 | 2 - local address after bind (port is nonzero) | 121 | 2 - local address after bind (port is nonzero) |
@@ -127,7 +128,6 @@ struct globals { | |||
127 | 128 | ||
128 | jmp_buf jbuf; /* timer crud */ | 129 | jmp_buf jbuf; /* timer crud */ |
129 | 130 | ||
130 | /* will malloc up the following globals: */ | ||
131 | fd_set ding1; /* for select loop */ | 131 | fd_set ding1; /* for select loop */ |
132 | fd_set ding2; | 132 | fd_set ding2; |
133 | char bigbuf_in[BIGSIZ]; /* data buffers */ | 133 | char bigbuf_in[BIGSIZ]; /* data buffers */ |
@@ -159,17 +159,16 @@ struct globals { | |||
159 | 159 | ||
160 | /* Must match getopt32 call! */ | 160 | /* Must match getopt32 call! */ |
161 | enum { | 161 | enum { |
162 | OPT_h = (1 << 0), | 162 | OPT_n = (1 << 0), |
163 | OPT_n = (1 << 1), | 163 | OPT_p = (1 << 1), |
164 | OPT_p = (1 << 2), | 164 | OPT_s = (1 << 2), |
165 | OPT_s = (1 << 3), | 165 | OPT_u = (1 << 3), |
166 | OPT_u = (1 << 4), | 166 | OPT_v = (1 << 4), |
167 | OPT_v = (1 << 5), | 167 | OPT_w = (1 << 5), |
168 | OPT_w = (1 << 6), | 168 | OPT_l = (1 << 6) * ENABLE_NC_SERVER, |
169 | OPT_l = (1 << 7) * ENABLE_NC_SERVER, | 169 | OPT_i = (1 << (6+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA, |
170 | OPT_i = (1 << (7+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA, | 170 | OPT_o = (1 << (7+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA, |
171 | OPT_o = (1 << (8+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA, | 171 | OPT_z = (1 << (8+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA, |
172 | OPT_z = (1 << (9+ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA, | ||
173 | }; | 172 | }; |
174 | 173 | ||
175 | #define o_nflag (option_mask32 & OPT_n) | 174 | #define o_nflag (option_mask32 & OPT_n) |
@@ -263,6 +262,8 @@ Debug("findline returning whole thing: %d", siz); | |||
263 | static int doexec(char **proggie) NORETURN; | 262 | static int doexec(char **proggie) NORETURN; |
264 | static int doexec(char **proggie) | 263 | static int doexec(char **proggie) |
265 | { | 264 | { |
265 | if (G.proggie0saved) | ||
266 | proggie[0] = G.proggie0saved; | ||
266 | xmove_fd(netfd, 0); | 267 | xmove_fd(netfd, 0); |
267 | dup2(0, 1); | 268 | dup2(0, 1); |
268 | /* dup2(0, 2); - do we *really* want this? NO! | 269 | /* dup2(0, 2); - do we *really* want this? NO! |
@@ -726,7 +727,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv) | |||
726 | { | 727 | { |
727 | char *str_p, *str_s; | 728 | char *str_p, *str_s; |
728 | IF_NC_EXTRA(char *str_i, *str_o;) | 729 | IF_NC_EXTRA(char *str_i, *str_o;) |
729 | char *themdotted = themdotted; /* gcc */ | 730 | char *themdotted = themdotted; /* for compiler */ |
730 | char **proggie; | 731 | char **proggie; |
731 | int x; | 732 | int x; |
732 | unsigned o_lport = 0; | 733 | unsigned o_lport = 0; |
@@ -754,13 +755,27 @@ int nc_main(int argc UNUSED_PARAM, char **argv) | |||
754 | proggie++; | 755 | proggie++; |
755 | goto e_found; | 756 | goto e_found; |
756 | } | 757 | } |
758 | /* -<other_opts>e PROG [ARGS] ? */ | ||
759 | /* (aboriginal linux uses this form) */ | ||
760 | if (proggie[0][0] == '-') { | ||
761 | char *optpos = *proggie + 1; | ||
762 | /* Skip all valid opts w/o params */ | ||
763 | optpos = optpos + strspn(optpos, "nuv"IF_NC_SERVER("l")IF_NC_EXTRA("z")); | ||
764 | if (*optpos == 'e' && !optpos[1]) { | ||
765 | *optpos = '\0'; | ||
766 | proggie++; | ||
767 | G.proggie0saved = *proggie; | ||
768 | *proggie = NULL; /* terminate argv for getopt32 */ | ||
769 | goto e_found; | ||
770 | } | ||
771 | } | ||
757 | } | 772 | } |
758 | proggie = NULL; | 773 | proggie = NULL; |
759 | e_found: | 774 | e_found: |
760 | 775 | ||
761 | // -g -G -t -r deleted, unimplemented -a deleted too | 776 | // -g -G -t -r deleted, unimplemented -a deleted too |
762 | opt_complementary = "?2:vv:w+"; /* max 2 params; -v is a counter; -w N */ | 777 | opt_complementary = "?2:vv:w+"; /* max 2 params; -v is a counter; -w N */ |
763 | getopt32(argv, "hnp:s:uvw:" IF_NC_SERVER("l") | 778 | getopt32(argv, "np:s:uvw:" IF_NC_SERVER("l") |
764 | IF_NC_EXTRA("i:o:z"), | 779 | IF_NC_EXTRA("i:o:z"), |
765 | &str_p, &str_s, &o_wait | 780 | &str_p, &str_s, &o_wait |
766 | IF_NC_EXTRA(, &str_i, &str_o), &o_verbose); | 781 | IF_NC_EXTRA(, &str_i, &str_o), &o_verbose); |