fix: packet receive issues

This commit is contained in:
ngn
2024-08-08 15:38:26 +03:00
parent 65a9d7610b
commit 7e7cd68a1e
5 changed files with 48 additions and 44 deletions

View File

@ -80,28 +80,13 @@ bool lm_mptp_server_recv(int sock, lm_mptp_t *packet) {
return false;
}
char buffer[sizeof(packet->header) + MPTP_HOST_MAX + MPTP_DATA_MAX];
ssize_t total = sizeof(buffer), used = 0;
bzero(buffer, sizeof(buffer));
bzero(packet, sizeof(lm_mptp_t));
if (recv(sock, buffer, sizeof(buffer), 0) <= 0) {
lm_error_set(LM_ERR_MPTPRecvFail);
return false;
if(!lm_mptp_recv(sock, packet)){
pdebug(__func__, "failed to receive the packet: %s", lm_strerror());
return false; // error set by function
}
copy_from_buffer(&packet->header, buffer, sizeof(packet->header), &total, &used);
packet->header.flags = ntohs(packet->header.flags);
// packet->header.host_size = ntohs(packet->header.host_size);
// packet->header.data_size = ntohs(packet->header.data_size);
if (packet->header.host_size <= MPTP_HOST_MAX)
copy_from_buffer(&packet->host, buffer, packet->header.host_size, &total, &used);
if (packet->header.data_size <= MPTP_DATA_MAX)
copy_from_buffer(&packet->data, buffer, packet->header.data_size, &total, &used);
return true;
}