aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorLuca <deri@ntop.org>2017-04-18 17:20:43 +0200
committerLuca <deri@ntop.org>2017-04-18 17:20:43 +0200
commitc1db9a830d84281c146d9628c10620d7425ee009 (patch)
tree8999c42ee8247214f58fec7b2e2219d02212c296 /example
parent4c5de9ef8e9e14289ce9024349390fe06b59c769 (diff)
Compilation fix for old compilers
Diffstat (limited to 'example')
-rw-r--r--example/ndpi_util.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/example/ndpi_util.c b/example/ndpi_util.c
index cd3c8a1e3..783f05c86 100644
--- a/example/ndpi_util.c
+++ b/example/ndpi_util.c
@@ -915,7 +915,9 @@ struct ndpi_proto ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
/* ********************************************************** */
static uint32_t crc32_for_byte(uint32_t r) {
- for(int j = 0; j < 8; ++j)
+ int j;
+
+ for(j = 0; j < 8; ++j)
r = (r & 1? 0: (uint32_t)0xEDB88320L) ^ r >> 1;
return r ^ (uint32_t)0xFF000000L;
}
@@ -926,11 +928,13 @@ static uint32_t crc32_for_byte(uint32_t r) {
typedef unsigned long accum_t;
static void init_tables(uint32_t* table, uint32_t* wtable) {
- for(size_t i = 0; i < 0x100; ++i)
+ size_t i, k, w, j;
+
+ for(i = 0; i < 0x100; ++i)
table[i] = crc32_for_byte(i);
- for(size_t k = 0; k < sizeof(accum_t); ++k)
- for(size_t w, i = 0; i < 0x100; ++i) {
- for(size_t j = w = 0; j < sizeof(accum_t); ++j)
+ for(k = 0; k < sizeof(accum_t); ++k)
+ for(i = 0; i < 0x100; ++i) {
+ for(j = w = 0; j < sizeof(accum_t); ++j)
w = table[(uint8_t)(j == k? w ^ i: w)] ^ w >> 8;
wtable[(k << 8) + i] = w ^ (k? wtable[0]: 0);
}
@@ -939,13 +943,16 @@ static void init_tables(uint32_t* table, uint32_t* wtable) {
void ethernet_crc32(const void* data, size_t n_bytes, uint32_t* crc) {
static uint32_t table[0x100], wtable[0x100*sizeof(accum_t)];
size_t n_accum = n_bytes/sizeof(accum_t);
+ size_t i, k, j;
+
if(!*table)
init_tables(table, wtable);
- for(size_t i = 0; i < n_accum; ++i) {
+ for(i = 0; i < n_accum; ++i) {
accum_t a = *crc ^ ((accum_t*)data)[i];
- for(size_t j = *crc = 0; j < sizeof(accum_t); ++j)
+ for(j = *crc = 0; j < sizeof(accum_t); ++j)
*crc ^= wtable[(j << 8) + (uint8_t)(a >> 8*j)];
}
- for(size_t i = n_accum*sizeof(accum_t); i < n_bytes; ++i)
+
+ for(i = n_accum*sizeof(accum_t); i < n_bytes; ++i)
*crc = table[(uint8_t)*crc ^ ((uint8_t*)data)[i]] ^ *crc >> 8;
}