Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01005e00001600000000000108004500002000000000010200000a000001e0000016220000000000000101000001
18 changes: 6 additions & 12 deletions Tests/Packet++Test/Tests/IgmpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,12 @@ PTF_TEST_CASE(Igmpv3ParsingTest)
// Only the start of a record was checked against the layer, so a truncated one was returned
// and its fields were then read past the end of the buffer.
{
uint8_t truncated[] = { // Ethernet
0x01, 0x00, 0x5e, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
// IPv4, total length 32, protocol 2 (IGMP)
0x45, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x0a, 0x00,
0x00, 0x01, 0xe0, 0x00, 0x00, 0x16,
// IGMPv3 report: 8 byte header claiming one group record, then only 4 bytes of it
0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01
};

timeval truncatedTime = {};
pcpp::RawPacket truncatedRawPacket(truncated, sizeof(truncated), truncatedTime, false, pcpp::LINKTYPE_ETHERNET);
pcpp::Packet truncatedPacket(&truncatedRawPacket);
// Packet contents
// Ethernet
// IPv4, total length 32, protocol 2 (IGMP)
// IGMPv3 report: 8 byte header claiming one group record, then only 4 bytes of it
auto truncatedRawPacket = createPacketFromHexResource("PacketExamples/igmpv3_report_truncated.dat");
pcpp::Packet truncatedPacket(truncatedRawPacket.get());

auto truncatedReportLayer = truncatedPacket.getLayerOfType<pcpp::IgmpV3ReportLayer>();
PTF_ASSERT_NOT_NULL(truncatedReportLayer);
Expand Down
2 changes: 1 addition & 1 deletion Tests/PcppTestUtilities/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace pcpp_tests
}

void ResourceProvider::saveResource(ResourceType resourceType, const char* filename, const uint8_t* data,
size_t length) const
size_t length)
{
if (m_Frozen)
{
Expand Down
15 changes: 13 additions & 2 deletions Tests/PcppTestUtilities/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ namespace pcpp_tests
/// @param frozen If true, the provider is read-only and does not allow saving resources.
explicit ResourceProvider(std::string dataRoot, bool frozen = true);

/// @brief Freezes the provider, preventing any modifications or saving of resources.
void freeze()
{
m_Frozen = true;
}

/// @brief Allows the provider to be modified, enabling saving of resources.
void unfreeze()
{
m_Frozen = false;
}

/// @brief Loads a resource from resource provider.
/// @param filename The name of the resource file to load.
/// @param resourceType The type of the loaded resource. Determines how the resource is processed.
Expand All @@ -50,8 +62,7 @@ namespace pcpp_tests
/// @param data Pointer to the data to be saved.
/// @param length The length of the data in bytes.
/// @throw std::runtime_error if the provider is frozen and does not allow saving.
void saveResource(ResourceType resourceType, const char* filename, const uint8_t* data,
size_t length) const;
void saveResource(ResourceType resourceType, const char* filename, const uint8_t* data, size_t length);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stripped the const since it conceptually mutates the resource store.


private:
std::string m_DataRoot; ///< The root directory for test data files
Expand Down
Loading