diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 4763f4363cc3..5c9376d5fc01 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -32,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1983, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ /* Many bug fixes are from Jim Guyton */ @@ -46,6 +50,7 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; /* * TFTP User Program -- Command Interface. */ +#include #include #include #include @@ -55,7 +60,7 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #include #include -#include +#include #include #include #include @@ -145,8 +150,6 @@ struct cmd cmdtab[] = { struct cmd *getcmd(); char *tail(); -char *index(); -char *rindex(); int main(argc, argv) @@ -156,21 +159,15 @@ main(argc, argv) struct sockaddr_in sin; sp = getservbyname("tftp", "udp"); - if (sp == 0) { - fprintf(stderr, "tftp: udp/tftp: unknown service\n"); - exit(1); - } + if (sp == 0) + errx(1, "udp/tftp: unknown service"); f = socket(AF_INET, SOCK_DGRAM, 0); - if (f < 0) { - perror("tftp: socket"); - exit(3); - } + if (f < 0) + err(3, "socket"); bzero((char *)&sin, sizeof(sin)); sin.sin_family = AF_INET; - if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - perror("tftp: bind"); - exit(1); - } + if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) + err(1, "bind"); strcpy(mode, "netascii"); signal(SIGINT, intr); if (argc > 1) { @@ -183,7 +180,7 @@ main(argc, argv) command(); } -char hostname[100]; +char hostname[MAXHOSTNAMELEN]; void setpeer(argc, argv) @@ -364,7 +361,7 @@ put(argc, argv) cp = argc == 2 ? tail(targ) : argv[1]; fd = open(cp, O_RDONLY); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(cp); + warn("%s", cp); return; } if (verbose) @@ -382,7 +379,7 @@ put(argc, argv) strcpy(cp, tail(argv[n])); fd = open(argv[n], O_RDONLY); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(argv[n]); + warn("%s", argv[n]); continue; } if (verbose) @@ -457,7 +454,7 @@ get(argc, argv) cp = argc == 3 ? argv[2] : tail(src); fd = creat(cp, 0644); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(cp); + warn("%s", cp); return; } if (verbose) @@ -470,7 +467,7 @@ get(argc, argv) cp = tail(src); /* new .. jdg */ fd = creat(cp, 0644); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(cp); + warn("%s", cp); continue; } if (verbose) diff --git a/usr.bin/tftp/tftp.1 b/usr.bin/tftp/tftp.1 index b2c5a16d707c..4b1a25931f4d 100644 --- a/usr.bin/tftp/tftp.1 +++ b/usr.bin/tftp/tftp.1 @@ -38,7 +38,7 @@ .Nm tftp .Nd trivial file transfer program .Sh SYNOPSIS -.Nm tftp +.Nm .Op Ar host .Sh DESCRIPTION .Nm Tftp @@ -49,7 +49,7 @@ which allows users to transfer files to and from a remote machine. The remote .Ar host may be specified on the command line, in which case -.Nm tftp +.Nm uses .Ar host as the default host for future transfers (see the @@ -57,9 +57,9 @@ as the default host for future transfers (see the command below). .Sh COMMANDS Once -.Nm tftp +.Nm is running, it issues the prompt -.LI tftp> +.Nm tftp> and recognizes the following commands: .Pp .Bl -tag -width verbose -compact diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c index 2ca4001b1714..014e28763179 100644 --- a/usr.bin/tftp/tftp.c +++ b/usr.bin/tftp/tftp.c @@ -32,7 +32,11 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ /* Many bug fixes are from Jim Guyton */ @@ -48,6 +52,7 @@ static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; #include +#include #include #include #include @@ -57,8 +62,6 @@ static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; #include "extern.h" #include "tftpsubs.h" -extern int errno; - extern struct sockaddr_in peeraddr; /* filled in by main */ extern int f; /* the opened socket */ extern int trace; @@ -128,7 +131,7 @@ sendfile(fd, name, mode) n = sendto(f, dp, size + 4, 0, (struct sockaddr *)&peeraddr, sizeof(peeraddr)); if (n != size + 4) { - perror("tftp: sendto"); + warn("sendto"); goto abort; } read_ahead(file, convert); @@ -141,7 +144,7 @@ sendfile(fd, name, mode) } while (n <= 0); alarm(0); if (n < 0) { - perror("tftp: recvfrom"); + warn("recvfrom"); goto abort; } peeraddr.sin_port = from.sin_port; /* added */ @@ -232,7 +235,7 @@ recvfile(fd, name, mode) if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peeraddr, sizeof(peeraddr)) != size) { alarm(0); - perror("tftp: sendto"); + warn("sendto"); goto abort; } write_behind(file, convert); @@ -245,7 +248,7 @@ recvfile(fd, name, mode) } while (n <= 0); alarm(0); if (n < 0) { - perror("tftp: recvfrom"); + warn("recvfrom"); goto abort; } peeraddr.sin_port = from.sin_port; /* added */ @@ -363,7 +366,7 @@ nak(error) tpacket("sent", tp, length); if (sendto(f, ackbuf, length, 0, (struct sockaddr *)&peeraddr, sizeof(peeraddr)) != length) - perror("nak"); + warn("nak"); } static void diff --git a/usr.bin/tftp/tftpsubs.c b/usr.bin/tftp/tftpsubs.c index a143602dbea5..277d561403e0 100644 --- a/usr.bin/tftp/tftpsubs.c +++ b/usr.bin/tftp/tftpsubs.c @@ -32,7 +32,11 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ /* Simple minded read-ahead/write-behind subroutines for tftp user and