Skip to content

Commit

Permalink
The 'parse packet' function code formating updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-scherba committed Aug 23, 2019
1 parent cd97678 commit 474b8f6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,20 +576,20 @@ int ksnCoreParsePacket(void *packet, size_t packet_len, ksnCorePacketData *rd) {
rd->raw_data = packet;
rd->raw_data_len = packet_len;

rd->from_len = *((uint8_t*)packet); ptr += sizeof(rd->from_len); // From length
if(rd->from_len &&
rd->from_len + PACKET_HEADER_ADD_SIZE <= packet_len &&
*((char*)(packet + ptr + rd->from_len - 1)) == '\0'
) {
rd->from = (char*)(packet + ptr); ptr += rd->from_len; // From pointer
if(strlen(rd->from) + 1 == rd->from_len) {

rd->cmd = *((uint8_t*)(packet + ptr)); ptr += sizeof(rd->cmd); // Command ID
rd->data = packet + ptr; // Data pointer
rd->data_len = packet_len - ptr; // Data length

packed_valid = 1;
}
rd->from_len = *((uint8_t *)packet); ptr += sizeof(rd->from_len); // From length
if (rd->from_len &&
rd->from_len + PACKET_HEADER_ADD_SIZE <= packet_len &&
*((char *)(packet + ptr + rd->from_len - 1)) == '\0'
) {
rd->from = (char *)(packet + ptr); ptr += rd->from_len; // From pointer
if(strlen(rd->from) + 1 == rd->from_len) {

rd->cmd = *((uint8_t *)(packet + ptr)); ptr += sizeof(rd->cmd); // Command ID
rd->data = packet + ptr; // Data pointer
rd->data_len = packet_len - ptr; // Data length

packed_valid = 1;
}
}

return packed_valid;
Expand Down

0 comments on commit 474b8f6

Please sign in to comment.