PcapPlusPlus  24.09
pcpp::RadiusLayer Class Reference

#include <RadiusLayer.h>

Inheritance diagram for pcpp::RadiusLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 RadiusLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 RadiusLayer (uint8_t code, uint8_t id, const uint8_t *authenticator, uint8_t authenticatorArrSize)
 
 RadiusLayer (uint8_t code, uint8_t id, const std::string &authenticator)
 
 ~RadiusLayer ()
 
radius_headergetRadiusHeader () const
 
std::string getAuthenticatorValue () const
 
void setAuthenticatorValue (const std::string &authValue)
 
RadiusAttribute getFirstAttribute () const
 
RadiusAttribute getNextAttribute (RadiusAttribute &attr) const
 
RadiusAttribute getAttribute (uint8_t attrType) const
 
size_t getAttributeCount () const
 
RadiusAttribute addAttribute (const RadiusAttributeBuilder &attrBuilder)
 
RadiusAttribute addAttributeAfter (const RadiusAttributeBuilder &attrBuilder, uint8_t prevAttrType)
 
bool removeAttribute (uint8_t attrType)
 
bool removeAllAttributes ()
 
size_t getHeaderLen () const
 
void parseNextLayer ()
 
void computeCalculateFields ()
 
std::string toString () const
 
OsiModelLayer getOsiModelLayer () const
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
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
 

Static Public Member Functions

static std::string getRadiusMessageString (uint8_t radiusMessageCode)
 
static bool isDataValid (const uint8_t *udpData, size_t udpDataLen)
 
static bool isRadiusPort (uint16_t port)
 

Detailed Description

Represents a RADIUS (Remote Authentication Dial-In User Service) protocol layer

Constructor & Destructor Documentation

◆ RadiusLayer() [1/3]

pcpp::RadiusLayer::RadiusLayer ( 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

◆ RadiusLayer() [2/3]

pcpp::RadiusLayer::RadiusLayer ( uint8_t  code,
uint8_t  id,
const uint8_t *  authenticator,
uint8_t  authenticatorArrSize 
)

A constructor that creates a new layer from scratch

Parameters
[in]codeThe RADIUS message code
[in]idThe RADIUS message ID
[in]authenticatorA pointer to a byte array containing the authenticator value
[in]authenticatorArrSizeThe authenticator byte array size. A valid size of the authenticator field is 16 bytes. If the provided size is less than that then the byte array will be copied to the packet but the missing bytes will stay zero. If the size is more than 16 bytes, only the first 16 bytes will be copied to the packet

◆ RadiusLayer() [3/3]

pcpp::RadiusLayer::RadiusLayer ( uint8_t  code,
uint8_t  id,
const std::string &  authenticator 
)

A constructor that creates a new layer from scratch

Parameters
[in]codeThe RADIUS message code
[in]idThe RADIUS message ID
[in]authenticatorA hex string representing the authenticator value. A valid size of the authenticator field is 16 bytes. If the hex string represents an array that is smaller than this then the missing bytes in the packet's authenticator field will stay zero. If the hex string represents an array that is larger than 16 bytes, only the first 16 bytes will be copied to the packet

◆ ~RadiusLayer()

pcpp::RadiusLayer::~RadiusLayer ( )
inline

A d'tor for this layer, currently does nothing

Member Function Documentation

◆ addAttribute()

RadiusAttribute pcpp::RadiusLayer::addAttribute ( const RadiusAttributeBuilder attrBuilder)

Add a new RADIUS attribute at the end of the layer

Parameters
[in]attrBuilderA RadiusAttributeBuilder object that contains the requested attribute data to add
Returns
A RadiusAttribute object containing the newly added RADIUS attribute data or logical null (RadiusAttribute::isNull() == true) if addition failed

◆ addAttributeAfter()

RadiusAttribute pcpp::RadiusLayer::addAttributeAfter ( const RadiusAttributeBuilder attrBuilder,
uint8_t  prevAttrType 
)

Add a new RADIUS attribute after an existing one

Parameters
[in]attrBuilderA RadiusAttributeBuilder object that contains the requested attribute data to add
[in]prevAttrTypeThe RADIUS attribute which the newly added attribute will come after
Returns
A RadiusAttribute object containing the newly added RADIUS attribute data or logical null (RadiusAttribute::isNull() == true) if addition failed

◆ computeCalculateFields()

void pcpp::RadiusLayer::computeCalculateFields ( )
virtual

Calculate and store the value of radius_header::length according to the layer size

Implements pcpp::Layer.

◆ getAttribute()

RadiusAttribute pcpp::RadiusLayer::getAttribute ( uint8_t  attrType) const

Get a RADIUS attribute by attribute type

Parameters
[in]attrTypeRADIUS attribute type
Returns
A RadiusAttribute object containing the first attribute data that matches this type, or logical null (RadiusAttribute::isNull() == true) if no such attribute found

◆ getAttributeCount()

size_t pcpp::RadiusLayer::getAttributeCount ( ) const
Returns
The number of RADIUS attributes in the packet

◆ getAuthenticatorValue()

std::string pcpp::RadiusLayer::getAuthenticatorValue ( ) const
Returns
A hex string representation of the radius_header::authenticator byte array value

◆ getFirstAttribute()

RadiusAttribute pcpp::RadiusLayer::getFirstAttribute ( ) const
Returns
The first RADIUS attribute in the packet. If there are no attributes the returned value will contain a logical null (RadiusAttribute::isNull() == true)

◆ getHeaderLen()

size_t pcpp::RadiusLayer::getHeaderLen ( ) const
virtual
Returns
The size written in radius_header::length

Implements pcpp::Layer.

◆ getNextAttribute()

RadiusAttribute pcpp::RadiusLayer::getNextAttribute ( RadiusAttribute attr) const

Get the RADIUS attribute that comes after a given attribute. If the given attribute was the last one, the returned value will contain a logical null (RadiusAttribute::isNull() == true)

Parameters
[in]attrA given attribute
Returns
A RadiusAttribute object containing the attribute data that comes next, or logical null if the given attribute: (1) was the last one; (2) contains a logical null or (3) doesn't belong to this packet

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getRadiusHeader()

radius_header* pcpp::RadiusLayer::getRadiusHeader ( ) const
inline

Get a pointer to the RADIUS header. Notice this points directly to the data, so every change will change the actual packet data

Returns
A pointer to the radius_header object

◆ getRadiusMessageString()

static std::string pcpp::RadiusLayer::getRadiusMessageString ( uint8_t  radiusMessageCode)
static

A static method that returns the RADIUS message string for a give message code. For example: the string "Access-Request" will be returned for code 1

Parameters
[in]radiusMessageCodeRADIUS message code
Returns
RADIUS message string

◆ isDataValid()

static bool pcpp::RadiusLayer::isDataValid ( const uint8_t *  udpData,
size_t  udpDataLen 
)
static

The static method makes validation of UDP data

Parameters
[in]udpDataThe pointer to the UDP payload data. It points to the first byte of RADIUS header.
[in]udpDataLenThe payload data size
Returns
True if the data is valid and can represent the RADIUS packet

◆ isRadiusPort()

bool pcpp::RadiusLayer::isRadiusPort ( uint16_t  port)
inlinestatic

A static method that checks whether the port is considered as RADIUS

Parameters
[in]portThe port number to be checked

◆ parseNextLayer()

void pcpp::RadiusLayer::parseNextLayer ( )
inlinevirtual

Does nothing for this layer, RADIUS is always last

Implements pcpp::Layer.

◆ removeAllAttributes()

bool pcpp::RadiusLayer::removeAllAttributes ( )

Remove all RADIUS attributes in this layer

Returns
True if all attributes were successfully removed or false if removal failed for some reason

◆ removeAttribute()

bool pcpp::RadiusLayer::removeAttribute ( uint8_t  attrType)

Remove an existing RADIUS attribute from the layer

Parameters
[in]attrTypeThe RADIUS attribute type to remove
Returns
True if the RADIUS attribute was successfully removed or false if type wasn't found or if removal failed

◆ setAuthenticatorValue()

void pcpp::RadiusLayer::setAuthenticatorValue ( const std::string &  authValue)

Setter for radius_header::authenticator

Parameters
[in]authValueA hex string representing the requested authenticator value

◆ toString()

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

Implements pcpp::Layer.