summaryrefslogtreecommitdiff
path: root/src/lib/frct_pci.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-08-22 17:38:44 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-08-22 17:38:44 +0200
commit743c2f69744fe3f0dac11e467a92ff5e4d80280b (patch)
tree5cd831f6a777d9be5d14e8aff1a66897d8163e19 /src/lib/frct_pci.c
parentfb771c0cf876ad58c50551b90dacc0b5689dae05 (diff)
downloadouroboros-743c2f69744fe3f0dac11e467a92ff5e4d80280b.tar.gz
ouroboros-743c2f69744fe3f0dac11e467a92ff5e4d80280b.zip
lib: Fix CRC check and add frct_clear
This adds the CRC check by default on outgoing SDUs. It fixes some errors in the serialization and deserialization of the SDU. frct_clear was added to avoid bad initialization of the array of FRCT instances.
Diffstat (limited to 'src/lib/frct_pci.c')
-rw-r--r--src/lib/frct_pci.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/lib/frct_pci.c b/src/lib/frct_pci.c
index 392e11c6..5ee14829 100644
--- a/src/lib/frct_pci.c
+++ b/src/lib/frct_pci.c
@@ -24,6 +24,9 @@
#include <ouroboros/hash.h>
#include <ouroboros/errno.h>
+#define OUROBOROS_PREFIX "frct-pci"
+#include <ouroboros/logs.h>
+
#include <assert.h>
#include <string.h>
@@ -73,6 +76,7 @@ int frct_pci_des(struct shm_du_buff * sdb,
uint8_t * head;
uint8_t * tail;
uint32_t crc;
+ uint32_t crc2;
assert(sdb);
assert(pci);
@@ -89,10 +93,14 @@ int frct_pci_des(struct shm_du_buff * sdb,
if (tail == NULL)
return -EPERM;
- mem_hash(HASH_CRC32, &crc, head, tail - head);
+ mem_hash(HASH_CRC32, &crc, head,
+ tail - head - hash_len(HASH_CRC32));
+
+ memcpy(&crc2, tail - hash_len(HASH_CRC32),
+ hash_len(HASH_CRC32));
/* Corrupted SDU */
- if (crc != 0)
+ if (crc != crc2)
return -1;
shm_du_buff_tail_release(sdb, hash_len(HASH_CRC32));