- } else if (pkt_num(rx) != ACK) {
- fprintf(stderr, "Expected ACK(%d), got ", block);
- pkt_print(rx, stderr);
- fprintf(stderr, "!\n");
+ } else if (pkt_num(rx) != ACK || ackblock > block) {
+ if (verbosity) {
+ fprintf(stderr, "Expected ACK(%d), got ", block);
+ pkt_print(rx, stderr);
+ fprintf(stderr, ".\n");
+ }
+
+ if (ackblock != -1 && ++errors > 5) {
+ fprintf(stderr, "Protocol error; bailing out.\n");
+ ret = -1;
+ goto cleanup;
+ }