aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-04-26 23:59:12 +0000
committerEric Andersen <andersen@codepoet.org>2002-04-26 23:59:12 +0000
commit1323c940fd651a818e133f5c13f28b708998420a (patch)
treea73ac5d076263be38e8e419ea07b565a1acf0296
parent00a6a750357d49d3e9cedf3edee7ae2aceae6748 (diff)
downloadbusybox-w32-1323c940fd651a818e133f5c13f28b708998420a.tar.gz
busybox-w32-1323c940fd651a818e133f5c13f28b708998420a.tar.bz2
busybox-w32-1323c940fd651a818e133f5c13f28b708998420a.zip
Add netcat -i option, per patch from Cristian Ionescu-Idbohrn
<cristian.ionescu-idbohrn@axis.com>
-rw-r--r--include/usage.h1
-rw-r--r--networking/nc.c42
2 files changed, 41 insertions, 2 deletions
diff --git a/include/usage.h b/include/usage.h
index d690d90f9..ad34dfcff 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1267,6 +1267,7 @@
1267 "Options:\n" \ 1267 "Options:\n" \
1268 "\t-l\t\tlisten mode, for inbound connects\n" \ 1268 "\t-l\t\tlisten mode, for inbound connects\n" \
1269 "\t-p PORT\t\tlocal port number\n" \ 1269 "\t-p PORT\t\tlocal port number\n" \
1270 "\t-i SECS\t\tdelay interval for lines sent\n" \
1270 "\t-e PROG\t\tprogram to exec after connect (dangerous!)" 1271 "\t-e PROG\t\tprogram to exec after connect (dangerous!)"
1271#define nc_example_usage \ 1272#define nc_example_usage \
1272 "$ nc foobar.somedomain.com 25\n" \ 1273 "$ nc foobar.somedomain.com 25\n" \
diff --git a/networking/nc.c b/networking/nc.c
index 5335872e5..e1741cdb3 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -40,17 +40,22 @@
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include "busybox.h" 41#include "busybox.h"
42 42
43#define GAPING_SECURITY_HOLE
44
43int nc_main(int argc, char **argv) 45int nc_main(int argc, char **argv)
44{ 46{
45 int do_listen = 0, lport = 0, tmpfd, opt, sfd; 47 int do_listen = 0, lport = 0, delay = 0, tmpfd, opt, sfd;
46 char buf[BUFSIZ]; 48 char buf[BUFSIZ];
49#ifdef GAPING_SECURITY_HOLE
50 char * pr00gie = NULL;
51#endif
47 52
48 struct sockaddr_in address; 53 struct sockaddr_in address;
49 struct hostent *hostinfo; 54 struct hostent *hostinfo;
50 55
51 fd_set readfds, testfds; 56 fd_set readfds, testfds;
52 57
53 while ((opt = getopt(argc, argv, "lp:")) > 0) { 58 while ((opt = getopt(argc, argv, "lp:i:e:")) > 0) {
54 switch (opt) { 59 switch (opt) {
55 case 'l': 60 case 'l':
56 do_listen++; 61 do_listen++;
@@ -58,11 +63,27 @@ int nc_main(int argc, char **argv)
58 case 'p': 63 case 'p':
59 lport = atoi(optarg); 64 lport = atoi(optarg);
60 break; 65 break;
66 case 'i':
67 delay = atoi(optarg);
68 break;
69#ifdef GAPING_SECURITY_HOLE
70 case 'e':
71 pr00gie = optarg;
72 break;
73#endif
61 default: 74 default:
62 show_usage(); 75 show_usage();
63 } 76 }
64 } 77 }
65 78
79#ifdef GAPING_SECURITY_HOLE
80 if (pr00gie) {
81 /* won't need stdin */
82 close (fileno(stdin));
83 }
84#endif /* GAPING_SECURITY_HOLE */
85
86
66 if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc)) 87 if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc))
67 show_usage(); 88 show_usage();
68 89
@@ -100,6 +121,20 @@ int nc_main(int argc, char **argv)
100 perror_msg_and_die("connect"); 121 perror_msg_and_die("connect");
101 } 122 }
102 123
124#ifdef GAPING_SECURITY_HOLE
125 /* -e given? */
126 if (pr00gie) {
127 dup2(sfd, 0);
128 close(sfd);
129 dup2 (0, 1);
130 dup2 (0, 2);
131 execl (pr00gie, pr00gie, NULL);
132 /* Don't print stuff or it will go over the wire.... */
133 _exit(-1);
134 }
135#endif /* GAPING_SECURITY_HOLE */
136
137
103 FD_ZERO(&readfds); 138 FD_ZERO(&readfds);
104 FD_SET(sfd, &readfds); 139 FD_SET(sfd, &readfds);
105 FD_SET(STDIN_FILENO, &readfds); 140 FD_SET(STDIN_FILENO, &readfds);
@@ -131,6 +166,9 @@ int nc_main(int argc, char **argv)
131 166
132 if (full_write(ofd, buf, nread) < 0) 167 if (full_write(ofd, buf, nread) < 0)
133 perror_msg_and_die("write"); 168 perror_msg_and_die("write");
169 if (delay > 0) {
170 sleep(delay);
171 }
134 } 172 }
135 } 173 }
136 } 174 }