Skip to content

Commit

Permalink
Fixes poc_assign from seladb#1129
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura committed Aug 9, 2023
1 parent 5666e28 commit 1471520
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions Packet++/header/NflogLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,22 @@ namespace pcpp
/**
* @return recordLen attribute in NflogTLVRawData
*/
size_t getTotalSize() const { return m_Data->recordLen; }
size_t getTotalSize() const
{
// as in https://github.com/the-tcpdump-group/libpcap/blob/766b607d60d8038087b49fc4cf433dac3dcdb49c/pcap-util.c#L371-L374
uint16_t size = m_Data->recordLen;
if (size % 4 != 0)
size += 4 - size % 4;
return size;
}

/**
* Assign a pointer to the TLV record raw data (byte array)
* @param[in] recordRawData A pointer to the TLV record raw data
*/
void assign(uint8_t* recordRawData)
{
if(recordRawData == nullptr)
m_Data = nullptr;
else
{
// to pass from some unknown paddings after tlv with type NFULA_PREFIX
while (*recordRawData == 0)
recordRawData += 1;
m_Data = (NflogTLVRawData*)recordRawData;
}
m_Data = (NflogTLVRawData*)recordRawData;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Tests/Packet++Test/Tests/NflogTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ PTF_TEST_CASE(NflogPacketParsingTest)
pcpp::NflogTlvType::NFULA_PAYLOAD
};

int optSizes[6] = {8, 5, 8, 8, 8, 65};
int optSizes[6] = {8, 8, 8, 8, 8, 68};
std::string optDataAsHexString[6] = {
"0800010000000300",
"05000a0000",
"05000a0000000000",
"0800050000000002",
"08000b0000000000",
"08000e0000000000",
"410009004500003d021040004011208f0a00020f0a000203a542003500294156c04e0100000100000000000003777777076578616d706c65036e65740000010001"
"410009004500003d021040004011208f0a00020f0a000203a542003500294156c04e0100000100000000000003777777076578616d706c65036e657400000100012f0a31"
};

for (int i = 0; i < 6; i++) {
Expand All @@ -56,5 +56,5 @@ PTF_TEST_CASE(NflogPacketParsingTest)
}

/// sum of all TLVs before payload + size of nflog_header + size of (recordLength + recordType) variables of payload TLV
PTF_ASSERT_EQUAL(nflogLayer->getHeaderLen(), 45);
PTF_ASSERT_EQUAL(nflogLayer->getHeaderLen(), 48);
}

0 comments on commit 1471520

Please sign in to comment.