ssize_t do_recv(struct utcp_connection *x, const void *data, size_t len) {
if(!len) {
if(errno) {
- fprintf(stderr, "%p Error: %s\n", x->utcp, strerror(errno));
+ fprintf(stderr, "%p Error: %s\n", (void *)x->utcp, strerror(errno));
} else {
- fprintf(stderr, "%p Connection closed by peer\n", x->utcp);
+ fprintf(stderr, "%p Connection closed by peer\n", (void *)x->utcp);
}
if(x != c) {
ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) {
+ const uint8_t *ptr = data;
+
if(!utcp) {
errno = EFAULT;
return -1;
// Make a copy from the potentially unaligned data to a struct hdr
- memcpy(&hdr, data, sizeof(hdr));
- data += sizeof(hdr);
+ memcpy(&hdr, ptr, sizeof(hdr));
+ ptr += sizeof(hdr);
len -= sizeof(hdr);
// Drop packets with an unknown CTL flag
return -1;
}
- init = data;
+ init = ptr;
break;
default:
}
len -= auxlen;
- data += auxlen;
+ ptr += auxlen;
if(!(aux & 0x800)) {
break;
return -1;
}
- memcpy(&aux, data, 2);
+ memcpy(&aux, ptr, 2);
len -= 2;
- data += 2;
+ ptr += 2;
}
// Try to match the packet to an existing connection
acceptable = len > (size_t) - rcv_offset;
if(acceptable) {
- data -= rcv_offset;
+ ptr -= rcv_offset;
len += rcv_offset;
hdr.seq -= rcv_offset;
}
}
}
+ uint32_t advanced;
+
if(!(hdr.ctl & ACK)) {
+ advanced = 0;
goto skip_ack;
}
// 3. Advance snd.una
- uint32_t advanced = seqdiff(hdr.ack, c->snd.una);
+ advanced = seqdiff(hdr.ack, c->snd.una);
prevrcvnxt = c->rcv.nxt;
if(advanced) {
return 0;
}
- handle_incoming_data(c, hdr.seq, data, len);
+ handle_incoming_data(c, hdr.seq, ptr, len);
}
// 7. Process FIN stuff