Skip to content

Commit

Permalink
Fixed endian issue while DEBUG_PROTOBUF is enabled. (#2112)
Browse files Browse the repository at this point in the history
Signed-off-by: Toni Uhlig <[email protected]>
  • Loading branch information
utoni authored Oct 25, 2023
1 parent 4a8e710 commit 9509cd5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/lib/protocols/protobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ static void ndpi_search_protobuf(struct ndpi_detection_module_struct *ndpi_struc
return;
}
#ifdef DEBUG_PROTOBUF
printf("[VARINT: %llu]", (unsigned long long int)value);
printf("[VARINT: %llu / %llx]", (unsigned long long int)value,
(unsigned long long int)value);
#endif
break;
}
Expand All @@ -187,8 +188,14 @@ static void ndpi_search_protobuf(struct ndpi_detection_module_struct *ndpi_struc
return;
}
#ifdef DEBUG_PROTOBUF
uint64_t value = ndpi_ntohll(*(uint64_t *)&packet->payload[offset]);
printf("[I64: %llu]", (unsigned long long int)value);
union {
int64_t as_i64;
uint64_t as_u64;
double as_double;
} value;
value.as_u64 = le64toh(*(uint64_t *)&packet->payload[offset]);
printf("[I64: %lld / %llu / %lf]", (long long int)value.as_i64,
(unsigned long long int)value.as_u64, value.as_double);
#endif
offset += 8;
break;
Expand Down Expand Up @@ -227,8 +234,13 @@ static void ndpi_search_protobuf(struct ndpi_detection_module_struct *ndpi_struc
break;
}
#ifdef DEBUG_PROTOBUF
uint32_t value = ntohl(*(uint32_t *)&packet->payload[offset]);
printf("[I32: %u]", value);
union {
int32_t as_i32;
uint32_t as_u32;
float as_float;
} value;
value.as_u32 = le32toh(*(uint32_t *)&packet->payload[offset]);
printf("[I32: %d / %u / %f]", value.as_i32, value.as_u32, value.as_float);
#endif
offset += 4;
break;
Expand Down

0 comments on commit 9509cd5

Please sign in to comment.