diff options
Diffstat (limited to 'toys/net')
-rw-r--r-- | toys/net/ftpget.c | 16 | ||||
-rw-r--r-- | toys/net/netcat.c | 38 | ||||
-rw-r--r-- | toys/net/ping.c | 5 | ||||
-rw-r--r-- | toys/net/tunctl.c | 4 |
4 files changed, 28 insertions, 35 deletions
diff --git a/toys/net/ftpget.c b/toys/net/ftpget.c index 9d6f6fd7..ad3c3030 100644 --- a/toys/net/ftpget.c +++ b/toys/net/ftpget.c @@ -46,9 +46,7 @@ config FTPPUT #include "toys.h" GLOBALS( - char *user; - char *port; - char *password; + char *u, *p, *P; int fd; ) @@ -101,20 +99,20 @@ void ftpget_main(void) if (!(toys.optflags&(FLAG_v-1))) toys.optflags |= (toys.which->name[3]=='g') ? FLAG_g : FLAG_s; - if (!TT.user) TT.user = "anonymous"; - if (!TT.password) TT.password = "ftpget@"; - if (!TT.port) TT.port = "21"; + if (!TT.u) TT.u = "anonymous"; + if (!TT.P) TT.P = "ftpget@"; + if (!TT.p) TT.p = "21"; if (!remote) remote = toys.optargs[1]; // connect - TT.fd = xconnect(xgetaddrinfo(*toys.optargs, TT.port, 0, SOCK_STREAM, 0, + TT.fd = xconnect(xgetaddrinfo(*toys.optargs, TT.p, 0, SOCK_STREAM, 0, AI_ADDRCONFIG)); if (getpeername(TT.fd, (void *)&si6, &sl)) perror_exit("getpeername"); // Login ftp_line(0, 0, 220); - rc = ftp_line("USER", TT.user, 0); - if (rc == 331) rc = ftp_line("PASS", TT.password, 0); + rc = ftp_line("USER", TT.u, 0); + if (rc == 331) rc = ftp_line("PASS", TT.P, 0); if (rc != 230) error_exit_raw(toybuf); if (toys.optflags & FLAG_m) { diff --git a/toys/net/netcat.c b/toys/net/netcat.c index 039b1944..54700c36 100644 --- a/toys/net/netcat.c +++ b/toys/net/netcat.c @@ -7,7 +7,7 @@ * netcat -L zombies USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN)) -USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("^tlL")"w#<1W#<1p#<1>65535s:q#<1f:"USE_NETCAT_LISTEN("[!tlL][!Lw]"), TOYFLAG_BIN)) +USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("^tlL")"w#<1W#<1p#<1>65535q#<1s:f:"USE_NETCAT_LISTEN("[!tlL][!Lw]"), TOYFLAG_BIN)) config NETCAT bool "netcat" @@ -20,7 +20,7 @@ config NETCAT -q quit SECONDS after EOF on stdin, even if stdout hasn't closed yet -s local source address -w SECONDS timeout to establish connection - -W SECONDS timeout for idle connection + -W SECONDS timeout for more data on an idle connection Use "stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho" with netcat -f to connect to a serial port. @@ -49,18 +49,14 @@ config NETCAT_LISTEN #include "toys.h" GLOBALS( - char *filename; // -f read from filename instead of network - long quit_delay; // -q Exit after EOF from stdin after # seconds. - char *source_address; // -s Bind to a specific source address. - long port; // -p Bind to a specific source port. - long idle; // -W Wait # seconds for more data - long wait; // -w Wait # seconds for a connection. + char *f, *s; + long q, p, W, w; ) static void timeout(int signum) { - if (TT.wait) error_exit("Timeout"); - // This should be xexit() but would need siglongjmp()... + if (TT.w) error_exit("Timeout"); + // TODO This should be xexit() but would need siglongjmp()... exit(0); } @@ -102,10 +98,10 @@ void netcat_main(void) pid_t child; // Addjust idle and quit_delay to miliseconds or -1 for no timeout - TT.idle = TT.idle ? TT.idle*1000 : -1; - TT.quit_delay = TT.quit_delay ? TT.quit_delay*1000 : -1; + TT.W = TT.W ? TT.W*1000 : -1; + TT.q = TT.q ? TT.q*1000 : -1; - set_alarm(TT.wait); + set_alarm(TT.w); // The argument parsing logic can't make "<2" conditional on other // arguments like -f and -l, so do it by hand here. @@ -113,17 +109,17 @@ void netcat_main(void) (!(toys.optflags&(FLAG_l|FLAG_L)) && toys.optc!=2)) help_exit("bad argument count"); - if (TT.filename) in1 = out2 = xopen(TT.filename, O_RDWR); + if (TT.f) in1 = out2 = xopen(TT.f, O_RDWR); else { // Setup socket sockfd = xsocket(AF_INET, SOCK_STREAM, 0); setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &out1, sizeof(out1)); address->sin_family = AF_INET; - if (TT.source_address || TT.port) { - address->sin_port = SWAP_BE16(TT.port); - if (TT.source_address) - lookup_name(TT.source_address, (uint32_t *)&(address->sin_addr)); + if (TT.s || TT.p) { + address->sin_port = SWAP_BE16(TT.p); + if (TT.s) + lookup_name(TT.s, (uint32_t *)&(address->sin_addr)); if (bind(sockfd, (struct sockaddr *)address, sizeof(*address))) perror_exit("bind"); } @@ -143,13 +139,13 @@ void netcat_main(void) in1 = out2 = sockfd; - pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay); + pollinate(in1, in2, out1, out2, TT.W, TT.q); } else { // Listen for incoming connections socklen_t len = sizeof(*address); if (listen(sockfd, 5)) error_exit("listen"); - if (!TT.port) { + if (!TT.p) { getsockname(sockfd, (struct sockaddr *)address, &len); printf("%d\n", SWAP_BE16(address->sin_port)); fflush(stdout); @@ -188,7 +184,7 @@ void netcat_main(void) xexec(toys.optargs); } - pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay); + pollinate(in1, in2, out1, out2, TT.W, TT.q); close(in1); } while (!(toys.optflags&FLAG_l)); } diff --git a/toys/net/ping.c b/toys/net/ping.c index ad7679fd..1829af71 100644 --- a/toys/net/ping.c +++ b/toys/net/ping.c @@ -11,7 +11,7 @@ * Yes, I wimped out and capped -s at sizeof(toybuf), waiting for a complaint... // -s > 4088 = sizeof(toybuf)-sizeof(struct icmphdr), then kernel adds 20 bytes -USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i%W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56i%W#<0=3w#<0qf46I:[-46]", TOYFLAG_USR|TOYFLAG_BIN)) USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN)) config PING @@ -47,9 +47,8 @@ config PING #include <netinet/ip_icmp.h> GLOBALS( - long w, W, i; char *I; - long s, c, t, m; + long w, W, i, s, c, t, m; struct sockaddr *sa; int sock; diff --git a/toys/net/tunctl.c b/toys/net/tunctl.c index 1aafebfd..6a2cf1ee 100644 --- a/toys/net/tunctl.c +++ b/toys/net/tunctl.c @@ -32,13 +32,13 @@ config TUNCTL #include <linux/if_tun.h> GLOBALS( - char *user; + char *u; ) void tunctl_main(void) { struct ifreq *ifr = (void *)toybuf; - uid_t u = TT.user ? xgetuid(TT.user) : 0; + uid_t u = TT.u ? xgetuid(TT.u) : 0; int fd = xopen("/dev/net/tun", O_RDWR); // Associate filehandle with device |