diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-05-12 23:41:47 +0400 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-05-12 23:41:47 +0400 |
commit | 7ab9c7ee52db8759d457819f5480378fa3aa97cc (patch) | |
tree | 37ef0fb8b142a4925b866c7caa5207b71b4ecae6 /networking | |
parent | 3d427ac5efd249dc25dd03deb30520335f68911a (diff) |
Lots of updates. Finished implementing BB_FEATURE_TRIVIAL_HELP
which lets you compile out most of the "--help" output, saving
up to 17k.
Renamed mnc to nc.
-Erik
Diffstat (limited to 'networking')
-rw-r--r-- | networking/hostname.c | 11 | ||||
-rw-r--r-- | networking/nc.c | 133 | ||||
-rw-r--r-- | networking/nslookup.c | 8 | ||||
-rw-r--r-- | networking/ping.c | 17 | ||||
-rw-r--r-- | networking/telnet.c | 9 |
5 files changed, 165 insertions, 13 deletions
diff --git a/networking/hostname.c b/networking/hostname.c index 8cc334da0..ef921024b 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: hostname.c,v 1.7 2000/02/08 19:58:47 erik Exp $ + * $Id: hostname.c,v 1.8 2000/05/12 19:41:47 erik Exp $ * Mini hostname implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -31,15 +31,18 @@ #include <stdio.h> static const char *hostname_usage = - "hostname [OPTION] {hostname | -F file}\n\n" - "Get or set the hostname or DNS domain name. If a hostname is given\n" + "hostname [OPTION] {hostname | -F file}\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nGet or set the hostname or DNS domain name. If a hostname is given\n" "(or a file with the -F parameter), the host name will be set.\n\n" "Options:\n" "\t-s\t\tShort\n" "\t-i\t\tAddresses for the hostname\n" "\t-d\t\tDNS domain name\n" - "\t-F FILE\t\tUse the contents of FILE to specify the hostname\n"; + "\t-F FILE\t\tUse the contents of FILE to specify the hostname\n" +#endif + ; void do_sethostname(char *s, int isfile) diff --git a/networking/nc.c b/networking/nc.c new file mode 100644 index 000000000..a588587fb --- /dev/null +++ b/networking/nc.c @@ -0,0 +1,133 @@ +/* vi: set sw=4 ts=4: */ +/* nc: mini-netcat - built from the ground up for LRP + Copyright (C) 1998 Charles P. Wright + + 0.0.1 6K It works. + 0.0.2 5K Smaller and you can also check the exit condition if you wish. + 0.0.3 Uses select() + + 19980918 Busy Boxed! Dave Cinege + 19990512 Uses Select. Charles P. Wright + 19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +#include "internal.h" +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <sys/time.h> +#include <sys/ioctl.h> + +#define BUFSIZE 100 + +static const char nc_usage[] = "nc [IP] [port]\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nNetcat opens a pipe to IP:port\n" +#endif + ; + +int nc_main(int argc, char **argv) +{ + int sfd; + int result; + int len; + char ch[BUFSIZE]; + + struct sockaddr_in address; + struct hostent *hostinfo; + + fd_set readfds, testfds; + + argc--; + argv++; + if (argc < 2 || **(argv + 1) == '-') { + usage(nc_usage); + } + + sfd = socket(AF_INET, SOCK_STREAM, 0); + + hostinfo = (struct hostent *) gethostbyname(*argv); + + if (!hostinfo) { + exit(1); + } + + address.sin_family = AF_INET; + address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; + address.sin_port = htons(atoi(*(++argv))); + + len = sizeof(address); + + result = connect(sfd, (struct sockaddr *) &address, len); + + if (result < 0) { + exit(2); + } + + FD_ZERO(&readfds); + FD_SET(sfd, &readfds); + FD_SET(fileno(stdin), &readfds); + + while (1) { + int fd; + int ofd; + int nread; + + testfds = readfds; + + result = + select(FD_SETSIZE, &testfds, (fd_set *) NULL, (fd_set *) NULL, + (struct timeval *) 0); + + if (result < 1) { + exit(3); + } + + for (fd = 0; fd < FD_SETSIZE; fd++) { + if (FD_ISSET(fd, &testfds)) { + int trn = 0; + int rn; + + ioctl(fd, FIONREAD, &nread); + + if (fd == sfd) { + if (nread == 0) + exit(0); + ofd = fileno(stdout); + } else { + ofd = sfd; + } + + + + do { + rn = (BUFSIZE < nread - trn) ? BUFSIZE : nread - trn; + trn += rn; + read(fd, ch, rn); + write(ofd, ch, rn); + } + while (trn < nread); + } + } + } +} diff --git a/networking/nslookup.c b/networking/nslookup.c index e4bf52f80..82bcf56a1 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c @@ -41,7 +41,11 @@ | + find out how the real nslookup gets the default name server */ -static const char nslookup_usage[] = "nslookup [HOST]\n\nQueries the nameserver for the IP address of the given HOST\n"; +static const char nslookup_usage[] = "nslookup [HOST]\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nQueries the nameserver for the IP address of the given HOST\n" +#endif +; /* I have to see how the real nslookup does this. @@ -173,4 +177,4 @@ int nslookup_main(int argc, char **argv) exit( TRUE); } -/* $Id: nslookup.c,v 1.8 2000/05/02 00:07:56 erik Exp $ */ +/* $Id: nslookup.c,v 1.9 2000/05/12 19:41:47 erik Exp $ */ diff --git a/networking/ping.c b/networking/ping.c index 9f83002a2..14a56cd55 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: ping.c,v 1.14 2000/04/25 23:24:55 erik Exp $ + * $Id: ping.c,v 1.15 2000/05/12 19:41:47 erik Exp $ * Mini ping implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -90,7 +90,11 @@ static int in_cksum(unsigned short *buf, int sz) /* simple version */ #ifdef BB_SIMPLE_PING -static const char *ping_usage = "ping host\n\n"; +static const char *ping_usage = "ping host\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nSend ICMP ECHO_REQUEST packets to network hosts\n" +#endif + ; static char *hostname = NULL; @@ -179,12 +183,15 @@ extern int ping_main(int argc, char **argv) #else /* full(er) version */ -static const char *ping_usage = "ping [OPTION]... host\n\n" - "Send ICMP ECHO_REQUEST packets to network hosts.\n\n" +static const char *ping_usage = "ping [OPTION]... host\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nSend ICMP ECHO_REQUEST packets to network hosts.\n\n" "Options:\n" "\t-c COUNT\tSend only COUNT pings.\n" "\t-q\t\tQuiet mode, only displays output at start\n" - "\t\t\tand when finished.\n"; + "\t\t\tand when finished.\n" +#endif + ; static char *hostname = NULL; static struct sockaddr_in pingaddr; diff --git a/networking/telnet.c b/networking/telnet.c index 8c58521eb..8b6d5f5dc 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -1,5 +1,5 @@ /* - * $Id: telnet.c,v 1.2 2000/05/01 19:10:52 erik Exp $ + * $Id: telnet.c,v 1.3 2000/05/12 19:41:47 erik Exp $ * Mini telnet implementation for busybox * * Copyright (C) 2000 by Randolph Chung <tausq@debian.org> @@ -46,7 +46,12 @@ static int STDIN = 0; static int STDOUT = 1; -static const char *telnet_usage = "telnet host [port]\n\n"; +static const char *telnet_usage = "telnet host [port]\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nProvides interactive communication with another\n" + "networked host using the TELNET protocol\n" +#endif + ; static struct termios saved_tc; static unsigned char options[NTELOPTS]; static char tr_state = 0; /* telnet send and receive state */ |