tftp.c (9b50d9027575220cb6dd09b3e62f03f511e908b8) | tftp.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 |
35#if 0 |
|
35static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; | 36static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; |
37#endif 38static const char rcsid[] = 39 "$Id$"; |
|
36#endif /* not lint */ 37 38/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */ 39 40/* 41 * TFTP User Program -- Protocol Machines 42 */ 43#include <sys/types.h> 44#include <sys/socket.h> 45#include <sys/time.h> 46 47#include <netinet/in.h> 48 49#include <arpa/tftp.h> 50 | 40#endif /* not lint */ 41 42/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */ 43 44/* 45 * TFTP User Program -- Protocol Machines 46 */ 47#include <sys/types.h> 48#include <sys/socket.h> 49#include <sys/time.h> 50 51#include <netinet/in.h> 52 53#include <arpa/tftp.h> 54 |
55#include <err.h> |
|
51#include <errno.h> 52#include <setjmp.h> 53#include <signal.h> 54#include <stdio.h> 55#include <unistd.h> 56 57#include "extern.h" 58#include "tftpsubs.h" 59 | 56#include <errno.h> 57#include <setjmp.h> 58#include <signal.h> 59#include <stdio.h> 60#include <unistd.h> 61 62#include "extern.h" 63#include "tftpsubs.h" 64 |
60extern int errno; 61 | |
62extern struct sockaddr_in peeraddr; /* filled in by main */ 63extern int f; /* the opened socket */ 64extern int trace; 65extern int verbose; 66extern int rexmtval; 67extern int maxtimeout; 68 69#define PKTSIZE SEGSIZE+4 --- 53 unchanged lines hidden (view full) --- 123 timeout = 0; 124 (void) setjmp(timeoutbuf); 125send_data: 126 if (trace) 127 tpacket("sent", dp, size + 4); 128 n = sendto(f, dp, size + 4, 0, 129 (struct sockaddr *)&peeraddr, sizeof(peeraddr)); 130 if (n != size + 4) { | 65extern struct sockaddr_in peeraddr; /* filled in by main */ 66extern int f; /* the opened socket */ 67extern int trace; 68extern int verbose; 69extern int rexmtval; 70extern int maxtimeout; 71 72#define PKTSIZE SEGSIZE+4 --- 53 unchanged lines hidden (view full) --- 126 timeout = 0; 127 (void) setjmp(timeoutbuf); 128send_data: 129 if (trace) 130 tpacket("sent", dp, size + 4); 131 n = sendto(f, dp, size + 4, 0, 132 (struct sockaddr *)&peeraddr, sizeof(peeraddr)); 133 if (n != size + 4) { |
131 perror("tftp: sendto"); | 134 warn("sendto"); |
132 goto abort; 133 } 134 read_ahead(file, convert); 135 for ( ; ; ) { 136 alarm(rexmtval); 137 do { 138 fromlen = sizeof(from); 139 n = recvfrom(f, ackbuf, sizeof(ackbuf), 0, 140 (struct sockaddr *)&from, &fromlen); 141 } while (n <= 0); 142 alarm(0); 143 if (n < 0) { | 135 goto abort; 136 } 137 read_ahead(file, convert); 138 for ( ; ; ) { 139 alarm(rexmtval); 140 do { 141 fromlen = sizeof(from); 142 n = recvfrom(f, ackbuf, sizeof(ackbuf), 0, 143 (struct sockaddr *)&from, &fromlen); 144 } while (n <= 0); 145 alarm(0); 146 if (n < 0) { |
144 perror("tftp: recvfrom"); | 147 warn("recvfrom"); |
145 goto abort; 146 } 147 peeraddr.sin_port = from.sin_port; /* added */ 148 if (trace) 149 tpacket("received", ap, n); 150 /* should verify packet came from server */ 151 ap->th_opcode = ntohs(ap->th_opcode); 152 ap->th_block = ntohs(ap->th_block); --- 74 unchanged lines hidden (view full) --- 227 timeout = 0; 228 (void) setjmp(timeoutbuf); 229send_ack: 230 if (trace) 231 tpacket("sent", ap, size); 232 if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peeraddr, 233 sizeof(peeraddr)) != size) { 234 alarm(0); | 148 goto abort; 149 } 150 peeraddr.sin_port = from.sin_port; /* added */ 151 if (trace) 152 tpacket("received", ap, n); 153 /* should verify packet came from server */ 154 ap->th_opcode = ntohs(ap->th_opcode); 155 ap->th_block = ntohs(ap->th_block); --- 74 unchanged lines hidden (view full) --- 230 timeout = 0; 231 (void) setjmp(timeoutbuf); 232send_ack: 233 if (trace) 234 tpacket("sent", ap, size); 235 if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peeraddr, 236 sizeof(peeraddr)) != size) { 237 alarm(0); |
235 perror("tftp: sendto"); | 238 warn("sendto"); |
236 goto abort; 237 } 238 write_behind(file, convert); 239 for ( ; ; ) { 240 alarm(rexmtval); 241 do { 242 fromlen = sizeof(from); 243 n = recvfrom(f, dp, PKTSIZE, 0, 244 (struct sockaddr *)&from, &fromlen); 245 } while (n <= 0); 246 alarm(0); 247 if (n < 0) { | 239 goto abort; 240 } 241 write_behind(file, convert); 242 for ( ; ; ) { 243 alarm(rexmtval); 244 do { 245 fromlen = sizeof(from); 246 n = recvfrom(f, dp, PKTSIZE, 0, 247 (struct sockaddr *)&from, &fromlen); 248 } while (n <= 0); 249 alarm(0); 250 if (n < 0) { |
248 perror("tftp: recvfrom"); | 251 warn("recvfrom"); |
249 goto abort; 250 } 251 peeraddr.sin_port = from.sin_port; /* added */ 252 if (trace) 253 tpacket("received", dp, n); 254 /* should verify client address */ 255 dp->th_opcode = ntohs(dp->th_opcode); 256 dp->th_block = ntohs(dp->th_block); --- 101 unchanged lines hidden (view full) --- 358 tp->th_code = EUNDEF; 359 } 360 strcpy(tp->th_msg, pe->e_msg); 361 length = strlen(pe->e_msg) + 4; 362 if (trace) 363 tpacket("sent", tp, length); 364 if (sendto(f, ackbuf, length, 0, (struct sockaddr *)&peeraddr, 365 sizeof(peeraddr)) != length) | 252 goto abort; 253 } 254 peeraddr.sin_port = from.sin_port; /* added */ 255 if (trace) 256 tpacket("received", dp, n); 257 /* should verify client address */ 258 dp->th_opcode = ntohs(dp->th_opcode); 259 dp->th_block = ntohs(dp->th_block); --- 101 unchanged lines hidden (view full) --- 361 tp->th_code = EUNDEF; 362 } 363 strcpy(tp->th_msg, pe->e_msg); 364 length = strlen(pe->e_msg) + 4; 365 if (trace) 366 tpacket("sent", tp, length); 367 if (sendto(f, ackbuf, length, 0, (struct sockaddr *)&peeraddr, 368 sizeof(peeraddr)) != length) |
366 perror("nak"); | 369 warn("nak"); |
367} 368 369static void 370tpacket(s, tp, n) 371 const char *s; 372 struct tftphdr *tp; 373 int n; 374{ --- 79 unchanged lines hidden --- | 370} 371 372static void 373tpacket(s, tp, n) 374 const char *s; 375 struct tftphdr *tp; 376 int n; 377{ --- 79 unchanged lines hidden --- |