- perror("receive");
- break;
- }
- alarm(0);
- if (trace)
- tpacket("received", tp, n);
- /* should verify packet came from server */
-#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;
- }
- if (tp->th_opcode != ACK || block != tp->th_block)
- goto again;
+ if (n < 0) {
+ perror("tftp: recvfrom");
+ aborted = 1;
+ goto done;
+ }
+ if (to.sin_addr.s_addr != from.sin_addr.s_addr) {
+ tpacket("discarded (wrong host)", &from, tp, n);
+ goto again;
+ }
+ if (to.sin_port = sin.sin_port)
+ to.sin_port = from.sin_port;
+ if (to.sin_port != from.sin_port) {
+ tpacket("discarded (wrong port)", &from, tp, n);
+ goto again;
+ }
+ if (trace)
+ tpacket("received", &from, tp, n);
+ /* should verify packet came from server */
+ tp->th_opcode = ntohs(tp->th_opcode);
+ tp->th_block = ntohs(tp->th_block);
+ if (tp->th_opcode == ERROR) {
+ printf("Error code %d: %s\n", tp->th_code,
+ tp->th_msg);
+ aborted = 1;
+ goto done;
+ }
+ } while (tp->th_opcode != ACK && block != tp->th_block);