mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
handle larger sequence number and message length correctly with ntoh()
This commit is contained in:
parent
83e03070a5
commit
ed05263795
1 changed files with 13 additions and 8 deletions
|
@ -178,6 +178,7 @@ int socket_read(struct node *n, struct msg *pool, int poolsize, int first, int c
|
|||
|
||||
/* Wait until next packet received */
|
||||
poll(&(struct pollfd) { .fd = s->sd, .events = POLLIN }, 1, -1);
|
||||
|
||||
/* Get size of received packet in bytes */
|
||||
ioctl(s->sd, FIONREAD, &bytes);
|
||||
|
||||
|
@ -203,17 +204,21 @@ int socket_read(struct node *n, struct msg *pool, int poolsize, int first, int c
|
|||
debug(10, "Received packet of %u bytes: %u samples a %u values per sample", bytes, cnt, (bytes / cnt) / 4 - 4);
|
||||
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
struct msg *n = &pool[(first+poolsize+i) % poolsize];
|
||||
|
||||
/* Check integrity of packet */
|
||||
bytes -= MSG_LEN(n);
|
||||
struct msg *m = &pool[(first+poolsize+i) % poolsize];
|
||||
|
||||
/* Convert headers to host byte order */
|
||||
n->sequence = ntohs(n->sequence);
|
||||
m->sequence = ntohl(m->sequence);
|
||||
m->length = ntohs(m->length);
|
||||
|
||||
/* Check integrity of packet */
|
||||
if (bytes / cnt != MSG_LEN(m))
|
||||
error("Invalid message len: %u for node '%s'", MSG_LEN(m), n->name);
|
||||
|
||||
bytes -= MSG_LEN(m);
|
||||
|
||||
/* Convert message to host endianess */
|
||||
if (n->endian != MSG_ENDIAN_HOST)
|
||||
msg_swap(n);
|
||||
if (m->endian != MSG_ENDIAN_HOST)
|
||||
msg_swap(m);
|
||||
}
|
||||
|
||||
/* Check packet integrity */
|
||||
|
@ -456,4 +461,4 @@ int socket_parse_addr(const char *addr, struct sockaddr *saddr, enum socket_laye
|
|||
return ret;
|
||||
}
|
||||
|
||||
REGISTER_NODE_TYPE(BSD_SOCKET, "socket", socket)
|
||||
REGISTER_NODE_TYPE(BSD_SOCKET, "socket", socket)
|
||||
|
|
Loading…
Add table
Reference in a new issue