diff options
author | 2001-03-22 01:34:01 +0000 | |
---|---|---|
committer | 2001-03-22 01:34:01 +0000 | |
commit | 3ff9bf5d354a0fe4b73ec681f292e8ef55eecfce (patch) | |
tree | 9920154bef5f95b349c559234339979d997c73b9 /usr.bin/tftp/main.c | |
parent | Fix thinko in kn_do_query error checking; angelos OK'd (diff) | |
download | wireguard-openbsd-3ff9bf5d354a0fe4b73ec681f292e8ef55eecfce.tar.xz wireguard-openbsd-3ff9bf5d354a0fe4b73ec681f292e8ef55eecfce.zip |
use err/warn, space police
Diffstat (limited to 'usr.bin/tftp/main.c')
-rw-r--r-- | usr.bin/tftp/main.c | 43 |
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) |