fprintf(stderr, "%p new state: %s\n", c->utcp, strstate[state]);
}
-static void print_packet(const void *pkt, size_t len) {
+static void print_packet(struct utcp *utcp, const char *dir, const void *pkt, size_t len) {
struct hdr hdr;
if(len < sizeof hdr) {
- fprintf(stderr, "short packet (%zu bytes)\n", len);
+ fprintf(stderr, "%p %s: short packet (%zu bytes)\n", utcp, dir, len);
return;
}
memcpy(&hdr, pkt, sizeof hdr);
- fprintf (stderr, "src=%u dst=%u seq=%u ack=%u wnd=%u ctl=", hdr.src, hdr.dst, hdr.seq, hdr.ack, hdr.wnd);
+ fprintf (stderr, "%p %s: src=%u dst=%u seq=%u ack=%u wnd=%u ctl=", utcp, dir, hdr.src, hdr.dst, hdr.seq, hdr.ack, hdr.wnd);
if(hdr.ctl & SYN)
fprintf(stderr, "SYN");
if(hdr.ctl & RST)
set_state(c, SYN_SENT);
+ print_packet(utcp, "send", &hdr, sizeof hdr);
utcp->send(utcp, &hdr, sizeof hdr);
gettimeofday(&c->conn_timeout, NULL);
data += seglen;
left -= seglen;
+ print_packet(c->utcp, "send", &pkt, sizeof pkt.hdr + seglen);
c->utcp->send(c->utcp, &pkt, sizeof pkt.hdr + seglen);
}
return -1;
}
- fprintf(stderr, "%p got: ", utcp);
- print_packet(data, len);
+ print_packet(utcp, "recv", data, len);
struct hdr hdr;
if(len < sizeof hdr) {
hdr.ack = c->rcv.irs + 1;
hdr.seq = c->snd.iss;
hdr.ctl = SYN | ACK;
+ print_packet(c->utcp, "send", &hdr, sizeof hdr);
utcp->send(utcp, &hdr, sizeof hdr);
return 0;
} else { // CLOSED
hdr.ack = c->rcv.nxt;
hdr.ctl = SYN | ACK;
}
+ print_packet(c->utcp, "send", &hdr, sizeof hdr);
utcp->send(utcp, &hdr, sizeof hdr);
// TODO: queue any data?
}
hdr.seq = 0;
hdr.ctl = RST | ACK;
}
+ print_packet(c->utcp, "send", &hdr, sizeof hdr);
utcp->send(utcp, &hdr, sizeof hdr);
return 0;
hdr.seq = c->snd.nxt;
hdr.ack = c->rcv.nxt;
hdr.ctl = ACK;
+ print_packet(c->utcp, "send", &hdr, sizeof hdr);
utcp->send(utcp, &hdr, sizeof hdr);
if(c->state == CLOSE_WAIT || c->state == TIME_WAIT) {
errno = 0;
c->snd.nxt += 1;
+ print_packet(c->utcp, "send", &hdr, sizeof hdr);
c->utcp->send(c->utcp, &hdr, sizeof hdr);
return 0;
}
hdr.wnd = 0;
hdr.ctl = RST;
+ print_packet(c->utcp, "send", &hdr, sizeof hdr);
c->utcp->send(c->utcp, &hdr, sizeof hdr);
return 0;
}
pkt.hdr.ack = 0;
pkt.hdr.wnd = c->rcv.wnd;
pkt.hdr.ctl = SYN;
+ print_packet(c->utcp, "rtrx", &pkt, sizeof pkt.hdr);
utcp->send(utcp, &pkt, sizeof pkt.hdr);
break;
pkt.hdr.seq = c->snd.nxt;
pkt.hdr.ack = c->rcv.nxt;
pkt.hdr.ctl = SYN | ACK;
+ print_packet(c->utcp, "rtrx", &pkt, sizeof pkt.hdr);
utcp->send(utcp, &pkt, sizeof pkt.hdr);
break;
if(len > utcp->mtu)
len = utcp->mtu;
memcpy(pkt.data, c->sndbuf, len);
+ print_packet(c->utcp, "rtrx", &pkt, sizeof pkt.hdr + len);
utcp->send(utcp, &pkt, sizeof pkt.hdr + len);
break;