PcapPlusPlus  21.05
pcpp::SdpLayer Class Reference

#include <SdpLayer.h>

Inheritance diagram for pcpp::SdpLayer:
pcpp::TextBasedProtocolMessage pcpp::Layer pcpp::IDataContainer

Public Member Functions

 SdpLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 SdpLayer ()
 
 SdpLayer (std::string username, long sessionID, long sessionVersion, IPv4Address ipAddress, std::string sessionName, long startTime, long stopTime)
 
 SdpLayer (const SdpLayer &other)
 
SdpLayeroperator= (const SdpLayer &other)
 
IPv4Address getOwnerIPv4Address () const
 
uint16_t getMediaPort (std::string mediaType) const
 
bool addMediaDescription (std::string mediaType, uint16_t mediaPort, std::string mediaProtocol, std::string mediaFormat, std::vector< std::string > mediaAttributes)
 
OsiModelLayer getOsiModelLayer () const
 
std::string toString () const
 
- Public Member Functions inherited from pcpp::TextBasedProtocolMessage
HeaderFieldgetFieldByName (std::string fieldName, int index=0) const
 
HeaderFieldgetFirstField () const
 
HeaderFieldgetNextField (HeaderField *prevField) const
 
int getFieldCount () const
 
virtual HeaderFieldaddField (const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldaddField (const HeaderField &newField)
 
HeaderFieldaddEndOfHeader ()
 
virtual HeaderFieldinsertField (HeaderField *prevField, const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldinsertField (std::string prevFieldName, const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldinsertField (HeaderField *prevField, const HeaderField &newField)
 
bool removeField (HeaderField *fieldToRemove)
 
bool removeField (std::string fieldName, int index=0)
 
bool isHeaderComplete () const
 
virtual void parseNextLayer ()
 
size_t getHeaderLen () const
 
virtual void computeCalculateFields ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 

Detailed Description

Represents a SDP (Session Description Protocol) message. SDP is a text-based protocol described by a series of fields, one per line (lines are separated by CRLF). The form of each field is as follows:

[character]=[value]

Each character represents a certain type of field. All field type are represented as macros in SdpLayer.h file (for example: PCPP_SDP_ORIGINATOR_FIELD is a macro for the originator field (o=) ).
For more details about SDP structure please refer to its Wikipedia page: https://en.wikipedia.org/wiki/Session_Description_Protocol

Constructor & Destructor Documentation

◆ SdpLayer() [1/4]

pcpp::SdpLayer::SdpLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

◆ SdpLayer() [2/4]

pcpp::SdpLayer::SdpLayer ( )

An empty c'tor which initialize an empty message with no fields

◆ SdpLayer() [3/4]

pcpp::SdpLayer::SdpLayer ( std::string  username,
long  sessionID,
long  sessionVersion,
IPv4Address  ipAddress,
std::string  sessionName,
long  startTime,
long  stopTime 
)

A c'tor which initializes a message with the minimum required fields.
After this c'tor the message will look like this:

v=0
o=[username] [sessionID] [sessionVersion] IN IP4 [ipAddress]
s=[sessionName]
c=IN IP4 [ipAddress]
t=[startTime] [endTime]
Parameters
[in]usernameUser's login on the originating host
[in]sessionIDA globally unique identifier for the session
[in]sessionVersionA version number for this session description
[in]ipAddressThe address of the machine from which the session is created
[in]sessionNameA textual session name
[in]startTimeThe start time of the session
[in]stopTimeThe stop time of the session

◆ SdpLayer() [4/4]

pcpp::SdpLayer::SdpLayer ( const SdpLayer other)
inline

A copy constructor for this layer. Inherits the base copy constructor and doesn't add anything else

Parameters
[in]otherThe instance to copy from

Member Function Documentation

◆ addMediaDescription()

bool pcpp::SdpLayer::addMediaDescription ( std::string  mediaType,
uint16_t  mediaPort,
std::string  mediaProtocol,
std::string  mediaFormat,
std::vector< std::string >  mediaAttributes 
)

Adds a 'media-description' field (m=) with all necessary data and attribute fields (a=) with data relevant for this media.
After this method is run the following block of fields will be added at the end of the message:

m=[mediaType] [mediaPort] [mediaProtocol] [mediaFormat]
a=[1st media attribute]
a=[2nd media attribute]
...
Parameters
[in]mediaTypeThe media type, usually "audio", "video", "text" or "image"
[in]mediaPortThe transport port to which the media stream is sent
[in]mediaProtocolThe transport protocol, usually "udp", "RTP/AVP" or "RTP/SAVP"
[in]mediaFormatA space-separated list of media format description. For example: "8 96"
[in]mediaAttributesA vector of media attributes. Each string in this vector will be translated into a 'media-attribute' field (a=)
Returns
True if all fields were added properly or false if at least one field was failed to be added

◆ getMediaPort()

uint16_t pcpp::SdpLayer::getMediaPort ( std::string  mediaType) const

The 'media-description' field (m=) contains the transport port to which the media stream is sent. This port can be used to track the RTP data relevant for the call. This method extracts this port from the 'media-description' field and returns it. Since a SDP message can contain several 'media-description' fields, one for each media type (e.g audio, image, etc.), the user is required to provide the media type. A value of 0 will be returned in the following cases: (1) if 'media-description' field doesn't exist; (2) if provided media type was not found; (3) if 'media-description' field didn't contain a port

Parameters
[in]mediaTypeThe media type to search in
Returns
The transport port to which the media stream is sent

◆ getOsiModelLayer()

OsiModelLayer pcpp::SdpLayer::getOsiModelLayer ( ) const
inlinevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getOwnerIPv4Address()

IPv4Address pcpp::SdpLayer::getOwnerIPv4Address ( ) const

The 'originator' field (o=) contains the IP address of the the machine from which the session is created. This IP address can be used to track the RTP data relevant for the call. This method extracts this IP address from the 'originator' field and returns it. A value of IPv4Address::Zero will be returned in the following cases: (1) if 'originator' field doesn't exist; (2) if it doesn't contain the IP address; (3) if it contains a non-IPv4 address

Returns
Te IP address of the the machine from which the session is created

◆ operator=()

SdpLayer& pcpp::SdpLayer::operator= ( const SdpLayer other)
inline

An assignment operator overload for this layer. Inherits the base assignment operator and doesn't add anything else

Parameters
[in]otherThe instance to copy from

◆ toString()

std::string pcpp::SdpLayer::toString ( ) const
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.