- alarm(0);
- if (trace)
- tpacket("received", tp, n);
- /* should verify client address */
-#if vax || pdp11
- tp->th_opcode = ntohs(tp->th_opcode);
- tp->th_block = ntohs(tp->th_block);
-#endif
- if (tp->th_opcode == ERROR) {
- printf("Error code %d: %s\n", tp->th_code,
- tp->th_msg);
- break;
+ write_behind(file, convert);
+ for ( ; ; ) {
+ alarm(rexmtval);
+ do {
+ fromlen = sizeof (from);
+ n = recvfrom(f, dp, PKTSIZE, 0,
+ (caddr_t)&from, &fromlen);
+ } while (n <= 0);
+ alarm(0);
+ if (n < 0) {
+ perror("tftp: recvfrom");
+ goto abort;
+ }
+ sin.sin_port = from.sin_port; /* added */
+ if (trace)
+ tpacket("received", dp, n);
+ /* should verify client address */
+ dp->th_opcode = ntohs(dp->th_opcode);
+ dp->th_block = ntohs(dp->th_block);
+ if (dp->th_opcode == ERROR) {
+ printf("Error code %d: %s\n", dp->th_code,
+ dp->th_msg);
+ goto abort;
+ }
+ if (dp->th_opcode == DATA) {
+ int j;
+
+ if (dp->th_block == block) {
+ break; /* have next packet */
+ }
+ /* On an error, try to synchronize
+ * both sides.
+ */
+ j = synchnet(f);
+ if (j && trace) {
+ printf("discarded %d packets\n", j);
+ }
+ if (dp->th_block == (block-1)) {
+ goto send_ack; /* resend ack */
+ }
+ }