SCCS-vsn: libexec/tftpd/tftpd.c 5.4
#endif not lint
#ifndef lint
#endif not lint
#ifndef lint
-static char sccsid[] = "@(#)tftpd.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)tftpd.c 5.4 (Berkeley) %G%";
timeout = 0;
(void) setjmp(timeoutbuf);
timeout = 0;
(void) setjmp(timeoutbuf);
+send_data:
+ /* Now, we flush anything pending to be read */
+ /* This is to try to keep in synch between the two sides */
+ while (1) {
+ int i;
+ char rbuf[PKTSIZE];
+
+ (void) ioctl(peer, FIONREAD, &i);
+ if (i) {
+ fromlen = sizeof from;
+ n = recvfrom(peer, rbuf, sizeof (rbuf), 0,
+ (caddr_t)&from, &fromlen);
+ } else {
+ break;
+ }
+ }
if (send(peer, dp, size + 4, 0) != size + 4) {
perror("tftpd: write");
goto abort;
}
read_ahead(file, pf->f_convert);
if (send(peer, dp, size + 4, 0) != size + 4) {
perror("tftpd: write");
goto abort;
}
read_ahead(file, pf->f_convert);
alarm(rexmtval); /* read the ack */
n = recv(peer, ackbuf, sizeof (ackbuf), 0);
alarm(0);
alarm(rexmtval); /* read the ack */
n = recv(peer, ackbuf, sizeof (ackbuf), 0);
alarm(0);
if (ap->th_opcode == ERROR)
goto abort;
if (ap->th_opcode == ERROR)
goto abort;
+
+ if (ap->th_opcode == ACK) {
+ if (ap->th_block == block) {
+ break;
+ }
+ if (ap->th_block == (block -1)) {
+ goto send_data;
+ }
+ }
- } while (ap->th_opcode != ACK || ap->th_block != block);
block++;
} while (size == SEGSIZE);
abort:
block++;
} while (size == SEGSIZE);
abort:
block++;
(void) setjmp(timeoutbuf);
send_ack:
block++;
(void) setjmp(timeoutbuf);
send_ack:
+ /* Now, we flush anything pending to be read */
+ /* This is to try to keep in synch between the two sides */
+ while (1) {
+ int i;
+ char rbuf[PKTSIZE];
+
+ (void) ioctl(peer, FIONREAD, &i);
+ if (i) {
+ fromlen = sizeof from;
+ n = recvfrom(peer, rbuf, sizeof (rbuf), 0,
+ (caddr_t)&from, &fromlen);
+ } else {
+ break;
+ }
+ }
if (send(peer, ackbuf, 4, 0) != 4) {
perror("tftpd: write");
goto abort;
if (send(peer, ackbuf, 4, 0) != 4) {
perror("tftpd: write");
goto abort;