summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-03-22 01:34:02 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-03-22 01:34:02 +0000
commitccafea6d5edf0b2e97cd81b18efbdaa338a53476 (patch)
treeedd544e5f16b679b57cc7e5c39ddb1079c43a415
parentc789dfd638e7a1fbb38261b8542ca946b5905ed3 (diff)
use err/warn, space police
-rw-r--r--usr.bin/tftp/main.c43
-rw-r--r--usr.bin/tftp/tftp.c16
2 files changed, 26 insertions, 33 deletions
diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
index 2b98d7efbaf..2a71ab739be 100644
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.5 2000/12/07 18:13:14 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.6 2001/03/22 01:34:01 mickey Exp $ */
/* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: main.c,v 1.5 2000/12/07 18:13:14 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.6 2001/03/22 01:34:01 mickey Exp $";
#endif /* not lint */
/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
@@ -69,6 +69,7 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.5 2000/12/07 18:13:14 deraadt Exp $"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <err.h>
#include "extern.h"
@@ -162,21 +163,15 @@ main(argc, argv)
struct sockaddr_in s_in;
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, "tftp: socket");
bzero((char *)&s_in, sizeof (s_in));
s_in.sin_family = AF_INET;
- if (bind(f, (struct sockaddr *)&s_in, sizeof (s_in)) < 0) {
- perror("tftp: bind");
- exit(1);
- }
+ if (bind(f, (struct sockaddr *)&s_in, sizeof (s_in)) < 0)
+ err(1, "tftp: bind");
strcpy(mode, "netascii");
signal(SIGINT, intr);
if (argc > 1) {
@@ -291,7 +286,7 @@ void
setbinary(argc, argv)
int argc;
char *argv[];
-{
+{
settftpmode("octet");
}
@@ -355,8 +350,7 @@ put(argc, argv)
*targ++ = 0;
hp = gethostbyname(cp);
if (hp == NULL) {
- fprintf(stderr, "tftp: %s: ", cp);
- herror((char *)NULL);
+ warnx("%s: %s", cp, hstrerror(h_errno));
return;
}
bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr, hp->h_length);
@@ -372,7 +366,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("open: %s", cp);
return;
}
if (verbose)
@@ -384,13 +378,13 @@ put(argc, argv)
}
/* this assumes the target is a directory */
/* on a remote unix system. hmmmm. */
- cp = strchr(targ, '\0');
+ cp = strchr(targ, '\0');
*cp++ = '/';
for (n = 1; n < argc - 1; n++) {
strcpy(cp, tail(argv[n]));
fd = open(argv[n], O_RDONLY);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(argv[n]);
+ warn("open: %s", argv[n]);
continue;
}
if (verbose)
@@ -452,8 +446,7 @@ get(argc, argv)
*src++ = 0;
hp = gethostbyname(argv[n]);
if (hp == NULL) {
- fprintf(stderr, "tftp: %s: ", argv[n]);
- herror((char *)NULL);
+ warnx("%s: %s", argv[n], hstrerror(h_errno));
continue;
}
bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr,
@@ -466,7 +459,7 @@ get(argc, argv)
cp = argc == 3 ? argv[2] : tail(src);
fd = creat(cp, 0644);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(cp);
+ warn("create: %s", cp);
return;
}
if (verbose)
@@ -479,7 +472,7 @@ get(argc, argv)
cp = tail(src); /* new .. jdg */
fd = creat(cp, 0644);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(cp);
+ warn("create: %s", cp);
continue;
}
if (verbose)
@@ -585,7 +578,7 @@ tail(filename)
char *filename;
{
register char *s;
-
+
while (*filename) {
s = strrchr(filename, '/');
if (s == NULL)
diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c
index 9776e1ede5d..c03a88493e0 100644
--- a/usr.bin/tftp/tftp.c
+++ b/usr.bin/tftp/tftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tftp.c,v 1.6 2000/12/07 18:13:14 deraadt Exp $ */
+/* $OpenBSD: tftp.c,v 1.7 2001/03/22 01:34:01 mickey Exp $ */
/* $NetBSD: tftp.c,v 1.5 1995/04/29 05:55:25 cgd Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: tftp.c,v 1.6 2000/12/07 18:13:14 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: tftp.c,v 1.7 2001/03/22 01:34:01 mickey Exp $";
#endif /* not lint */
/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
@@ -60,6 +60,7 @@ static char rcsid[] = "$OpenBSD: tftp.c,v 1.6 2000/12/07 18:13:14 deraadt Exp $"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <err.h>
#include "extern.h"
#include "tftpsubs.h"
@@ -134,7 +135,7 @@ send_data:
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);
@@ -147,7 +148,7 @@ send_data:
} while (n <= 0);
alarm(0);
if (n < 0) {
- perror("tftp: recvfrom");
+ warn("recvfrom");
goto abort;
}
peeraddr.sin_port = from.sin_port; /* added */
@@ -238,7 +239,7 @@ send_ack:
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);
@@ -251,7 +252,7 @@ send_ack:
} while (n <= 0);
alarm(0);
if (n < 0) {
- perror("tftp: recvfrom");
+ warn("recvfrom");
goto abort;
}
peeraddr.sin_port = from.sin_port; /* added */
@@ -351,7 +352,6 @@ nak(error)
register struct errmsg *pe;
register struct tftphdr *tp;
int length;
- char *strerror();
tp = (struct tftphdr *)ackbuf;
tp->th_opcode = htons((u_short)ERROR);
@@ -369,7 +369,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