main.c (eaa86f9d7fcbe6b82b1defa62f31071324c836ed) main.c (fd129a0245ccdbed26aee4a48cd7d4b2fa74a99d)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char copyright[] =
35static const char copyright[] =
36"@(#) Copyright (c) 1983, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
36"@(#) Copyright (c) 1983, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
41static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
42static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
43#endif
44static const char rcsid[] =
45 "$Id$";
42#endif /* not lint */
43
44/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
45
46/*
47 * TFTP User Program -- Command Interface.
48 */
46#endif /* not lint */
47
48/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
49
50/*
51 * TFTP User Program -- Command Interface.
52 */
53#include <sys/param.h>
49#include <sys/types.h>
50#include <sys/socket.h>
51#include <sys/file.h>
52
53#include <netinet/in.h>
54
55#include <arpa/inet.h>
56
57#include <ctype.h>
54#include <sys/types.h>
55#include <sys/socket.h>
56#include <sys/file.h>
57
58#include <netinet/in.h>
59
60#include <arpa/inet.h>
61
62#include <ctype.h>
58#include <errno.h>
63#include <err.h>
59#include <netdb.h>
60#include <setjmp.h>
61#include <signal.h>
62#include <stdio.h>
63#include <stdlib.h>
64#include <string.h>
65#include <unistd.h>
66

--- 73 unchanged lines hidden (view full) ---

140 { "rexmt", xhelp, setrexmt },
141 { "timeout", ihelp, settimeout },
142 { "?", hhelp, help },
143 { 0 }
144};
145
146struct cmd *getcmd();
147char *tail();
64#include <netdb.h>
65#include <setjmp.h>
66#include <signal.h>
67#include <stdio.h>
68#include <stdlib.h>
69#include <string.h>
70#include <unistd.h>
71

--- 73 unchanged lines hidden (view full) ---

145 { "rexmt", xhelp, setrexmt },
146 { "timeout", ihelp, settimeout },
147 { "?", hhelp, help },
148 { 0 }
149};
150
151struct cmd *getcmd();
152char *tail();
148char *index();
149char *rindex();
150
151int
152main(argc, argv)
153 int argc;
154 char *argv[];
155{
156 struct sockaddr_in sin;
157
158 sp = getservbyname("tftp", "udp");
153
154int
155main(argc, argv)
156 int argc;
157 char *argv[];
158{
159 struct sockaddr_in sin;
160
161 sp = getservbyname("tftp", "udp");
159 if (sp == 0) {
160 fprintf(stderr, "tftp: udp/tftp: unknown service\n");
161 exit(1);
162 }
162 if (sp == 0)
163 errx(1, "udp/tftp: unknown service");
163 f = socket(AF_INET, SOCK_DGRAM, 0);
164 f = socket(AF_INET, SOCK_DGRAM, 0);
164 if (f < 0) {
165 perror("tftp: socket");
166 exit(3);
167 }
165 if (f < 0)
166 err(3, "socket");
168 bzero((char *)&sin, sizeof(sin));
169 sin.sin_family = AF_INET;
167 bzero((char *)&sin, sizeof(sin));
168 sin.sin_family = AF_INET;
170 if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
171 perror("tftp: bind");
172 exit(1);
173 }
169 if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0)
170 err(1, "bind");
174 strcpy(mode, "netascii");
175 signal(SIGINT, intr);
176 if (argc > 1) {
177 if (setjmp(toplevel) != 0)
178 exit(0);
179 setpeer(argc, argv);
180 }
181 if (setjmp(toplevel) != 0)
182 (void)putchar('\n');
183 command();
184}
185
171 strcpy(mode, "netascii");
172 signal(SIGINT, intr);
173 if (argc > 1) {
174 if (setjmp(toplevel) != 0)
175 exit(0);
176 setpeer(argc, argv);
177 }
178 if (setjmp(toplevel) != 0)
179 (void)putchar('\n');
180 command();
181}
182
186char hostname[100];
183char hostname[MAXHOSTNAMELEN];
187
188void
189setpeer(argc, argv)
190 int argc;
191 char *argv[];
192{
193 struct hostent *host;
194

--- 164 unchanged lines hidden (view full) ---

359 if (!connected) {
360 printf("No target machine specified.\n");
361 return;
362 }
363 if (argc < 4) {
364 cp = argc == 2 ? tail(targ) : argv[1];
365 fd = open(cp, O_RDONLY);
366 if (fd < 0) {
184
185void
186setpeer(argc, argv)
187 int argc;
188 char *argv[];
189{
190 struct hostent *host;
191

--- 164 unchanged lines hidden (view full) ---

356 if (!connected) {
357 printf("No target machine specified.\n");
358 return;
359 }
360 if (argc < 4) {
361 cp = argc == 2 ? tail(targ) : argv[1];
362 fd = open(cp, O_RDONLY);
363 if (fd < 0) {
367 fprintf(stderr, "tftp: "); perror(cp);
364 warn("%s", cp);
368 return;
369 }
370 if (verbose)
371 printf("putting %s to %s:%s [%s]\n",
372 cp, hostname, targ, mode);
373 peeraddr.sin_port = port;
374 sendfile(fd, targ, mode);
375 return;
376 }
377 /* this assumes the target is a directory */
378 /* on a remote unix system. hmmmm. */
379 cp = index(targ, '\0');
380 *cp++ = '/';
381 for (n = 1; n < argc - 1; n++) {
382 strcpy(cp, tail(argv[n]));
383 fd = open(argv[n], O_RDONLY);
384 if (fd < 0) {
365 return;
366 }
367 if (verbose)
368 printf("putting %s to %s:%s [%s]\n",
369 cp, hostname, targ, mode);
370 peeraddr.sin_port = port;
371 sendfile(fd, targ, mode);
372 return;
373 }
374 /* this assumes the target is a directory */
375 /* on a remote unix system. hmmmm. */
376 cp = index(targ, '\0');
377 *cp++ = '/';
378 for (n = 1; n < argc - 1; n++) {
379 strcpy(cp, tail(argv[n]));
380 fd = open(argv[n], O_RDONLY);
381 if (fd < 0) {
385 fprintf(stderr, "tftp: "); perror(argv[n]);
382 warn("%s", argv[n]);
386 continue;
387 }
388 if (verbose)
389 printf("putting %s to %s:%s [%s]\n",
390 argv[n], hostname, targ, mode);
391 peeraddr.sin_port = port;
392 sendfile(fd, targ, mode);
393 }

--- 58 unchanged lines hidden (view full) ---

452 peeraddr.sin_family = hp->h_addrtype;
453 connected = 1;
454 strcpy(hostname, hp->h_name);
455 }
456 if (argc < 4) {
457 cp = argc == 3 ? argv[2] : tail(src);
458 fd = creat(cp, 0644);
459 if (fd < 0) {
383 continue;
384 }
385 if (verbose)
386 printf("putting %s to %s:%s [%s]\n",
387 argv[n], hostname, targ, mode);
388 peeraddr.sin_port = port;
389 sendfile(fd, targ, mode);
390 }

--- 58 unchanged lines hidden (view full) ---

449 peeraddr.sin_family = hp->h_addrtype;
450 connected = 1;
451 strcpy(hostname, hp->h_name);
452 }
453 if (argc < 4) {
454 cp = argc == 3 ? argv[2] : tail(src);
455 fd = creat(cp, 0644);
456 if (fd < 0) {
460 fprintf(stderr, "tftp: "); perror(cp);
457 warn("%s", cp);
461 return;
462 }
463 if (verbose)
464 printf("getting from %s:%s to %s [%s]\n",
465 hostname, src, cp, mode);
466 peeraddr.sin_port = port;
467 recvfile(fd, src, mode);
468 break;
469 }
470 cp = tail(src); /* new .. jdg */
471 fd = creat(cp, 0644);
472 if (fd < 0) {
458 return;
459 }
460 if (verbose)
461 printf("getting from %s:%s to %s [%s]\n",
462 hostname, src, cp, mode);
463 peeraddr.sin_port = port;
464 recvfile(fd, src, mode);
465 break;
466 }
467 cp = tail(src); /* new .. jdg */
468 fd = creat(cp, 0644);
469 if (fd < 0) {
473 fprintf(stderr, "tftp: "); perror(cp);
470 warn("%s", cp);
474 continue;
475 }
476 if (verbose)
477 printf("getting from %s:%s to %s [%s]\n",
478 hostname, src, cp, mode);
479 peeraddr.sin_port = port;
480 recvfile(fd, src, mode);
481 }

--- 257 unchanged lines hidden ---
471 continue;
472 }
473 if (verbose)
474 printf("getting from %s:%s to %s [%s]\n",
475 hostname, src, cp, mode);
476 peeraddr.sin_port = port;
477 recvfile(fd, src, mode);
478 }

--- 257 unchanged lines hidden ---