Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/tftp ansify, const, knf
details: https://anonhg.NetBSD.org/src/rev/fa3b0cf76e1b
branches: trunk
changeset: 769667:fa3b0cf76e1b
user: christos <christos%NetBSD.org@localhost>
date: Sat Sep 17 15:15:46 2011 +0000
description:
ansify, const, knf
diffstat:
usr.bin/tftp/extern.h | 6 +-
usr.bin/tftp/main.c | 386 +++++++++++++++++++++--------------------------
usr.bin/tftp/tftp.c | 14 +-
usr.bin/tftp/tftpsubs.c | 59 +++---
usr.bin/tftp/tftpsubs.h | 16 +-
5 files changed, 211 insertions(+), 270 deletions(-)
diffs (truncated from 1023 to 300 lines):
diff -r 5258260527da -r fa3b0cf76e1b usr.bin/tftp/extern.h
--- a/usr.bin/tftp/extern.h Sat Sep 17 14:44:18 2011 +0000
+++ b/usr.bin/tftp/extern.h Sat Sep 17 15:15:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.6 2006/07/21 17:49:00 jmcneill Exp $ */
+/* $NetBSD: extern.h,v 1.7 2011/09/17 15:15:46 christos Exp $ */
/*
* Copyright (c) 1993
@@ -47,5 +47,5 @@
extern ushort mcmasterslave;
extern struct sockaddr_storage peeraddr; /* filled in by main */
-void recvfile __P((int, char *, char *));
-void sendfile __P((int, char *, char *));
+void recvfile(int, const char *, const char *);
+void sendfile(int, const char *, const char *);
diff -r 5258260527da -r fa3b0cf76e1b usr.bin/tftp/main.c
--- a/usr.bin/tftp/main.c Sat Sep 17 14:44:18 2011 +0000
+++ b/usr.bin/tftp/main.c Sat Sep 17 15:15:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.28 2011/09/17 03:09:51 minskim Exp $ */
+/* $NetBSD: main.c,v 1.29 2011/09/17 15:15:46 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: main.c,v 1.28 2011/09/17 03:09:51 minskim Exp $");
+__RCSID("$NetBSD: main.c,v 1.29 2011/09/17 15:15:46 christos Exp $");
#endif
#endif /* not lint */
@@ -46,6 +46,7 @@
* TFTP User Program -- Command Interface.
*/
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -77,74 +78,78 @@
int verbose;
int tsize=0;
int tout=0;
-size_t def_blksize=SEGSIZE;
-size_t blksize=SEGSIZE;
+size_t def_blksize = SEGSIZE;
+size_t blksize = SEGSIZE;
in_addr_t mcaddr = INADDR_NONE;
uint16_t mcport;
+u_int def_rexmtval = TIMEOUT;
+u_int rexmtval = TIMEOUT;
ushort mcmasterslave;
-int connected;
-char mode[32];
-char line[LBUFLEN];
-int margc;
-char *margv[20];
-const char *prompt = "tftp";
-jmp_buf toplevel;
+int maxtimeout = 5 * TIMEOUT;
+
+static int connected;
+static char mode[32];
+static char line[LBUFLEN];
+static int margc;
+static char *margv[20];
+static const char *prompt = "tftp";
+static char hostname[MAXHOSTNAMELEN];
+static jmp_buf toplevel;
-void get __P((int, char **));
-void help __P((int, char **));
-void modecmd __P((int, char **));
-void put __P((int, char **));
-__dead static void quit __P((int, char **));
-void setascii __P((int, char **));
-void setbinary __P((int, char **));
-void setpeer0 __P((const char *, const char *));
-void setpeer __P((int, char **));
-void setrexmt __P((int, char **));
-void settimeout __P((int, char **));
-void settrace __P((int, char **));
-void setverbose __P((int, char **));
-void setblksize __P((int, char **));
-void settsize __P((int, char **));
-void settimeoutopt __P((int, char **));
-void status __P((int, char **));
-char *tail __P((char *));
-int main __P((int, char *[]));
-__dead static void intr __P((int));
-const struct cmd *getcmd __P((char *));
+static void get(int, char **);
+static void help(int, char **);
+static void modecmd(int, char **);
+static void put(int, char **);
+static __dead void quit(int, char **);
+static void setascii(int, char **);
+static void setbinary(int, char **);
+static void setpeer0(const char *, const char *);
+static void setpeer(int, char **);
+static void setrexmt(int, char **);
+static void settimeout(int, char **);
+static void settrace(int, char **);
+static void setverbose(int, char **);
+static void setblksize(int, char **);
+static void settsize(int, char **);
+static void settimeoutopt(int, char **);
+static void status(int, char **);
+static char *tail(char *);
+static __dead void intr(int);
+static const struct cmd *getcmd(const char *);
-static __dead void command __P((void));
+static __dead void command(void);
-static void getusage __P((char *));
-static void makeargv __P((void));
-static void putusage __P((char *));
-static void settftpmode __P((const char *));
+static void getUsage(char *);
+static void makeargv(void);
+static void putUsage(const char *);
+static void settftpmode(const char *);
-#define HELPINDENT (sizeof("connect"))
+#define HELPINDENT sizeof("connect")
struct cmd {
const char *name;
const char *help;
- void (*handler) __P((int, char **));
+ void (*handler)(int, char **);
};
-const char vhelp[] = "toggle verbose mode";
-const char thelp[] = "toggle packet tracing";
-const char tshelp[] = "toggle extended tsize option";
-const char tohelp[] = "toggle extended timeout option";
-const char blhelp[] = "set an alternative blocksize (def. 512)";
-const char chelp[] = "connect to remote tftp";
-const char qhelp[] = "exit tftp";
-const char hhelp[] = "print help information";
-const char shelp[] = "send file";
-const char rhelp[] = "receive file";
-const char mhelp[] = "set file transfer mode";
-const char sthelp[] = "show current status";
-const char xhelp[] = "set per-packet retransmission timeout";
-const char ihelp[] = "set total retransmission timeout";
-const char ashelp[] = "set mode to netascii";
-const char bnhelp[] = "set mode to octet";
+static const char vhelp[] = "toggle verbose mode";
+static const char thelp[] = "toggle packet tracing";
+static const char tshelp[] = "toggle extended tsize option";
+static const char tohelp[] = "toggle extended timeout option";
+static const char blhelp[] = "set an alternative blocksize (def. 512)";
+static const char chelp[] = "connect to remote tftp";
+static const char qhelp[] = "exit tftp";
+static const char hhelp[] = "print help information";
+static const char shelp[] = "send file";
+static const char rhelp[] = "receive file";
+static const char mhelp[] = "set file transfer mode";
+static const char sthelp[] = "show current status";
+static const char xhelp[] = "set per-packet retransmission timeout";
+static const char ihelp[] = "set total retransmission timeout";
+static const char ashelp[] = "set mode to netascii";
+static const char bnhelp[] = "set mode to octet";
-const struct cmd cmdtab[] = {
+static const struct cmd cmdtab[] = {
{ "connect", chelp, setpeer },
{ "mode", mhelp, modecmd },
{ "put", shelp, put },
@@ -164,10 +169,21 @@
{ .name = NULL }
};
+static struct modes {
+ const char *m_name;
+ const char *m_mode;
+} modes[] = {
+ { "ascii", "netascii" },
+ { "netascii", "netascii" },
+ { "binary", "octet" },
+ { "image", "octet" },
+ { "octet", "octet" },
+/* { "mail", "mail" }, */
+ { 0, 0 }
+};
+
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
int c;
@@ -185,8 +201,8 @@
tout = 1;
break;
default:
- (void)printf("usage: %s [-e] host-name [port]\n",
- getprogname());
+ (void)fprintf(stderr,
+ "Usage: %s [-e] host-name [port]\n", getprogname());
exit(1);
}
}
@@ -203,15 +219,20 @@
if (setjmp(toplevel) != 0)
(void)putchar('\n');
command();
- return (0);
+ return 0;
}
-char hostname[100];
+static void
+getmore(const char *cmd, const char *prm)
+{
+ (void)strlcpy(line, cmd, sizeof(line));
+ (void)printf("%s", prm);
+ (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin);
+ makeargv();
+}
-void
-setpeer0(host, port)
- const char *host;
- const char *port;
+static void
+setpeer0(const char *host, const char *port)
{
struct addrinfo hints, *res0, *res;
int error, soopt;
@@ -241,7 +262,7 @@
if (res->ai_addrlen > sizeof(peeraddr))
continue;
f = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
- if (f < 0) {
+ if (f == -1) {
cause = "socket";
continue;
}
@@ -250,7 +271,7 @@
ss.ss_family = res->ai_family;
ss.ss_len = res->ai_addrlen;
if (bind(f, (struct sockaddr *)(void *)&ss,
- (socklen_t)ss.ss_len) < 0) {
+ (socklen_t)ss.ss_len) == -1) {
cause = "bind";
(void)close(f);
f = -1;
@@ -263,20 +284,20 @@
if (f >= 0) {
soopt = 65536;
if (setsockopt(f, SOL_SOCKET, SO_SNDBUF, &soopt, sizeof(soopt))
- < 0) {
+ == -1) {
(void)close(f);
f = -1;
cause = "setsockopt SNDBUF";
}
- else if (setsockopt(f, SOL_SOCKET, SO_RCVBUF, &soopt, sizeof(soopt))
- < 0) {
+ else if (setsockopt(f, SOL_SOCKET, SO_RCVBUF, &soopt,
+ sizeof(soopt)) == -1) {
(void)close(f);
f = -1;
cause = "setsockopt RCVBUF";
}
}
- if (f < 0 || res == NULL)
+ if (f == -1 || res == NULL)
warn("%s", cause);
else {
/* res->ai_addr <= sizeof(peeraddr) is guaranteed */
@@ -292,22 +313,18 @@
freeaddrinfo(res0);
}
-void
-setpeer(argc, argv)
- int argc;
- char *argv[];
+static void
+setpeer(int argc, char *argv[])
{
if (argc < 2) {
- (void)strlcpy(line, "Connect ", sizeof(line));
- (void)printf("(to) ");
- (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin);
- makeargv();
+ getmore("Connect ", "(to) ");
Home |
Main Index |
Thread Index |
Old Index