Mercurial > hg > toybox
comparison toys/other/netcat.c @ 674:7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 08 Oct 2012 00:02:30 -0500 |
parents | 6df4ccc0acbe |
children | 786841fdb1e0 |
comparison
equal
deleted
inserted
replaced
673:c102f31a753e | 674:7e846e281e38 |
---|---|
1 /* vi: set sw=4 ts=4: | 1 /* vi: set sw=4 ts=4: |
2 * | 2 * |
3 * netcat.c - Forward stdin/stdout to a file or network connection. | 3 * netcat.c - Forward stdin/stdout to a file or network connection. |
4 * | 4 * |
5 * Copyright 2007 Rob Landley <rob@landley.net> | 5 * Copyright 2007 Rob Landley <rob@landley.net> |
6 * | |
7 * TODO: udp, ipv6, genericize for telnet/microcom/tail-f | |
8 | |
6 | 9 |
7 USE_NETCAT(OLDTOY(nc, netcat, USE_NETCAT_LISTEN("tl^L^")"w#p#s:q#f:", TOYFLAG_BIN)) | 10 USE_NETCAT(OLDTOY(nc, netcat, USE_NETCAT_LISTEN("tl^L^")"w#p#s:q#f:", TOYFLAG_BIN)) |
8 USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("tl^L^")"w#p#s:q#f:", TOYFLAG_BIN)) | 11 USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("tl^L^")"w#p#s:q#f:", TOYFLAG_BIN)) |
9 | 12 |
10 config NETCAT | 13 config NETCAT |
38 | 41 |
39 For a quick-and-dirty server, try something like: | 42 For a quick-and-dirty server, try something like: |
40 netcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l | 43 netcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l |
41 */ | 44 */ |
42 | 45 |
46 #define FOR_netcat | |
43 #include "toys.h" | 47 #include "toys.h" |
44 #include "toynet.h" | 48 #include "toynet.h" |
45 | 49 |
46 DEFINE_GLOBALS( | 50 GLOBALS( |
47 char *filename; // -f read from filename instead of network | 51 char *filename; // -f read from filename instead of network |
48 long quit_delay; // -q Exit after EOF from stdin after # seconds. | 52 long quit_delay; // -q Exit after EOF from stdin after # seconds. |
49 char *source_address; // -s Bind to a specific source address. | 53 char *source_address; // -s Bind to a specific source address. |
50 long port; // -p Bind to a specific source port. | 54 long port; // -p Bind to a specific source port. |
51 long wait; // -w Wait # seconds for a connection. | 55 long wait; // -w Wait # seconds for a connection. |
52 ) | 56 ) |
53 | |
54 #define TT this.netcat | |
55 | |
56 #define FLAG_f 1 | |
57 #define FLAG_L 32 | |
58 #define FLAG_l 64 | |
59 #define FLAG_t 128 | |
60 | 57 |
61 static void timeout(int signum) | 58 static void timeout(int signum) |
62 { | 59 { |
63 if (TT.wait) error_exit("Timeout"); | 60 if (TT.wait) error_exit("Timeout"); |
64 exit(0); | 61 exit(0); |