Skip to content
Draft
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
18 changes: 4 additions & 14 deletions Packet++/header/SipLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,10 @@ namespace pcpp
}

/// A static factory method that attempts to create a SIP layer from existing packet raw data
/// The method first checks whether the source or destination port matches the SIP protocol.
/// @param[in] data A pointer to the raw data
/// @param[in] dataLen Size of the data in bytes
/// @param[in] prevLayer A pointer to the previous layer
/// @param[in] packet A pointer to the Packet instance where layer will be stored in
/// @param[in] srcPort Source port number to check
/// @param[in] dstPort Dest port number to check
/// @return A newly allocated SIP layer of type request or response, or nullptr if parsing fails
static SipLayer* parseSipLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet,
uint16_t srcPort, uint16_t dstPort);

/// A static factory method that attempts to create a SIP layer from existing packet raw data
/// This method does not check source or destination ports. Instead, it uses heuristics
/// to determine whether the data represents a SIP request or response.
///
/// The method uses heuristics to determine whether the data contains a SIP request or response message and
/// creates the relevant layer type. If no message type can be identified, the method returns nullptr.
///
/// @param[in] data A pointer to the raw data
/// @param[in] dataLen Size of the data in bytes
/// @param[in] prevLayer A pointer to the previous layer
Expand Down
24 changes: 0 additions & 24 deletions Packet++/src/SipLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,30 +159,6 @@ namespace pcpp
}
}

SipLayer* SipLayer::parseSipLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, uint16_t srcPort,
uint16_t dstPort)
{
if (!(SipLayer::isSipPort(srcPort) || SipLayer::isSipPort(dstPort)))
{
return nullptr;
}

if (SipRequestFirstLine::parseMethod(reinterpret_cast<char*>(data), dataLen) !=
SipRequestLayer::SipMethodUnknown)
{
return new SipRequestLayer(data, dataLen, prevLayer, packet);
}

if (SipResponseFirstLine::parseStatusCode(reinterpret_cast<char*>(data), dataLen) !=
SipResponseLayer::SipStatusCodeUnknown &&
!SipResponseFirstLine::parseVersion(reinterpret_cast<char*>(data), dataLen).empty())
{
return new SipResponseLayer(data, dataLen, prevLayer, packet);
}

return nullptr;
}

SipLayer* SipLayer::parseSipLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
{
SipLayer::SipParseResult sipParseResult = detectSipMessageType(data, dataLen);
Expand Down
8 changes: 2 additions & 6 deletions Packet++/src/UdpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ namespace pcpp
}
else if (SipLayer::isSipPort(portDst) || SipLayer::isSipPort(portSrc))
{
// Resolves the overload of parseSipLayer, without static_casting a function pointer.
auto* (*fac)(uint8_t*, size_t, Layer*, Packet*, uint16_t, uint16_t) = SipLayer::parseSipLayer;
tryConstructNextLayerFromFactoryWithFallback<PayloadLayer>(fac, udpData, udpDataLen, portSrc, portDst);
tryConstructNextLayerFromFactoryWithFallback<PayloadLayer>(SipLayer::parseSipLayer, udpData, udpDataLen);
}
else if ((RadiusLayer::isRadiusPort(portDst) || RadiusLayer::isRadiusPort(portSrc)) &&
RadiusLayer::isDataValid(udpData, udpDataLen))
Expand Down Expand Up @@ -173,9 +171,7 @@ namespace pcpp

// Here, heuristics for all protocols should be invoked to determine the correct layer
{
// Resolves the overload of parseSipLayer, without static_casting a function pointer.
auto* (*fac)(uint8_t*, size_t, Layer*, Packet*) = SipLayer::parseSipLayer;
tryConstructNextLayerFromFactoryWithFallback<PayloadLayer>(fac, udpData, udpDataLen);
tryConstructNextLayerFromFactoryWithFallback<PayloadLayer>(SipLayer::parseSipLayer, udpData, udpDataLen);
}

if (!hasNextLayer())
Expand Down
Loading