aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
authorIsaac Dunham <idunham@lavabit.com>2013-07-06 11:26:15 -0500
committerIsaac Dunham <idunham@lavabit.com>2013-07-06 11:26:15 -0500
commitc810f9f80b9db62de09b6cf4c6ca770eed72ce53 (patch)
tree2ef2dbf640e94ecd7918b54a1e1bea7ce779f78c /toys/other
parent8e9ec867e5753e63778d67c3cb1cce68792f7b24 (diff)
downloadtoybox-c810f9f80b9db62de09b6cf4c6ca770eed72ce53.tar.gz
This inlines CRC64, and nothing more.
The functions involved were called only once.
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/hello.c13
-rw-r--r--toys/other/netcat.c30
2 files changed, 24 insertions, 19 deletions
diff --git a/toys/other/hello.c b/toys/other/hello.c
index b0fc5381..a6bc69eb 100644
--- a/toys/other/hello.c
+++ b/toys/other/hello.c
@@ -5,7 +5,9 @@
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
* See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
-USE_HELLO(NEWTOY(hello, "e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN))
+// Accept many different kinds of command line argument:
+
+USE_HELLO(NEWTOY(hello, "(walrus)(blubber):e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN))
config HELLO
bool "hello"
@@ -29,14 +31,18 @@ GLOBALS(
long c_number;
struct arg_list *d_list;
long e_count;
+ char *blubber_string;
int more_globals;
)
+// Parse many different kinds of command line argument:
+
void hello_main(void)
{
printf("Hello world\n");
+ if (toys.optflags) printf("flags=%x\n", toys.optflags);
if (toys.optflags & FLAG_a) printf("Saw a\n");
if (toys.optflags & FLAG_b) printf("b=%s\n", TT.b_string);
if (toys.optflags & FLAG_c) printf("c=%ld\n", TT.c_number);
@@ -44,7 +50,8 @@ void hello_main(void)
printf("d=%s\n", TT.d_list->arg);
TT.d_list = TT.d_list->next;
}
- if (TT.e_count) printf("e was seen %ld times", TT.e_count);
-
+ if (TT.e_count) printf("e was seen %ld times\n", TT.e_count);
while (*toys.optargs) printf("optarg=%s\n", *(toys.optargs++));
+ if (toys.optflags & FLAG_walrus) printf("Saw --walrus\n");
+ if (TT.blubber_string) printf("--blubber=%s\n", TT.blubber_string);
}
diff --git a/toys/other/netcat.c b/toys/other/netcat.c
index 0173e6db..a245d119 100644
--- a/toys/other/netcat.c
+++ b/toys/other/netcat.c
@@ -11,13 +11,13 @@ config NETCAT
bool "netcat"
default y
help
- usage: netcat [-wpq #] [-s addr] {IPADDR PORTNUM|-f FILENAME|-let} [-e COMMAND]
+ usage: netcat [-wpq #] [-s addr] [-u] {IPADDR PORTNUM|-f FILENAME}
- -w SECONDS timeout for connection
+ -f use FILENAME (ala /dev/ttyS0) instead of network
-p local port number
- -s local ipv4 address
-q SECONDS quit this many seconds after EOF on stdin.
- -f use FILENAME (ala /dev/ttyS0) instead of network
+ -s local ipv4 address
+ -w SECONDS timeout for connection
Use "stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho" with
netcat -f to connect to a serial port.
@@ -27,13 +27,14 @@ config NETCAT_LISTEN
default y
depends on NETCAT
help
+ usage: netcat [-t] [-lL COMMAND...]
+
-t allocate tty (must come before -l or -L)
-l listen for one incoming connection.
-L listen for multiple incoming connections (server mode).
- Any additional command line arguments after -l or -L are executed
- to handle each incoming connection. If none, the connection is
- forwarded to stdin/stdout.
+ The command line after -l or -L is executed to handle each incoming
+ connection. If none, the connection is forwarded to stdin/stdout.
For a quick-and-dirty server, try something like:
netcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l
@@ -68,7 +69,7 @@ static void lookup_name(char *name, uint32_t *result)
{
struct hostent *hostbyname;
- hostbyname = gethostbyname(name);
+ hostbyname = gethostbyname(name); // getaddrinfo
if (!hostbyname) error_exit("no host '%s'", name);
*result = *(uint32_t *)*hostbyname->h_addr_list;
}
@@ -102,8 +103,7 @@ void netcat_main(void)
struct sockaddr_in address;
// Setup socket
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (-1 == sockfd) perror_exit("socket");
+ sockfd = xsocket(AF_INET, SOCK_STREAM, 0);
fcntl(sockfd, F_SETFD, FD_CLOEXEC);
temp = 1;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &temp, sizeof(temp));
@@ -140,7 +140,7 @@ void netcat_main(void)
}
// Do we need to return immediately because -l has arguments?
- if ((toys.optflags&FLAG_l) && toys.optc) {
+ if ((toys.optflags & FLAG_l) && toys.optc) {
if (fork()) goto cleanup;
close(0);
close(1);
@@ -170,7 +170,7 @@ void netcat_main(void)
if (!temp) close(sockfd);
dup2(fd, 0);
dup2(fd, 1);
- dup2(fd, 2);
+ if (toys.optflags&FLAG_L) dup2(fd, 2);
if (fd>2) close(fd);
}
}
@@ -186,10 +186,8 @@ void netcat_main(void)
// (Does not play well with -L, but what _should_ that do?)
set_alarm(0);
- if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc)) {
- execvp(*toys.optargs, toys.optargs);
- error_exit("Exec failed");
- }
+ if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc))
+ xexec(toys.optargs);
// Poll loop copying stdin->socket and socket->stdout.
for (;;) {