PcapPlusPlus  Next
pcpp::WireGuardLayer Class Reference

#include <WireGuardLayer.h>

Inheritance diagram for pcpp::WireGuardLayer:
pcpp::Layer pcpp::IDataContainer pcpp::WireGuardCookieReplyLayer pcpp::WireGuardHandshakeInitiationLayer pcpp::WireGuardHandshakeResponseLayer pcpp::WireGuardTransportDataLayer

Classes

struct  wg_common_header
 

Public Types

enum class  WireGuardMessageType {
  Unknown = 0 , HandshakeInitiation = 1 , HandshakeResponse = 2 , CookieReply = 3 ,
  TransportData = 4
}
 

Public Member Functions

 WireGuardLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
std::string getMessageTypeAsString () const
 
uint8_t getMessageType () const
 
uint32_t getReserved () const
 
void setReserved (const std::array< uint8_t, 3 > &reserved)
 
void parseNextLayer () override
 
size_t getHeaderLen () const override
 
void computeCalculateFields () override
 
std::string toString () const override
 
OsiModelLayer getOsiModelLayer () const override
 
virtual WireGuardMessageType getWireGuardMessageType () const
 
- Public Member Functions inherited from pcpp::Layer
 ~Layer () override
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
bool isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) 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 override
 

Static Public Member Functions

static bool isWireGuardPorts (uint16_t portSrc, uint16_t portDst)
 
static bool isDataValid (const uint8_t *data, size_t dataLen)
 
static WireGuardLayerparseWireGuardLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 

Detailed Description

Represents a WireGuard protocol layer

Member Enumeration Documentation

◆ WireGuardMessageType

WireGuard message types

Enumerator
Unknown 

Unknown Initiation message

HandshakeInitiation 

Handshake Initiation message

HandshakeResponse 

Handshake Response message

CookieReply 

Cookie Reply message

TransportData 

Transport Data message

Constructor & Destructor Documentation

◆ WireGuardLayer()

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

Constructs a WireGuardLayer object.

Parameters
dataPointer to the raw data representing the WireGuard layer
dataLenLength of the data
prevLayerPointer to the previous layer in the packet (if any)
packetPointer to the packet this layer belongs to

Member Function Documentation

◆ computeCalculateFields()

void pcpp::WireGuardLayer::computeCalculateFields ( )
inlineoverridevirtual

No fields to compute or update, so this method is left empty.

Implements pcpp::Layer.

◆ getHeaderLen()

size_t pcpp::WireGuardLayer::getHeaderLen ( ) const
overridevirtual
Returns
Size of the header in bytes.

Implements pcpp::Layer.

◆ getMessageType()

uint8_t pcpp::WireGuardLayer::getMessageType ( ) const
Returns
The message type as an unsigned 32-bit integer.

◆ getMessageTypeAsString()

std::string pcpp::WireGuardLayer::getMessageTypeAsString ( ) const
Returns
String representation of the message type.

◆ getOsiModelLayer()

OsiModelLayer pcpp::WireGuardLayer::getOsiModelLayer ( ) const
inlineoverridevirtual
Returns
OSI model layer corresponding to the Network layer

Implements pcpp::Layer.

◆ getReserved()

uint32_t pcpp::WireGuardLayer::getReserved ( ) const
Returns
The reserved field as a 32-bit integer.

◆ getWireGuardMessageType()

virtual WireGuardMessageType pcpp::WireGuardLayer::getWireGuardMessageType ( ) const
inlinevirtual

◆ isDataValid()

static bool pcpp::WireGuardLayer::isDataValid ( const uint8_t *  data,
size_t  dataLen 
)
static

Checks if the given data represents a WireGuard message.

Parameters
dataPointer to the raw data
dataLenLength of the data
Returns
True if the data starts with a valid WireGuard message type, false otherwise

◆ isWireGuardPorts()

static bool pcpp::WireGuardLayer::isWireGuardPorts ( uint16_t  portSrc,
uint16_t  portDst 
)
inlinestatic

Checks if the given port numbers are WireGuard ports.

Parameters
portSrcThe source port number to check
portDstThe destination port number to check
Returns
True if either port matches the WireGuard port (51820), false otherwise

◆ parseNextLayer()

void pcpp::WireGuardLayer::parseNextLayer ( )
inlineoverridevirtual

Does nothing for this layer (WireGuard layer is always last)

Implements pcpp::Layer.

◆ parseWireGuardLayer()

static WireGuardLayer* pcpp::WireGuardLayer::parseWireGuardLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
static

Parses the raw data into a WireGuard layer.

Parameters
dataPointer to the raw data
dataLenLength of the data
prevLayerPointer to the previous layer
packetPointer to the packet
Returns
A pointer to the parsed WireGuardLayer, or nullptr if parsing fails

◆ setReserved()

void pcpp::WireGuardLayer::setReserved ( const std::array< uint8_t, 3 > &  reserved)
Parameters
reservedThe reserved field to set as a An array containing the 3-byte.

◆ toString()

std::string pcpp::WireGuardLayer::toString ( ) const
overridevirtual

Converts the WireGuard layer to a string representation.

Returns
String representation of the WireGuard layer

Implements pcpp::Layer.