Skip to content

Commit

Permalink
Consider SIP content type to determine if the next layer is SDP (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Double0101 authored Feb 14, 2024
1 parent c47c819 commit 983869a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Packet++/src/SipLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ void SipLayer::parseNextLayer()
return;

size_t headerLen = getHeaderLen();
std::string contentType;
if (getContentLength() > 0)
{
HeaderField *contentTypeField = getFieldByName(PCPP_SIP_CONTENT_TYPE_FIELD);
if (contentTypeField != nullptr)
contentType = contentTypeField->getFieldValue();
}

if (contentType.find("application/sdp") != std::string::npos)
{
m_NextLayer = new SdpLayer(m_Data + headerLen, m_DataLen - headerLen, this, m_Packet);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Packet++Test/PacketExamples/sip_not_sdp.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0050563daf58005056c000080800450003ff1ac5000040113fa2ac106201ac106265a7c813c403ebc90a5055424c495348207369703a74656c6570686f6e6531403137322e31362e39382e3130313b7472616e73706f72743d554450205349502f322e300d0a5669613a205349502f322e302f554450203137322e31362e39382e313a34323935323b6272616e63683d7a39684734624b2d64383735347a2d613338643165356632376463306662392d312d2d2d64383735347a2d0d0a4d61782d466f7277617264733a2037300d0a436f6e746163743a203c7369703a74656c6570686f6e6531403137322e31362e39382e313a34323935323b7472616e73706f72743d5544503e0d0a546f3a203c7369703a74656c6570686f6e6531403137322e31362e39382e3130313b7472616e73706f72743d5544503e0d0a46726f6d3a203c7369703a74656c6570686f6e6531403137322e31362e39382e3130313b7472616e73706f72743d5544503e3b7461673d63663633633933340d0a43616c6c2d49443a205a474d334d47526a5a5751794d6a67304d6a526c4d6a646d5a544d3459575a6c4f44497a4f475a6a5a44632e0d0a435365713a2031205055424c4953480d0a457870697265733a203630300d0a416c6c6f773a20494e564954452c2041434b2c2043414e43454c2c204259452c204e4f544946592c2052454645522c204d4553534147452c204f5054494f4e532c20494e464f2c205355425343524942450d0a436f6e74656e742d547970653a206170706c69636174696f6e2f706964662b786d6c0d0a537570706f727465643a207265706c616365732c206e6f72656665727375622c20657874656e6465642d72656665722c2074696d65722c20582d636973636f2d736572766963657572690d0a557365722d4167656e743a205a20332e332e3231393333207232313930330d0a4576656e743a2070726573656e63650d0a416c6c6f772d4576656e74733a2070726573656e63652c206b706d6c0d0a436f6e74656e742d4c656e6774683a203237330d0a0d0a3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f3e0d0a3c70726573656e636520786d6c6e733d2275726e3a696574663a706172616d733a786d6c3a6e733a70696466220d0a20202020202020202020656e746974793d227369703a74656c6570686f6e6531403137322e31362e39382e3130313b7472616e73706f72743d554450223e0d0a20203c7475706c652069643d2274656c6570686f6e653122203e0d0a20202020203c7374617475733e3c62617369633e6f70656e3c2f62617369633e3c2f7374617475733e0d0a20202020203c6e6f74653e4f6e6c696e653c2f6e6f74653e0d0a20203c2f7475706c653e0d0a3c2f70726573656e63653e0d0a
Binary file not shown.
1 change: 1 addition & 0 deletions Tests/Packet++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ PTF_TEST_CASE(SipResponseLayerParsingTest);
PTF_TEST_CASE(SipResponseLayerCreationTest);
PTF_TEST_CASE(SipResponseLayerEditTest);
PTF_TEST_CASE(SdpLayerParsingTest);
PTF_TEST_CASE(SipNotSdpLayerParsingTest);
PTF_TEST_CASE(SdpLayerCreationTest);
PTF_TEST_CASE(SdpLayerEditTest);

Expand Down
18 changes: 18 additions & 0 deletions Tests/Packet++Test/Tests/SipSdpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,24 @@ PTF_TEST_CASE(SdpLayerParsingTest)
} // SdpLayerParsingTest


PTF_TEST_CASE(SipNotSdpLayerParsingTest)
{
timeval time;
gettimeofday(&time, nullptr);

READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/sip_not_sdp.dat");

pcpp::Packet notSdpPacket(&rawPacket1);

PTF_ASSERT_TRUE(notSdpPacket.isPacketOfType(pcpp::SIP));
pcpp::SipRequestLayer* sipLayer = notSdpPacket.getLayerOfType<pcpp::SipRequestLayer>();
PTF_ASSERT_EQUAL(sipLayer->getContentLength(), 273);

pcpp::Layer* nextLayer = sipLayer->getNextLayer();
PTF_ASSERT_EQUAL(nextLayer->getProtocol(), pcpp::GenericPayload);

PTF_ASSERT_FALSE(notSdpPacket.isPacketOfType(pcpp::SDP));
} // SipNotSdpLayerParsingTest

PTF_TEST_CASE(SdpLayerCreationTest)
{
Expand Down
1 change: 1 addition & 0 deletions Tests/Packet++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ int main(int argc, char* argv[])
PTF_RUN_TEST(SipResponseLayerParsingTest, "sip");
PTF_RUN_TEST(SipResponseLayerCreationTest, "sip");
PTF_RUN_TEST(SipResponseLayerEditTest, "sip");
PTF_RUN_TEST(SipNotSdpLayerParsingTest, "sip");
PTF_RUN_TEST(SdpLayerParsingTest, "sdp");
PTF_RUN_TEST(SdpLayerCreationTest, "sdp");
PTF_RUN_TEST(SdpLayerEditTest, "sdp");
Expand Down

0 comments on commit 983869a

Please sign in to comment.