PcapPlusPlus  24.09
pcpp::LdapLayer Class Reference

#include <LdapLayer.h>

Inheritance diagram for pcpp::LdapLayer:
pcpp::Layer pcpp::IDataContainer pcpp::LdapBindRequestLayer pcpp::LdapResponseLayer pcpp::LdapSearchRequestLayer pcpp::LdapSearchResultEntryLayer pcpp::LdapUnbindRequestLayer pcpp::LdapAddResponseLayer pcpp::LdapBindResponseLayer pcpp::LdapCompareResponseLayer pcpp::LdapDeleteResponseLayer pcpp::LdapModifyDNResponseLayer pcpp::LdapModifyResponseLayer pcpp::LdapSearchResultDoneLayer

Public Member Functions

 LdapLayer (uint16_t messageId, LdapOperationType operationType, const std::vector< Asn1Record * > &messageRecords, const std::vector< LdapControl > &controls=std::vector< LdapControl >())
 
Asn1SequenceRecordgetRootAsn1Record () const
 
Asn1ConstructedRecordgetLdapOperationAsn1Record () const
 
uint16_t getMessageID () const
 
std::vector< LdapControlgetControls () const
 
virtual LdapOperationType getLdapOperationType () const
 
template<typename Method , typename ResultType >
bool tryGet (Method method, ResultType &result)
 
void parseNextLayer () override
 
size_t getHeaderLen () const override
 
void computeCalculateFields () override
 
OsiModelLayer getOsiModelLayer () const override
 
std::string toString () const override
 
- 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 bool isLdapPort (uint16_t port)
 
static LdapLayerparseLdapMessage (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 

Detailed Description

Represents an LDAP message

Constructor & Destructor Documentation

◆ LdapLayer()

pcpp::LdapLayer::LdapLayer ( uint16_t  messageId,
LdapOperationType  operationType,
const std::vector< Asn1Record * > &  messageRecords,
const std::vector< LdapControl > &  controls = std::vector< LdapControl >() 
)

A constructor to create a new LDAP message

Parameters
[in]messageIdThe LDAP message ID
[in]operationTypeThe LDAP operation type
[in]messageRecordsA vector of ASN.1 records that comprise the LDAP message
[in]controlsA vector of LDAP controls. This is an optional parameter, if not provided the message will be created without LDAP controls

Member Function Documentation

◆ computeCalculateFields()

void pcpp::LdapLayer::computeCalculateFields ( )
inlineoverridevirtual

Each layer can compute field values automatically using this method. This is an abstract method

Implements pcpp::Layer.

◆ getControls()

std::vector<LdapControl> pcpp::LdapLayer::getControls ( ) const
Returns
A vector of LDAP controls in this message. If the message contains no controls then an empty vector is returned. If the Controls ASN.1 record is malformed, an exception is thrown

◆ getHeaderLen()

size_t pcpp::LdapLayer::getHeaderLen ( ) const
inlineoverridevirtual
Returns
The size of the LDAP message

Implements pcpp::Layer.

◆ getLdapOperationAsn1Record()

Asn1ConstructedRecord* pcpp::LdapLayer::getLdapOperationAsn1Record ( ) const
Returns
The ASN.1 record of the specific LDAP operation in this LDAP message. Each operation has a specific structure. If the Operation ASN.1 record is malformed, an exception is thrown

◆ getLdapOperationType()

virtual LdapOperationType pcpp::LdapLayer::getLdapOperationType ( ) const
virtual
Returns
The LDAP operation of this message. If the Operation ASN.1 record is malformed, an exception is thrown

Reimplemented in pcpp::LdapUnbindRequestLayer.

◆ getMessageID()

uint16_t pcpp::LdapLayer::getMessageID ( ) const
Returns
The LDAP message ID. If the ASN.1 record is malformed, an exception is thrown

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getRootAsn1Record()

Asn1SequenceRecord* pcpp::LdapLayer::getRootAsn1Record ( ) const
Returns
The root ASN.1 record of the LDAP message. All of the message data will be under this record. If the Root ASN.1 record is malformed, an exception is thrown

◆ isLdapPort()

static bool pcpp::LdapLayer::isLdapPort ( uint16_t  port)
inlinestatic

A static method that checks whether a source or dest port match those associated with the LDAP protocol

Parameters
[in]portThe port number to check
Returns
True if this is an LDAP port, false otherwise

◆ parseLdapMessage()

static LdapLayer* pcpp::LdapLayer::parseLdapMessage ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
static

A static message to parse an LDAP message from 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
Returns
An instance of LdapLayer if this is indeed an LDAP message, nullptr otherwise

◆ parseNextLayer()

void pcpp::LdapLayer::parseNextLayer ( )
overridevirtual

Tries to identify more LDAP messages in this packet if exist

Implements pcpp::Layer.

◆ toString()

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

Implements pcpp::Layer.

◆ tryGet()

template<typename Method , typename ResultType >
bool pcpp::LdapLayer::tryGet ( Method  method,
ResultType &  result 
)
inline

Most getter methods in this class throw an exception if the corresponding ASN.1 record is invalid. This is a wrapper method that allows calling these getters without adding a try...catch clause. It accepts the getter method and an out variable. It tries to call the getter and if no exception is thrown, the out variable will contain the result.

Here is an example:

uint16_t messageId;
ldapLayer->tryGet(&pcpp::LdapLayer::getMessageID, messageId));
uint16_t getMessageID() const

We call getMessageID(), if no exception is thrown the variable messageId will hold the result

Template Parameters
MethodThe class method type
ResultTypeThe expected result type (for example: uint8_t, std::string, etc.)
Parameters
[in]methodThe class method to call
[out]resultAn outvariable to contain the result if no exception is thrown
Returns
True if no exception was thrown or false otherwise