aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--METADATA4
-rw-r--r--android/device/generated/flags.h40
-rw-r--r--android/device/generated/globals.h5
-rw-r--r--android/device/generated/help.h2
-rw-r--r--android/device/generated/newtoys.h4
-rw-r--r--android/linux/generated/flags.h40
-rw-r--r--android/linux/generated/help.h2
-rw-r--r--android/linux/generated/newtoys.h4
-rw-r--r--android/mac/generated/flags.h40
-rw-r--r--android/mac/generated/help.h2
-rw-r--r--android/mac/generated/newtoys.h4
-rw-r--r--lib/lib.h4
-rw-r--r--lib/net.c6
-rw-r--r--lib/toyflags.h1
-rw-r--r--main.c11
-rwxr-xr-xtests/find.test1
-rw-r--r--toys/net/microcom.c7
-rw-r--r--toys/net/netcat.c89
-rw-r--r--toys/posix/find.c2
19 files changed, 170 insertions, 98 deletions
diff --git a/METADATA b/METADATA
index 94fd4032..ecef7a3b 100644
--- a/METADATA
+++ b/METADATA
@@ -9,12 +9,12 @@ third_party {
last_upgrade_date {
year: 2024
month: 5
- day: 9
+ day: 20
}
homepage: "https://landley.net/toybox/"
identifier {
type: "Git"
value: "https://github.com/landley/toybox"
- version: "6800a95ef32826e753881802a2c126c59d451397"
+ version: "3ad2a87991aae26f4041031c27dbbf63d5ec1ca7"
}
}
diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h
index 5d873312..906e3f63 100644
--- a/android/device/generated/flags.h
+++ b/android/device/generated/flags.h
@@ -2228,14 +2228,13 @@
#undef FLAG_r
#endif
-// netcat ^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U] ^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]
+// netcat ^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO] ^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]
#undef OPTSTR_netcat
-#define OPTSTR_netcat "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]"
+#define OPTSTR_netcat "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]"
#ifdef CLEANUP_netcat
#undef CLEANUP_netcat
#undef FOR_netcat
#undef FLAG_z
-#undef FLAG_v
#undef FLAG_n
#undef FLAG_U
#undef FLAG_u
@@ -2243,6 +2242,8 @@
#undef FLAG_4
#undef FLAG_f
#undef FLAG_s
+#undef FLAG_o
+#undef FLAG_O
#undef FLAG_q
#undef FLAG_p
#undef FLAG_W
@@ -5975,22 +5976,23 @@
#define TT this.netcat
#endif
#define FLAG_z (1LL<<0)
-#define FLAG_v (1LL<<1)
-#define FLAG_n (1LL<<2)
-#define FLAG_U (1LL<<3)
-#define FLAG_u (1LL<<4)
-#define FLAG_6 (1LL<<5)
-#define FLAG_4 (1LL<<6)
-#define FLAG_f (1LL<<7)
-#define FLAG_s (1LL<<8)
-#define FLAG_q (1LL<<9)
-#define FLAG_p (1LL<<10)
-#define FLAG_W (1LL<<11)
-#define FLAG_w (1LL<<12)
-#define FLAG_L (1LL<<13)
-#define FLAG_l (1LL<<14)
-#define FLAG_E (1LL<<15)
-#define FLAG_t (1LL<<16)
+#define FLAG_n (1LL<<1)
+#define FLAG_U (1LL<<2)
+#define FLAG_u (1LL<<3)
+#define FLAG_6 (1LL<<4)
+#define FLAG_4 (1LL<<5)
+#define FLAG_f (1LL<<6)
+#define FLAG_s (1LL<<7)
+#define FLAG_o (1LL<<8)
+#define FLAG_O (1LL<<9)
+#define FLAG_q (1LL<<10)
+#define FLAG_p (1LL<<11)
+#define FLAG_W (1LL<<12)
+#define FLAG_w (1LL<<13)
+#define FLAG_L (1LL<<14)
+#define FLAG_l (1LL<<15)
+#define FLAG_E (1LL<<16)
+#define FLAG_t (1LL<<17)
#endif
#ifdef FOR_netstat
diff --git a/android/device/generated/globals.h b/android/device/generated/globals.h
index 43023b91..dc1bc35e 100644
--- a/android/device/generated/globals.h
+++ b/android/device/generated/globals.h
@@ -78,8 +78,11 @@ struct microcom_data {
};
struct netcat_data {
- char *f, *s;
+ char *f, *s, *o, *O;
long q, p, W, w;
+
+ unsigned ofd, olast, opos, ocount[2];
+ char obuf[16];
};
struct netstat_data {
diff --git a/android/device/generated/help.h b/android/device/generated/help.h
index 6931101c..1c00091b 100644
--- a/android/device/generated/help.h
+++ b/android/device/generated/help.h
@@ -124,7 +124,7 @@
#define HELP_netstat "usage: netstat [-pWrxwutneal]\n\nDisplay networking information. Default is netstat -tuwx\n\n-r Routing table\n-a All sockets (not just connected)\n-l Listening server sockets\n-t TCP sockets\n-u UDP sockets\n-w Raw sockets\n-x Unix sockets\n-e Extended info\n-n Don't resolve names\n-W Wide display\n-p Show PID/program name of sockets"
-#define HELP_netcat "usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] {IPADDR PORTNUM|-f FILENAME|COMMAND...}\n\nForward stdin/stdout to a file or network connection.\n\n-4 Force IPv4\n-6 Force IPv6\n-E Forward stderr\n-f Use FILENAME (ala /dev/ttyS0) instead of network\n-L Listen and background each incoming connection (server mode)\n-l Listen for one incoming connection, then exit\n-n No DNS lookup\n-p Local port number\n-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet\n-s Local source address\n-t Allocate tty\n-v Verbose\n-u Use UDP\n-U Use a UNIX domain socket\n-W SECONDS timeout for more data on an idle connection\n-w SECONDS timeout to establish connection\n-z zero-I/O mode [used for scanning]\n\nWhen listening the COMMAND line is executed as a child process to handle\nan incoming connection. With no COMMAND -l forwards the connection\nto stdin/stdout. If no -p specified, -l prints the port it bound to and\nbackgrounds itself (returning immediately).\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL sh -l\n\nOr use \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port."
+#define HELP_netcat "usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] [-o FILE] {IPADDR PORTNUM|-f FILENAME|COMMAND...}\n\nForward stdin/stdout to a file or network connection.\n\n-4 Force IPv4\n-6 Force IPv6\n-E Forward stderr\n-f Use FILENAME (ala /dev/ttyS0) instead of network\n-L Listen and background each incoming connection (server mode)\n-l Listen for one incoming connection, then exit\n-n No DNS lookup\n-o Hex dump to FILE (-o- writes hex only to stdout)\n-O Hex dump to FILE (collated)\n-p Local port number\n-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet\n-s Local source address\n-t Allocate tty\n-u Use UDP\n-U Use a UNIX domain socket\n-W SECONDS timeout for more data on an idle connection\n-w SECONDS timeout to establish connection\n-z zero-I/O mode [used for scanning]\n\nWhen listening the COMMAND line is executed as a child process to handle\nan incoming connection. With no COMMAND -l forwards the connection\nto stdin/stdout. If no -p specified, -l prints the port it bound to and\nbackgrounds itself (returning immediately).\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL sh -l\n\nOr use \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port."
#define HELP_microcom "usage: microcom [-s SPEED] [-X] DEVICE\n\nSimple serial console. Hit CTRL-] for menu.\n\n-s Set baud rate to SPEED (default 115200)\n-X Ignore ^] menu escape"
diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h
index 92814854..0873071c 100644
--- a/android/device/generated/newtoys.h
+++ b/android/device/generated/newtoys.h
@@ -184,7 +184,7 @@ USE_MCOOKIE(NEWTOY(mcookie, "v(verbose)V(version)", TOYFLAG_USR|TOYFLAG_BIN))
USE_MD5SUM(NEWTOY(md5sum, "bc(check)s(status)[!bc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_MDEV(NEWTOY(mdev, "s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_UMASK))
USE_MEMEATER(NEWTOY(memeater, "<1>1M", TOYFLAG_USR|TOYFLAG_BIN))
-USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN))
+USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NOBUF))
USE_MIX(NEWTOY(mix, "c:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
USE_MKDIR(NEWTOY(mkdir, "<1"USE_MKDIR_Z("Z:")"vp(parent)(parents)m:", TOYFLAG_BIN|TOYFLAG_UMASK))
USE_MKE2FS(NEWTOY(mke2fs, "<1>2g:Fnqm#N#i#b#", TOYFLAG_SBIN))
@@ -204,7 +204,7 @@ USE_NBD_SERVER(OLDTOY(nbd-server, nbd_server, TOYFLAG_USR|TOYFLAG_BIN))
USE_NBD_CLIENT(NEWTOY(nbd_client, "<3>3b#<1>4294967295=4096ns", 0))
USE_NBD_SERVER(NEWTOY(nbd_server, "<1>1r", 0))
USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN))
-USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]", TOYFLAG_BIN))
+USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]", TOYFLAG_BIN))
USE_NETSTAT(NEWTOY(netstat, "pWrxwutneal", TOYFLAG_BIN))
USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_BIN))
USE_NL(NEWTOY(nl, "v#=1l#w#<0=6b:n:s:E", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h
index d51629e0..7a6ad283 100644
--- a/android/linux/generated/flags.h
+++ b/android/linux/generated/flags.h
@@ -2228,14 +2228,13 @@
#undef FLAG_r
#endif
-// netcat ^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]
+// netcat ^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]
#undef OPTSTR_netcat
-#define OPTSTR_netcat "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]"
+#define OPTSTR_netcat "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]"
#ifdef CLEANUP_netcat
#undef CLEANUP_netcat
#undef FOR_netcat
#undef FLAG_z
-#undef FLAG_v
#undef FLAG_n
#undef FLAG_U
#undef FLAG_u
@@ -2243,6 +2242,8 @@
#undef FLAG_4
#undef FLAG_f
#undef FLAG_s
+#undef FLAG_o
+#undef FLAG_O
#undef FLAG_q
#undef FLAG_p
#undef FLAG_W
@@ -5975,22 +5976,23 @@
#define TT this.netcat
#endif
#define FLAG_z (FORCED_FLAG<<0)
-#define FLAG_v (FORCED_FLAG<<1)
-#define FLAG_n (FORCED_FLAG<<2)
-#define FLAG_U (FORCED_FLAG<<3)
-#define FLAG_u (FORCED_FLAG<<4)
-#define FLAG_6 (FORCED_FLAG<<5)
-#define FLAG_4 (FORCED_FLAG<<6)
-#define FLAG_f (FORCED_FLAG<<7)
-#define FLAG_s (FORCED_FLAG<<8)
-#define FLAG_q (FORCED_FLAG<<9)
-#define FLAG_p (FORCED_FLAG<<10)
-#define FLAG_W (FORCED_FLAG<<11)
-#define FLAG_w (FORCED_FLAG<<12)
-#define FLAG_L (FORCED_FLAG<<13)
-#define FLAG_l (FORCED_FLAG<<14)
-#define FLAG_E (FORCED_FLAG<<15)
-#define FLAG_t (FORCED_FLAG<<16)
+#define FLAG_n (FORCED_FLAG<<1)
+#define FLAG_U (FORCED_FLAG<<2)
+#define FLAG_u (FORCED_FLAG<<3)
+#define FLAG_6 (FORCED_FLAG<<4)
+#define FLAG_4 (FORCED_FLAG<<5)
+#define FLAG_f (FORCED_FLAG<<6)
+#define FLAG_s (FORCED_FLAG<<7)
+#define FLAG_o (FORCED_FLAG<<8)
+#define FLAG_O (FORCED_FLAG<<9)
+#define FLAG_q (FORCED_FLAG<<10)
+#define FLAG_p (FORCED_FLAG<<11)
+#define FLAG_W (FORCED_FLAG<<12)
+#define FLAG_w (FORCED_FLAG<<13)
+#define FLAG_L (FORCED_FLAG<<14)
+#define FLAG_l (FORCED_FLAG<<15)
+#define FLAG_E (FORCED_FLAG<<16)
+#define FLAG_t (FORCED_FLAG<<17)
#endif
#ifdef FOR_netstat
diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h
index 8ce794a8..02095c14 100644
--- a/android/linux/generated/help.h
+++ b/android/linux/generated/help.h
@@ -126,7 +126,7 @@
#define HELP_netstat "usage: netstat [-pWrxwutneal]\n\nDisplay networking information. Default is netstat -tuwx\n\n-r Routing table\n-a All sockets (not just connected)\n-l Listening server sockets\n-t TCP sockets\n-u UDP sockets\n-w Raw sockets\n-x Unix sockets\n-e Extended info\n-n Don't resolve names\n-W Wide display\n-p Show PID/program name of sockets"
-#define HELP_netcat "usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] {IPADDR PORTNUM|-f FILENAME|COMMAND...}\n\nForward stdin/stdout to a file or network connection.\n\n-4 Force IPv4\n-6 Force IPv6\n-E Forward stderr\n-f Use FILENAME (ala /dev/ttyS0) instead of network\n-L Listen and background each incoming connection (server mode)\n-l Listen for one incoming connection, then exit\n-n No DNS lookup\n-p Local port number\n-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet\n-s Local source address\n-t Allocate tty\n-v Verbose\n-u Use UDP\n-U Use a UNIX domain socket\n-W SECONDS timeout for more data on an idle connection\n-w SECONDS timeout to establish connection\n-z zero-I/O mode [used for scanning]\n\nWhen listening the COMMAND line is executed as a child process to handle\nan incoming connection. With no COMMAND -l forwards the connection\nto stdin/stdout. If no -p specified, -l prints the port it bound to and\nbackgrounds itself (returning immediately).\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL sh -l\n\nOr use \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port."
+#define HELP_netcat "usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] [-o FILE] {IPADDR PORTNUM|-f FILENAME|COMMAND...}\n\nForward stdin/stdout to a file or network connection.\n\n-4 Force IPv4\n-6 Force IPv6\n-E Forward stderr\n-f Use FILENAME (ala /dev/ttyS0) instead of network\n-L Listen and background each incoming connection (server mode)\n-l Listen for one incoming connection, then exit\n-n No DNS lookup\n-o Hex dump to FILE (-o- writes hex only to stdout)\n-O Hex dump to FILE (collated)\n-p Local port number\n-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet\n-s Local source address\n-t Allocate tty\n-u Use UDP\n-U Use a UNIX domain socket\n-W SECONDS timeout for more data on an idle connection\n-w SECONDS timeout to establish connection\n-z zero-I/O mode [used for scanning]\n\nWhen listening the COMMAND line is executed as a child process to handle\nan incoming connection. With no COMMAND -l forwards the connection\nto stdin/stdout. If no -p specified, -l prints the port it bound to and\nbackgrounds itself (returning immediately).\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL sh -l\n\nOr use \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port."
#define HELP_microcom "usage: microcom [-s SPEED] [-X] DEVICE\n\nSimple serial console. Hit CTRL-] for menu.\n\n-s Set baud rate to SPEED (default 115200)\n-X Ignore ^] menu escape"
diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h
index 92814854..0873071c 100644
--- a/android/linux/generated/newtoys.h
+++ b/android/linux/generated/newtoys.h
@@ -184,7 +184,7 @@ USE_MCOOKIE(NEWTOY(mcookie, "v(verbose)V(version)", TOYFLAG_USR|TOYFLAG_BIN))
USE_MD5SUM(NEWTOY(md5sum, "bc(check)s(status)[!bc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_MDEV(NEWTOY(mdev, "s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_UMASK))
USE_MEMEATER(NEWTOY(memeater, "<1>1M", TOYFLAG_USR|TOYFLAG_BIN))
-USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN))
+USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NOBUF))
USE_MIX(NEWTOY(mix, "c:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
USE_MKDIR(NEWTOY(mkdir, "<1"USE_MKDIR_Z("Z:")"vp(parent)(parents)m:", TOYFLAG_BIN|TOYFLAG_UMASK))
USE_MKE2FS(NEWTOY(mke2fs, "<1>2g:Fnqm#N#i#b#", TOYFLAG_SBIN))
@@ -204,7 +204,7 @@ USE_NBD_SERVER(OLDTOY(nbd-server, nbd_server, TOYFLAG_USR|TOYFLAG_BIN))
USE_NBD_CLIENT(NEWTOY(nbd_client, "<3>3b#<1>4294967295=4096ns", 0))
USE_NBD_SERVER(NEWTOY(nbd_server, "<1>1r", 0))
USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN))
-USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]", TOYFLAG_BIN))
+USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]", TOYFLAG_BIN))
USE_NETSTAT(NEWTOY(netstat, "pWrxwutneal", TOYFLAG_BIN))
USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_BIN))
USE_NL(NEWTOY(nl, "v#=1l#w#<0=6b:n:s:E", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h
index 11ac529e..1183c4ed 100644
--- a/android/mac/generated/flags.h
+++ b/android/mac/generated/flags.h
@@ -2228,14 +2228,13 @@
#undef FLAG_r
#endif
-// netcat ^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]
+// netcat ^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]
#undef OPTSTR_netcat
-#define OPTSTR_netcat "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]"
+#define OPTSTR_netcat "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]"
#ifdef CLEANUP_netcat
#undef CLEANUP_netcat
#undef FOR_netcat
#undef FLAG_z
-#undef FLAG_v
#undef FLAG_n
#undef FLAG_U
#undef FLAG_u
@@ -2243,6 +2242,8 @@
#undef FLAG_4
#undef FLAG_f
#undef FLAG_s
+#undef FLAG_o
+#undef FLAG_O
#undef FLAG_q
#undef FLAG_p
#undef FLAG_W
@@ -5975,22 +5976,23 @@
#define TT this.netcat
#endif
#define FLAG_z (FORCED_FLAG<<0)
-#define FLAG_v (FORCED_FLAG<<1)
-#define FLAG_n (FORCED_FLAG<<2)
-#define FLAG_U (FORCED_FLAG<<3)
-#define FLAG_u (FORCED_FLAG<<4)
-#define FLAG_6 (FORCED_FLAG<<5)
-#define FLAG_4 (FORCED_FLAG<<6)
-#define FLAG_f (FORCED_FLAG<<7)
-#define FLAG_s (FORCED_FLAG<<8)
-#define FLAG_q (FORCED_FLAG<<9)
-#define FLAG_p (FORCED_FLAG<<10)
-#define FLAG_W (FORCED_FLAG<<11)
-#define FLAG_w (FORCED_FLAG<<12)
-#define FLAG_L (FORCED_FLAG<<13)
-#define FLAG_l (FORCED_FLAG<<14)
-#define FLAG_E (FORCED_FLAG<<15)
-#define FLAG_t (FORCED_FLAG<<16)
+#define FLAG_n (FORCED_FLAG<<1)
+#define FLAG_U (FORCED_FLAG<<2)
+#define FLAG_u (FORCED_FLAG<<3)
+#define FLAG_6 (FORCED_FLAG<<4)
+#define FLAG_4 (FORCED_FLAG<<5)
+#define FLAG_f (FORCED_FLAG<<6)
+#define FLAG_s (FORCED_FLAG<<7)
+#define FLAG_o (FORCED_FLAG<<8)
+#define FLAG_O (FORCED_FLAG<<9)
+#define FLAG_q (FORCED_FLAG<<10)
+#define FLAG_p (FORCED_FLAG<<11)
+#define FLAG_W (FORCED_FLAG<<12)
+#define FLAG_w (FORCED_FLAG<<13)
+#define FLAG_L (FORCED_FLAG<<14)
+#define FLAG_l (FORCED_FLAG<<15)
+#define FLAG_E (FORCED_FLAG<<16)
+#define FLAG_t (FORCED_FLAG<<17)
#endif
#ifdef FOR_netstat
diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h
index 8ce794a8..02095c14 100644
--- a/android/mac/generated/help.h
+++ b/android/mac/generated/help.h
@@ -126,7 +126,7 @@
#define HELP_netstat "usage: netstat [-pWrxwutneal]\n\nDisplay networking information. Default is netstat -tuwx\n\n-r Routing table\n-a All sockets (not just connected)\n-l Listening server sockets\n-t TCP sockets\n-u UDP sockets\n-w Raw sockets\n-x Unix sockets\n-e Extended info\n-n Don't resolve names\n-W Wide display\n-p Show PID/program name of sockets"
-#define HELP_netcat "usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] {IPADDR PORTNUM|-f FILENAME|COMMAND...}\n\nForward stdin/stdout to a file or network connection.\n\n-4 Force IPv4\n-6 Force IPv6\n-E Forward stderr\n-f Use FILENAME (ala /dev/ttyS0) instead of network\n-L Listen and background each incoming connection (server mode)\n-l Listen for one incoming connection, then exit\n-n No DNS lookup\n-p Local port number\n-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet\n-s Local source address\n-t Allocate tty\n-v Verbose\n-u Use UDP\n-U Use a UNIX domain socket\n-W SECONDS timeout for more data on an idle connection\n-w SECONDS timeout to establish connection\n-z zero-I/O mode [used for scanning]\n\nWhen listening the COMMAND line is executed as a child process to handle\nan incoming connection. With no COMMAND -l forwards the connection\nto stdin/stdout. If no -p specified, -l prints the port it bound to and\nbackgrounds itself (returning immediately).\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL sh -l\n\nOr use \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port."
+#define HELP_netcat "usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] [-o FILE] {IPADDR PORTNUM|-f FILENAME|COMMAND...}\n\nForward stdin/stdout to a file or network connection.\n\n-4 Force IPv4\n-6 Force IPv6\n-E Forward stderr\n-f Use FILENAME (ala /dev/ttyS0) instead of network\n-L Listen and background each incoming connection (server mode)\n-l Listen for one incoming connection, then exit\n-n No DNS lookup\n-o Hex dump to FILE (-o- writes hex only to stdout)\n-O Hex dump to FILE (collated)\n-p Local port number\n-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet\n-s Local source address\n-t Allocate tty\n-u Use UDP\n-U Use a UNIX domain socket\n-W SECONDS timeout for more data on an idle connection\n-w SECONDS timeout to establish connection\n-z zero-I/O mode [used for scanning]\n\nWhen listening the COMMAND line is executed as a child process to handle\nan incoming connection. With no COMMAND -l forwards the connection\nto stdin/stdout. If no -p specified, -l prints the port it bound to and\nbackgrounds itself (returning immediately).\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL sh -l\n\nOr use \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port."
#define HELP_microcom "usage: microcom [-s SPEED] [-X] DEVICE\n\nSimple serial console. Hit CTRL-] for menu.\n\n-s Set baud rate to SPEED (default 115200)\n-X Ignore ^] menu escape"
diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h
index 92814854..0873071c 100644
--- a/android/mac/generated/newtoys.h
+++ b/android/mac/generated/newtoys.h
@@ -184,7 +184,7 @@ USE_MCOOKIE(NEWTOY(mcookie, "v(verbose)V(version)", TOYFLAG_USR|TOYFLAG_BIN))
USE_MD5SUM(NEWTOY(md5sum, "bc(check)s(status)[!bc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_MDEV(NEWTOY(mdev, "s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_UMASK))
USE_MEMEATER(NEWTOY(memeater, "<1>1M", TOYFLAG_USR|TOYFLAG_BIN))
-USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN))
+USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NOBUF))
USE_MIX(NEWTOY(mix, "c:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
USE_MKDIR(NEWTOY(mkdir, "<1"USE_MKDIR_Z("Z:")"vp(parent)(parents)m:", TOYFLAG_BIN|TOYFLAG_UMASK))
USE_MKE2FS(NEWTOY(mke2fs, "<1>2g:Fnqm#N#i#b#", TOYFLAG_SBIN))
@@ -204,7 +204,7 @@ USE_NBD_SERVER(OLDTOY(nbd-server, nbd_server, TOYFLAG_USR|TOYFLAG_BIN))
USE_NBD_CLIENT(NEWTOY(nbd_client, "<3>3b#<1>4294967295=4096ns", 0))
USE_NBD_SERVER(NEWTOY(nbd_server, "<1>1r", 0))
USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN))
-USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]", TOYFLAG_BIN))
+USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]", TOYFLAG_BIN))
USE_NETSTAT(NEWTOY(netstat, "pWrxwutneal", TOYFLAG_BIN))
USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_BIN))
USE_NL(NEWTOY(nl, "v#=1l#w#<0=6b:n:s:E", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/lib/lib.h b/lib/lib.h
index 4618a2f0..5bc21f01 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -359,7 +359,9 @@ void xconnect(int fd, const struct sockaddr *sa, socklen_t len);
int xconnectany(struct addrinfo *ai);
int xbindany(struct addrinfo *ai);
int xpoll(struct pollfd *fds, int nfds, int timeout);
-int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_timeout);
+int pollinate(int in1, int in2, int out1, int out2,
+ void (*callback)(int fd, void *buf, size_t len),
+ int timeout, int shutdown_timeout);
char *ntop(struct sockaddr *sa);
void xsendto(int sockfd, void *buf, size_t len, struct sockaddr *dest);
int xrecvwait(int fd, char *buf, int len, union socksaddr *sa, int timeout);
diff --git a/lib/net.c b/lib/net.c
index 16a110e3..8fe006b6 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -96,7 +96,9 @@ int xpoll(struct pollfd *fds, int nfds, int timeout)
// Loop forwarding data from in1 to out1 and in2 to out2, handling
// half-connection shutdown. timeouts return if no data for X ms.
// Returns 0: both closed, 1 shutdown_timeout, 2 timeout
-int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_timeout)
+int pollinate(int in1, int in2, int out1, int out2,
+ void (*callback)(int fd, void *buf, size_t len),
+ int timeout, int shutdown_timeout)
{
struct pollfd pollfds[2];
int i, pollcount = 2;
@@ -115,7 +117,7 @@ int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_ti
int len = read(pollfds[i].fd, libbuf, sizeof(libbuf));
if (len<1) pollfds[i].revents = POLLHUP;
else {
- xwrite(i ? out2 : out1, libbuf, len);
+ callback(i ? out2 : out1, libbuf, len);
continue;
}
}
diff --git a/lib/toyflags.h b/lib/toyflags.h
index ab8e4f5b..928fe0bb 100644
--- a/lib/toyflags.h
+++ b/lib/toyflags.h
@@ -30,6 +30,7 @@
// Line buffered stdout
#define TOYFLAG_LINEBUF (1<<10)
+#define TOYFLAG_NOBUF (1<<11)
// Error code to return if argument parsing fails (default 1)
#define TOYFLAG_ARGFAIL(x) (x<<24)
diff --git a/main.c b/main.c
index 93cf768e..2cbaf172 100644
--- a/main.c
+++ b/main.c
@@ -154,8 +154,6 @@ void check_help(char **arg)
// Setup toybox global state for this command.
void toy_singleinit(struct toy_list *which, char *argv[])
{
- char *buf;
-
toys.which = which;
toys.argv = argv;
toys.toycount = ARRAY_LEN(toy_list);
@@ -168,6 +166,9 @@ void toy_singleinit(struct toy_list *which, char *argv[])
// Setup we only want to do once: skip for multiplexer or NOFORK reentry
if (!(CFG_TOYBOX && which == toy_list) && !(which->flags & TOYFLAG_NOFORK)) {
+ char *buf = 0;
+ int btype = _IOFBF;
+
toys.old_umask = umask(0);
if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask);
@@ -178,8 +179,10 @@ void toy_singleinit(struct toy_list *which, char *argv[])
uselocale(newlocale(LC_CTYPE_MASK, "C.UTF-8", 0) ? :
newlocale(LC_CTYPE_MASK, "en_US.UTF-8", 0));
- buf = (which->flags & TOYFLAG_LINEBUF) ? 0 : xmalloc(4096);
- setvbuf(stdout, buf, buf ? _IOFBF : _IOLBF, buf ? 4096 : 0);
+ if (which->flags & TOYFLAG_LINEBUF) btype = _IOLBF;
+ else if (which->flags & TOYFLAG_NOBUF) btype = _IONBF;
+ else buf = xmalloc(4096);
+ setvbuf(stdout, buf, btype, buf ? 4096 : 0);
}
}
diff --git a/tests/find.test b/tests/find.test
index e026d7b5..e4a161c4 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -162,6 +162,7 @@ testing '-size implies -type f' 'find dir -size -1M | sort' \
rm -rf dir
utf8locale
+skipnot [ "$(uname)" != "Darwin" ] # Darwin's towlower() is broken.
testing 'strlower edge case' \
'touch aaaaaⱥⱥⱥⱥⱥⱥⱥⱥⱥ; find . -iname aaaaaȺȺȺȺȺȺȺȺȺ' './aaaaaⱥⱥⱥⱥⱥⱥⱥⱥⱥ\n' \
'' ''
diff --git a/toys/net/microcom.c b/toys/net/microcom.c
index d805a062..1ee9204e 100644
--- a/toys/net/microcom.c
+++ b/toys/net/microcom.c
@@ -2,7 +2,7 @@
*
* Copyright 2017 The Android Open Source Project.
-USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN))
+USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NOBUF))
config MICROCOM
bool "microcom"
@@ -79,9 +79,8 @@ static void handle_esc(void)
}
free(filename);
close(fd);
- } else {
- xprintf("Ignoring unknown command.");
- }
+ } else xprintf("Ignoring unknown command.");
+
xprintf("\r\n");
}
diff --git a/toys/net/netcat.c b/toys/net/netcat.c
index 4e76fa7f..65eeea74 100644
--- a/toys/net/netcat.c
+++ b/toys/net/netcat.c
@@ -2,16 +2,16 @@
*
* Copyright 2007 Rob Landley <rob@landley.net>
*
- * TODO: genericize for telnet/microcom/tail-f, fix -t
+ * TODO: genericize for telnet/microcom/tail-f, fix -t with login_tty()
-USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1s:f:46uUnvz[!tlL][!Lw][!Lu][!46U]", TOYFLAG_BIN))
+USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]", TOYFLAG_BIN))
USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN))
config NETCAT
bool "netcat"
default y
help
- usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] {IPADDR PORTNUM|-f FILENAME|COMMAND...}
+ usage: netcat [-46ELlntUu] [-pqWw #] [-s addr] [-o FILE] {IPADDR PORTNUM|-f FILENAME|COMMAND...}
Forward stdin/stdout to a file or network connection.
@@ -22,11 +22,12 @@ config NETCAT
-L Listen and background each incoming connection (server mode)
-l Listen for one incoming connection, then exit
-n No DNS lookup
+ -o Hex dump to FILE (-o- writes hex only to stdout)
+ -O Hex dump to FILE (collated)
-p Local port number
-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet
-s Local source address
-t Allocate tty
- -v Verbose
-u Use UDP
-U Use a UNIX domain socket
-W SECONDS timeout for more data on an idle connection
@@ -49,8 +50,11 @@ config NETCAT
#include "toys.h"
GLOBALS(
- char *f, *s;
+ char *f, *s, *o, *O;
long q, p, W, w;
+
+ unsigned ofd, olast, opos, ocount[2];
+ char obuf[16];
)
static void timeout(int signum)
@@ -78,6 +82,49 @@ static int usock(char *name, int type, int out)
return sockfd;
}
+// Hex dump accumulated buffer data
+void oflush(void)
+{
+ char *s = toybuf;
+ unsigned *oc = TT.ocount+(TT.olast==1), uu;
+
+ if (!TT.opos) return;
+ s += sprintf(toybuf, "%c %08x", 60+2*(TT.olast==1), *oc);
+ for (uu = 0; uu<16; uu++) {
+ s += sprintf(s, uu<TT.opos ? " %02x" : " ", TT.obuf[uu]);
+ if (TT.obuf[uu]-32u>95) TT.obuf[uu] = '.';
+ }
+ dprintf(TT.ofd, "%s # %.*s\n", toybuf, TT.opos, TT.obuf);
+ *oc += TT.opos;
+ TT.opos = 0;
+}
+
+// Write data to output, and hex dump to -o if enabled.
+void ohexwrite(int fd, void *buf, size_t len)
+{
+ // Hex dump if -o specified. Output is always to fd 1, input != 1.
+ if (TT.ofd) {
+ int i = 0, j;
+
+ if (TT.olast != fd) oflush();
+ TT.olast = fd;
+
+ while (i<len) {
+ j = minof(16-TT.opos, len-i);
+ memcpy(TT.obuf+TT.opos, buf+i, j);
+ TT.opos += j;
+ i += j;
+ if (TT.opos==16 || !TT.O) oflush();
+ }
+
+ // Don't write data to stdout when -o goes to stdout.
+ if (TT.ofd==1 && fd==1) return;
+ }
+
+ // Pass along raw data
+ xwrite(fd, buf, len);
+}
+
void netcat_main(void)
{
int sockfd = -1, in1 = 0, in2 = 0, out1 = 1, out2 = 1, family = AF_UNSPEC,
@@ -85,7 +132,15 @@ void netcat_main(void)
socklen_t len;
pid_t child;
- // Addjust idle and quit_delay to ms or -1 for no timeout
+ // -o - disables normal writes to stdout, just gives hex dump.
+ if (TT.O) TT.o = TT.O;
+ if (TT.o) {
+ if (!strcmp(TT.o, "-")) TT.ofd = 1;
+ else TT.ofd = xcreate(TT.o, O_CREAT|O_TRUNC|O_WRONLY, 0666);
+ sigatexit(oflush);
+ }
+
+ // Adjust idle and quit_delay to ms or -1 for no timeout
TT.W = TT.W ? TT.W*1000 : -1;
TT.q = TT.q ? TT.q*1000 : -1;
@@ -104,16 +159,16 @@ void netcat_main(void)
else if (FLAG(6)) family = AF_INET6;
else if (FLAG(U)) family = AF_UNIX;
- if (TT.f) in1 = out2 = xopen(TT.f, O_RDWR);
- else {
+ if (TT.f) {
+ in1 = out2 = xopen(TT.f, O_RDWR);
+ alarm(0);
+ pollinate(in1, in2, out1, out2, ohexwrite, TT.W, TT.q);
+ } else {
// Setup socket
if (!FLAG(l) && !FLAG(L)) {
- char *host = toys.optargs[0];
- char *port = toys.optargs[1];
- if (FLAG(U)) sockfd = usock(host, type, 1);
- else sockfd = xconnectany(xgetaddrinfo(host, port, family, type, 0, AI_NUMERICHOST*FLAG(n)));
-
- if (FLAG(v)) printf("%s:%s [open]\n", host, port);
+ if (FLAG(U)) sockfd = usock(toys.optargs[0], type, 1);
+ else sockfd = xconnectany(xgetaddrinfo(toys.optargs[0], toys.optargs[1],
+ family, type, 0, AI_NUMERICHOST*FLAG(n)));
// Do not perform any I/O in zero mode
if (FLAG(z)) goto cleanup;
@@ -121,7 +176,7 @@ void netcat_main(void)
// We have a connection. Disarm timeout and start poll/send loop.
alarm(0);
in1 = out2 = sockfd;
- pollinate(in1, in2, out1, out2, TT.W, TT.q);
+ pollinate(in1, in2, out1, out2, ohexwrite, TT.W, TT.q);
} else {
// Listen for incoming connections
if (FLAG(U)) {
@@ -152,7 +207,7 @@ void netcat_main(void)
}
do {
- len = sizeof(struct sockaddr_storage);
+ len = sizeof(struct sockaddr_storage);
if (FLAG(u)) {
if (-1 == recvfrom(in1 = dup(sockfd), &child, 1, MSG_PEEK,
(void *)toybuf, &len)) perror_exit("recvfrom");
@@ -188,7 +243,7 @@ void netcat_main(void)
// Copy stdin/out
} else {
- pollinate(in1, in2, out1, out2, TT.W, TT.q);
+ pollinate(in1, in2, out1, out2, ohexwrite, TT.W, TT.q);
close(in1);
}
} while (FLAG(L));
diff --git a/toys/posix/find.c b/toys/posix/find.c
index c8e68683..ac148816 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -439,7 +439,7 @@ static int do_find(struct dirtree *new)
}
} else if (!strcmp(s, "size")) {
if (check) test = compare_numsign(new->st.st_size, -512, arg) &&
- ((new->st.st_mode & S_IFMT) == S_IFREG);
+ S_ISREG(new->st.st_mode);
} else if (!strcmp(s, "links")) {
if (check) test = compare_numsign(new->st.st_nlink, 0, arg);
} else if (!strcmp(s, "inum")) {