+ // Reset the receive buffer for the first fragment
+ if(!hdr->wnd) {
+ buffer_clear(&c->rcvbuf);
+ }
+
+ ssize_t rxd = buffer_put_at(&c->rcvbuf, hdr->wnd, data, len);
+
+ if(rxd != (ssize_t)len) {
+ return;
+ }
+
+ // Send the packet if it's the final fragment
+ if(!(hdr->ctl & MF)) {
+ buffer_call(&c->rcvbuf, c->recv, c, 0, hdr->wnd + len);
+ }
+
+ c->rcv.nxt = hdr->seq + len;
+}
+
+static void handle_incoming_data(struct utcp_connection *c, const struct hdr *hdr, const void *data, size_t len) {
+ if(!is_reliable(c)) {
+ handle_unreliable(c, hdr, data, len);
+ return;
+ }
+
+ uint32_t offset = seqdiff(hdr->seq, c->rcv.nxt);
+