1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-03 09:00:21 +00:00

Use err(3). 100 -> MAXHOSTNAMELEN from OpenBSD.

Obtained from: OpenBSD
This commit is contained in:
Philippe Charnier 1997-08-14 06:47:41 +00:00
parent a85a54896e
commit fd129a0245
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28202
4 changed files with 36 additions and 32 deletions

View File

@ -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 <guyton@rand-unix> */
@ -46,6 +50,7 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
/*
* TFTP User Program -- Command Interface.
*/
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>
@ -55,7 +60,7 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <err.h>
#include <netdb.h>
#include <setjmp.h>
#include <signal.h>
@ -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)

View File

@ -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

View File

@ -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 <guyton@rand-unix> */
@ -48,6 +52,7 @@ static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93";
#include <arpa/tftp.h>
#include <err.h>
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
@ -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

View File

@ -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