PcapPlusPlus  19.12
pcpp::HeaderField Class Reference

#include <TextBasedProtocol.h>

Public Member Functions

 HeaderField (const HeaderField &other)
 
size_t getFieldSize () const
 
std::string getFieldName () const
 
std::string getFieldValue () const
 
bool setFieldValue (std::string newValue)
 
bool isEndOfHeader () const
 

Detailed Description

A wrapper class for each text-based-protocol header field, e.g "Host", "Cookie", "Content-Length", "Via", "Call-ID", etc. Each field contains a name (e.g "Host") and a value (e.g "www.wikipedia.org"). The user can get and set both of them through dedicated methods. The separator between header fields is either CRLF ("\r\n\") or LF ("\n") in more rare cases, which means every HeaderField instance is responsible for wrapping and parsing a header field from the previous CRLF (not inclusive) until the next CRLF/LF (inclusive) A special case is with the end of a header, meaning 2 consecutive CRLFs ("\r\n\r\n") or consecutive LFs ("\n\n"). PcapPlusPlus treats the first CRLF/LF as part of the last field in the header, and the second CRLF is an HeaderField instance of its own which name and values are an empty string ("") or pcpp::PCPP_END_OF_TEXT_BASED_PROTOCOL_HEADER

Constructor & Destructor Documentation

◆ HeaderField()

pcpp::HeaderField::HeaderField ( const HeaderField other)

A copy constructor that creates a new instance out of an existing HeaderField instance. The copied instance will not have shared resources with the original instance, meaning all members and properties are copied

Parameters
[in]otherThe original instance to copy from

Member Function Documentation

◆ getFieldName()

std::string pcpp::HeaderField::getFieldName ( ) const
Returns
The field name as string. Notice the return data is copied data, so changing it won't change the packet data

◆ getFieldSize()

size_t pcpp::HeaderField::getFieldSize ( ) const
inline
Returns
The field length in bytes, meaning count of all characters from the previous CRLF (not inclusive) until the next CRLF (inclusive) For example: the field "Host: www.wikipedia.org\r\n" will have the length of 25

◆ getFieldValue()

std::string pcpp::HeaderField::getFieldValue ( ) const
Returns
The field value as string. Notice the return data is copied data, so changing it won't change the packet data

◆ isEndOfHeader()

bool pcpp::HeaderField::isEndOfHeader ( ) const
inline

Get an indication whether the field is a field that ends the header (meaning contain only CRLF - see class explanation)

Returns
True if this is a end-of-header field, false otherwise

◆ setFieldValue()

bool pcpp::HeaderField::setFieldValue ( std::string  newValue)

A setter for field value

Parameters
[in]newValueThe new value to set to the field. Old value will be deleted