summaryrefslogtreecommitdiff
path: root/usr.bin/tftp/main.c
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 /usr.bin/tftp/main.c
parentc789dfd638e7a1fbb38261b8542ca946b5905ed3 (diff)
use err/warn, space police
Diffstat (limited to 'usr.bin/tftp/main.c')
-rw-r--r--usr.bin/tftp/main.c43
1 files changed, 18 insertions, 25 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)