PcapPlusPlus
pcpp::GREv0Layer Class Reference

#include <GreLayer.h>

Inheritance diagram for pcpp::GREv0Layer:
pcpp::GreLayer pcpp::Layer pcpp::IDataContainer

Public Member Functions

 GREv0Layer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 GREv0Layer ()
 
gre_basic_headergetGreHeader ()
 
bool getChecksum (uint16_t &checksum)
 
bool setChecksum (uint16_t checksum)
 
bool unsetChecksum ()
 
bool getOffset (uint16_t &offset)
 
bool getKey (uint32_t &key)
 
bool setKey (uint32_t key)
 
bool unsetKey ()
 
void computeCalculateFields ()
 
std::string toString ()
 
- Public Member Functions inherited from pcpp::GreLayer
bool getSequenceNumber (uint32_t &seqNumber)
 
bool setSequenceNumber (uint32_t seqNumber)
 
bool unsetSequenceNumber ()
 
void parseNextLayer ()
 
size_t getHeaderLen ()
 
OsiModelLayer getOsiModelLayer ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer ()
 
LayergetPrevLayer ()
 
ProtocolType getProtocol ()
 
uint8_t * getData ()
 
size_t getDataLen ()
 
uint8_t * getLayerPayload ()
 
size_t getLayerPayloadSize ()
 
bool isAllocatedToPacket ()
 
void copyData (uint8_t *toArr)
 
uint8_t * getDataPtr (size_t offset=0)
 

Additional Inherited Members

- Static Public Member Functions inherited from pcpp::GreLayer
static ProtocolType getGREVersion (uint8_t *greData, size_t greDataLen)
 

Detailed Description

Represents a GRE version 0 protocol. Limitation: currently this layer doesn't support GRE routing information parsing and editing. So if a GREv0 packet includes routing information it won't be parse correctly. I didn't add it because of lack of time, but if you need it please tell me and I'll add it

Constructor & Destructor Documentation

◆ GREv0Layer() [1/2]

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

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

◆ GREv0Layer() [2/2]

pcpp::GREv0Layer::GREv0Layer ( )

A constructor that creates a new GREv0 header and allocates the data

Member Function Documentation

◆ computeCalculateFields()

void pcpp::GREv0Layer::computeCalculateFields ( )
virtual

Calculate the following fields:

Implements pcpp::Layer.

◆ getChecksum()

bool pcpp::GREv0Layer::getChecksum ( uint16_t &  checksum)

Get checksum value if field exists in layer

Parameters
[out]checksumThe returned checksum value if exists in layer. Else remain unchanged
Returns
True if checksum field exists in layer. In this case checksum parameter will be filled with the value. Or false if checksum field doesn't exist in layer

◆ getGreHeader()

gre_basic_header* pcpp::GREv0Layer::getGreHeader ( )
inline

Get a pointer to the basic GRE header containing only non-optional fields. Notice this points directly to the data, so every change will change the actual packet data. Also please notice that changing the set bits (gre_basic_header::strictSourceRouteBit, gre_basic_header::sequenceNumBit, gre_basic_header::keyBit, gre_basic_header::routingBit, gre_basic_header::checksumBit, gre_basic_header::ackSequenceNumBit) without using the proper set or unset methods (such as setChecksum(), unsetChecksum(), etc.) may result to wrong calculation of header length and really weird bugs. Please avoid doing so

Returns
A pointer to the gre_basic_header

◆ getKey()

bool pcpp::GREv0Layer::getKey ( uint32_t &  key)

Get key value if field exists in layer

Parameters
[out]keyThe returned key value if exists in layer. Else remain unchanged
Returns
True if key field exists in layer. In this case key parameter will be filled with the value. Or false if key field doesn't exist in layer

◆ getOffset()

bool pcpp::GREv0Layer::getOffset ( uint16_t &  offset)

Get offset value if field exists in layer. Notice there is no setOffset() method as GRE routing information isn't supported yet (see comment on class description)

Parameters
[out]offsetThe returned offset value if exists in layer. Else remain unchanged
Returns
True if offset field exists in layer. In this case offset parameter will be filled with the value. Or false if offset field doesn't exist in layer

◆ setChecksum()

bool pcpp::GREv0Layer::setChecksum ( uint16_t  checksum)

Set checksum value. If checksum or offset fields already exist (gre_basic_header::checksumBit or gre_basic_header::routingBit are set) then only the new value is set. If both fields don't exist a new 4-byte value will be added to the layer, gre_basic_header::checksumBit will be set (gre_basic_header::routingBit will remain unset), the new checksum value will be set and offset value will be set to 0. The reason both fields are added is that GREv0 protocol states both of them or none of them should exist on packet (even if only one of the bits are set)

Parameters
[in]checksumThe checksum value to set
Returns
True if managed to set the value/s successfully, or false otherwise (if couldn't extend the layer)

◆ setKey()

bool pcpp::GREv0Layer::setKey ( uint32_t  key)

Set key value. If field already exists (gre_basic_header::keyBit is set) then only the new value is set. If field doesn't exist it will be added to the layer, gre_basic_header::keyBit will be set and the new value will be set

Parameters
[in]keyThe key value to set
Returns
True if managed to set the value successfully, or false otherwise (if couldn't extend the layer)

◆ toString()

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

Implements pcpp::Layer.

◆ unsetChecksum()

bool pcpp::GREv0Layer::unsetChecksum ( )

Unset checksum and possibly remove it from the layer. It will be removed from the layer only if gre_basic_header::routingBit is not set as well. Otherwise checksum field will remain on packet with value of 0

Returns
True if managed to unset successfully or false (and error log) if checksum wasn't set in the first place or if didn't manage to remove it from the layer

◆ unsetKey()

bool pcpp::GREv0Layer::unsetKey ( )

Unset key and remove it from the layer

Returns
True if managed to unset successfully or false (and error log) if key wasn't set in the first place or if didn't manage to remove it from the layer