Skip to content

Commit

Permalink
IEEE C37.118: use new fast CRC-16/CCITT-FALSE implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xA50C1A1 committed Dec 5, 2023
1 parent 9ab52a0 commit ae59369
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/lib/protocols/ieee-c37118.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
#include "ndpi_api.h"
#include "ndpi_private.h"

static u_int16_t crc16(const u_int8_t* data, size_t n_bytes)
{
u_int16_t crc = 0xFFFF;

while (n_bytes--) {
crc ^= *data++ << 8;
for (u_int8_t i = 0; i < 8; i++) {
crc = crc & 0x8000 ? (crc << 1) ^ 0x1021 : crc << 1;
}
}

return crc & 0xFFFF;
}

static void ndpi_int_ieee_c37118_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
Expand All @@ -70,7 +56,7 @@ static void ndpi_search_ieee_c37118(struct ndpi_detection_module_struct *ndpi_st
u_int16_t crc = ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len-2));

if ((frame_size == packet->payload_packet_len) &&
(crc == crc16(packet->payload, packet->payload_packet_len-2)))
(crc == ndpi_crc16_ccit_false(packet->payload, packet->payload_packet_len-2)))
{
ndpi_int_ieee_c37118_add_connection(ndpi_struct, flow);
return;
Expand Down

0 comments on commit ae59369

Please sign in to comment.