Skip to content

Commit

Permalink
Fix serval issues related to multi-cross platform
Browse files Browse the repository at this point in the history
  • Loading branch information
raissi-oussema committed Dec 9, 2024
1 parent 7966b06 commit d4658d7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Packet++/header/DoIpLayerData.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ namespace pcpp
* - `maxConcurrentSockets`: Set to `0`, meaning no concurrent sockets are allowed by default.
* - `currentlyOpenSockets`: Set to `0`, indicating no sockets are currently open.
* - `maxDataSize`: Set to `nullptr`, meaning no data for this field. can be assigned after object
* creation by :
*
* @code
* EntityStatusResponseData data;
* data.maxDataSize = std::unique_ptr<std::array<uint8_t, 4>>(new std::array<uint8_t, 4> {0x00, 0x01, 0x02,
Expand Down
9 changes: 7 additions & 2 deletions Packet++/src/DoIpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,20 @@ namespace pcpp
std::string DoIpLayer::toString() const
{
std::stringstream os;
if (!resolveLayer())
{
os << "Malformed doip Packet";
return os.str();
}
DoIpProtocolVersion version = getProtocolVersion();
DoIpPayloadTypes type = getPayloadType();
uint32_t length = getPayloadLength();

os << "DOIP Layer:" << std::endl;
os << "Protocol Version: " << DoIpEnumToStringProtocolVersion.at(version) << std::hex << " (0x"
<< unsigned((uint8_t)version) << ")" << std::endl;
os << "Payload Type: " << getPayloadTypeAsStr() << std::hex << " (0x" << htole16((uint16_t)type) << ")"
<< std::endl;
os << "Payload Type: " << getPayloadTypeAsStr() << std::hex << " (0x" << std::setw(4) << std::setfill('0')
<< (uint16_t)type << ")" << std::endl;
os << std::dec << "Payload Length: " << length << std::endl;

return os.str();
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/DoIpLayerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ namespace pcpp
std::string VehicleIdentificationRequestVINData::toString() const
{
std::stringstream os;
os << "VIN: " << std::string(vin.data(), vin.end()) << std::endl;
os << "VIN: " << std::string(reinterpret_cast<const char*>(vin.data()), vin.size()) << std::endl;
return os.str();
}
std::vector<uint8_t> VehicleIdentificationRequestVINData::getData() const
Expand Down
37 changes: 18 additions & 19 deletions Tests/Packet++Test/Tests/DoIpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PTF_TEST_CASE(DoIpGenericHeaderNackPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 1);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Generic DOIP header Nack (0x0)\nPayload Length: 1\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Generic DOIP header Nack (0x0000)\nPayload Length: 1\n")
}

PTF_TEST_CASE(DoIpGenericHeaderNackPacketCreation)
Expand Down Expand Up @@ -90,7 +90,7 @@ PTF_TEST_CASE(DoIpGenericHeaderNackPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 1);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Generic DOIP header Nack (0x0)\nPayload Length: 1\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Generic DOIP header Nack (0x0000)\nPayload Length: 1\n")
}
// DoIpVehicleIdentificationRequestPacketParsing
PTF_TEST_CASE(DoIpVehicleIdentificationRequestPacketParsing)
Expand Down Expand Up @@ -124,7 +124,7 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadTypeAsStr(), "Vehicle identification request");
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request (0x1)\nPayload Length: 0\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request (0x0001)\nPayload Length: 0\n")
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 0x0);

} // DoIpVehicleIdentificationRequestPacketParsing
Expand Down Expand Up @@ -161,7 +161,7 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadTypeAsStr(), "Vehicle identification request");
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request (0x1)\nPayload Length: 0\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request (0x0001)\nPayload Length: 0\n")
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 0x0);
}
// VehicleIdentificationWithVIN
Expand Down Expand Up @@ -195,7 +195,6 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestVINPacketParsing)
if (data.buildFromLayer(doipLayer))
// std::cout << data.toString();
PTF_ASSERT_EQUAL(data.toString(), "VIN: BAUNEE4MZ17042403\n");
// PTF_ASSERT_EQUAL(doipLayer->getProtocolVersion(), pcpp::DoIpProtocolVersion::version02Iso2012);
PTF_ASSERT_EQUAL(doipLayer->getProtocolVersion(), pcpp::DoIpProtocolVersion::version02Iso2012, enumclass);
PTF_ASSERT_EQUAL(doipLayer->getInvertProtocolVersion(), 0xFD);
PTF_ASSERT_EQUAL(doipLayer->getPayloadType(), pcpp::DoIpPayloadTypes::VEHICLE_IDENTIFICATION_REQUEST_WITH_VIN,
Expand All @@ -204,7 +203,7 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestVINPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 0x11);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with VIN (0x3)\nPayload Length: 17\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with VIN (0x0003)\nPayload Length: 17\n")

} // DoIpVehicleIdentificationRequestVINPacketParsing

Expand Down Expand Up @@ -248,7 +247,7 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestVINPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 17);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with VIN (0x3)\nPayload Length: 17\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with VIN (0x0003)\nPayload Length: 17\n")
}
// VehicleIdentificationWithEID
PTF_TEST_CASE(DoIpVehicleIdentificationRequestEIDPacketParsing)
Expand Down Expand Up @@ -289,7 +288,7 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestEIDPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 0x6);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with EID (0x2)\nPayload Length: 6\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with EID (0x0002)\nPayload Length: 6\n")

} // DoIpVehicleIdentificationRequestVINPacketParsing

Expand Down Expand Up @@ -335,7 +334,7 @@ PTF_TEST_CASE(DoIpVehicleIdentificationRequestEIDPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 6);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with EID (0x2)\nPayload Length: 6\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle identification request with EID (0x0002)\nPayload Length: 6\n")
}
// VehicleAnnouncement
PTF_TEST_CASE(DoIpVehicleAnnouncementPacketParsing)
Expand Down Expand Up @@ -379,7 +378,7 @@ PTF_TEST_CASE(DoIpVehicleAnnouncementPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 32);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle announcement message / vehicle identification response message (0x4)\nPayload Length: 32\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle announcement message / vehicle identification response message (0x0004)\nPayload Length: 32\n")

} // DoIpVehicleAnnouncementPacketParsing

Expand Down Expand Up @@ -435,7 +434,7 @@ PTF_TEST_CASE(DoIpVehicleAnnouncementPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 33);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle announcement message / vehicle identification response message (0x4)\nPayload Length: 33\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Vehicle announcement message / vehicle identification response message (0x0004)\nPayload Length: 33\n")
}
// RoutingActivationRequest
PTF_TEST_CASE(DoIpRoutingActivationRequestPacketParsing)
Expand Down Expand Up @@ -477,7 +476,7 @@ PTF_TEST_CASE(DoIpRoutingActivationRequestPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 11);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation request (0x5)\nPayload Length: 11\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation request (0x0005)\nPayload Length: 11\n")
}

PTF_TEST_CASE(DoIpRoutingActivationRequestPacketCreation)
Expand Down Expand Up @@ -524,7 +523,7 @@ PTF_TEST_CASE(DoIpRoutingActivationRequestPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 11);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation request (0x5)\nPayload Length: 11\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation request (0x0005)\nPayload Length: 11\n")
}
// RoutingActivationResponse
PTF_TEST_CASE(DoIpRoutingActivationResponsePacketParsing)
Expand Down Expand Up @@ -564,7 +563,7 @@ PTF_TEST_CASE(DoIpRoutingActivationResponsePacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 9);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation response (0x6)\nPayload Length: 9\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation response (0x0006)\nPayload Length: 9\n")
}

PTF_TEST_CASE(DoIpRoutingActivationResponsePacketCreation)
Expand Down Expand Up @@ -612,7 +611,7 @@ PTF_TEST_CASE(DoIpRoutingActivationResponsePacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 13);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation response (0x6)\nPayload Length: 13\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Routing activation response (0x0006)\nPayload Length: 13\n")
}
// ---------------
// AliveCheckRequestPacket
Expand Down Expand Up @@ -645,7 +644,7 @@ PTF_TEST_CASE(DoIpAliveCheckRequestPacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 0);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check request (0x7)\nPayload Length: 0\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check request (0x0007)\nPayload Length: 0\n")
}

PTF_TEST_CASE(DoIpAliveCheckRequestPacketCreation)
Expand Down Expand Up @@ -685,7 +684,7 @@ PTF_TEST_CASE(DoIpAliveCheckRequestPacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 0);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check request (0x7)\nPayload Length: 0\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check request (0x0007)\nPayload Length: 0\n")
}
// ---------------
// AliveCheckResponsePacket
Expand Down Expand Up @@ -724,7 +723,7 @@ PTF_TEST_CASE(DoIpAliveCheckResponsePacketParsing)
PTF_ASSERT_EQUAL(doipLayer->getPayloadLength(), 2);
PTF_ASSERT_EQUAL(
doipLayer->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check response (0x8)\nPayload Length: 2\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check response (0x0008)\nPayload Length: 2\n")
}

PTF_TEST_CASE(DoIpAliveCheckResponsePacketCreation)
Expand Down Expand Up @@ -764,7 +763,7 @@ PTF_TEST_CASE(DoIpAliveCheckResponsePacketCreation)
PTF_ASSERT_EQUAL(_doipLayer2->getPayloadLength(), 2);
PTF_ASSERT_EQUAL(
_doipLayer2->toString(),
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check response (0x8)\nPayload Length: 2\n")
"DOIP Layer:\nProtocol Version: DoIP ISO 13400-2:2012 (0x2)\nPayload Type: Alive check response (0x0008)\nPayload Length: 2\n")
}
// ------------------
// EntityStatusRequestPacket
Expand Down
1 change: 0 additions & 1 deletion Tests/Pcap++Test/Common/PcapFileNamesDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@
#define EXAMPLE_PCAP_DESTRUCTOR2_PATH "PcapExamples/destructor2.pcap"
#define EXAMPLE_PCAP_NANO_PATH "PcapExamples/nanosecs.pcap"
#define EXAMPLE_PCAPNG_NANO_PATH "PcapExamples/nanosecs.pcapng"
#define EXAMPLE_PCAPNG_DOIP_PATH "PcapExamples/doip.pcap"
3 changes: 0 additions & 3 deletions Tests/Pcap++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ PTF_TEST_CASE(TestHttpResponseParsing);
PTF_TEST_CASE(TestPrintPacketAndLayers);
PTF_TEST_CASE(TestDnsParsing);

// Implemented in DoIpTests.cpp
PTF_TEST_CASE(DoIpPacketParsing);

// Implemented in TcpReassemblyTests.cpp
PTF_TEST_CASE(TestTcpReassemblySanity);
PTF_TEST_CASE(TestTcpReassemblyRetran);
Expand Down
17 changes: 0 additions & 17 deletions Tests/Pcap++Test/Tests/PacketParsingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,3 @@ PTF_TEST_CASE(TestDnsParsing)
// wireshark filter: dns.count.add_rr > 0 and dns.resp.type == 47
PTF_ASSERT_EQUAL(additionalWithTypeNSEC, 14);
} // TestDnsParsing

PTF_TEST_CASE(DoIpPacketParsing)
{
pcpp::PcapFileReaderDevice reader(EXAMPLE_PCAPNG_DOIP_PATH);
PTF_ASSERT_TRUE(reader.open());
pcpp::RawPacket rawPacket;
while (reader.getNextPacket(rawPacket))
{
pcpp::Packet packet(&rawPacket);
std::cout << packet.toString();
// pcpp::DoIpLayer* doipLayer = packet.getLayerOfType<pcpp::DoIpLayer>();
// PTF_ASSERT_TRUE(doipLayer->resolveProtocolVersion(doipLayer->getProtocolVersion(),
// doipLayer->getInvertProtocolVersion(), doipLayer->getPayloadType()));
// PTF_ASSERT_TRUE(doipLayer->resolvePayloadLength(doipLayer->getPayloadLength(), doipLayer->getPayloadType()));
pcpp::multiPlatformSleep(1);
}
}
1 change: 0 additions & 1 deletion Tests/Pcap++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ int main(int argc, char* argv[])
PTF_START_RUNNING_TESTS(userTagsInclude, userTagsExclude, configTags);

testSetUp();
PTF_RUN_TEST(DoIpPacketParsing, "no_network");
PTF_RUN_TEST(TestIPAddress, "no_network;ip");
PTF_RUN_TEST(TestMacAddress, "no_network;mac");
PTF_RUN_TEST(TestLRUList, "no_network");
Expand Down

0 comments on commit d4658d7

Please sign in to comment.