aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Lange <nolange79@gmail.com>2020-02-14 22:13:38 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-06-29 13:53:17 +0200
commita16c8ef21253d2fbb8f311ee34514cdc0a3f49a2 (patch)
treedba4988cbc961818b6cc07b312dcd7e34df7d89f
parentc918ea1673e4e930835d387bb989c620bf022e94 (diff)
downloadbusybox-a16c8ef21253d2fbb8f311ee34514cdc0a3f49a2.tar.gz
nc_bloaty: support udp broadcast ports
Add a -b option, identical to debians "traditional" netcat. This allows sending (subnet) UDP Broadcasts. function old new delta packed_usage 33420 33441 +21 nc_main 1041 1057 +16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0) Total: 37 bytes Signed-off-by: Norbert Lange <nolange79@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/nc_bloaty.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index 034e03d21..88eda6b28 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -84,6 +84,7 @@
//usage: )
//usage: "\n -n Don't do DNS resolution"
//usage: "\n -u UDP mode"
+//usage: "\n -b Allow broadcasts"
//usage: "\n -v Verbose"
//usage: IF_NC_EXTRA(
//usage: "\n -o FILE Hex dump traffic"
@@ -171,17 +172,19 @@ enum {
OPT_p = (1 << 1),
OPT_s = (1 << 2),
OPT_u = (1 << 3),
- OPT_v = (1 << 4),
- OPT_w = (1 << 5),
- OPT_l = (1 << 6) * ENABLE_NC_SERVER,
- OPT_k = (1 << 7) * ENABLE_NC_SERVER,
- OPT_i = (1 << (6+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
- OPT_o = (1 << (7+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
- OPT_z = (1 << (8+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
+ OPT_b = (1 << 4),
+ OPT_v = (1 << 5),
+ OPT_w = (1 << 6),
+ OPT_l = (1 << 7) * ENABLE_NC_SERVER,
+ OPT_k = (1 << 8) * ENABLE_NC_SERVER,
+ OPT_i = (1 << (7+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
+ OPT_o = (1 << (8+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
+ OPT_z = (1 << (9+2*ENABLE_NC_SERVER)) * ENABLE_NC_EXTRA,
};
#define o_nflag (option_mask32 & OPT_n)
#define o_udpmode (option_mask32 & OPT_u)
+#define o_bcmode (option_mask32 & OPT_b)
#if ENABLE_NC_EXTRA
#define o_ofile (option_mask32 & OPT_o)
#define o_zero (option_mask32 & OPT_z)
@@ -788,7 +791,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
// -g -G -t -r deleted, unimplemented -a deleted too
getopt32(argv, "^"
- "np:s:uvw:+"/* -w N */ IF_NC_SERVER("lk")
+ "np:s:ubvw:+"/* -w N */ IF_NC_SERVER("lk")
IF_NC_EXTRA("i:o:z")
"\0"
"?2:vv"IF_NC_SERVER(":ll"), /* max 2 params; -v and -l are counters */
@@ -851,8 +854,11 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
}
xmove_fd(x, netfd);
setsockopt_reuseaddr(netfd);
- if (o_udpmode)
+ if (o_udpmode) {
+ if (o_bcmode)
+ setsockopt_broadcast(netfd);
socket_want_pktinfo(netfd);
+ }
if (!ENABLE_FEATURE_UNIX_LOCAL
|| cnt_l != 0 /* listen */
|| ouraddr->u.sa.sa_family != AF_UNIX