Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/github_actions/dev/actions-depende…
Browse files Browse the repository at this point in the history
…ncies-9f9ef44f47
  • Loading branch information
tigercosmos authored Feb 3, 2025
2 parents 2b15042 + 80277e1 commit b58e835
Show file tree
Hide file tree
Showing 81 changed files with 9,766 additions and 14,586 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ repos:
- id: cppcheck
args: ["--std=c++11", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr", "--force"]
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.17.1
rev: 0.18.2
hooks:
- id: gersemi
args: ["-c"]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
pass_filenames: false
- repo: https://github.com/crate-ci/typos
rev: codespell-dict-v0.5.0
rev: typos-dict-v0.12.4
hooks:
- id: typos
args: ['--config=typos-config.toml']
Expand Down
21 changes: 17 additions & 4 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,28 @@ static struct _light_option *__parse_options(uint32_t **memory, const int32_t ma
opt->custom_option_code = *local_memory++;
opt->option_length = *local_memory++;

// PCPP patch
// Validate option_length
if (opt->option_length > max_len - 2 * sizeof(*local_memory)) {
free(opt);
return NULL;
}
// PCPP patch end

actual_length = (opt->option_length % alignment) == 0 ?
opt->option_length :
(opt->option_length / alignment + 1) * alignment;

if (actual_length > 0) {
opt->data = calloc(1, actual_length);
memcpy(opt->data, local_memory, actual_length);
local_memory += (sizeof(**memory) / sizeof(*local_memory)) * (actual_length / alignment);
// PCPP patch
// Validate actual_length
if (actual_length <= 0 || actual_length > max_len - 2 * sizeof(*local_memory)) {
free(opt);
return NULL;
}
opt->data = calloc(1, actual_length);
memcpy(opt->data, local_memory, actual_length);
local_memory += (sizeof(**memory) / sizeof(*local_memory)) * (actual_length / alignment);
// PCPP patch end

*memory = (uint32_t*)local_memory;
remaining_size = max_len - actual_length - 2 * sizeof(*local_memory);
Expand Down
133 changes: 50 additions & 83 deletions Packet++/header/ArpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,165 +6,132 @@

/// @file

/**
* \namespace pcpp
* \brief The main namespace for the PcapPlusPlus lib
*/
/// @namespace pcpp
/// @brief The main namespace for the PcapPlusPlus lib
namespace pcpp
{

/**
* @struct arphdr
* Represents an ARP protocol header
*/
/// @struct arphdr
/// Represents an ARP protocol header
#pragma pack(push, 1)
struct arphdr
{
/** Hardware type (HTYPE) */
/// Hardware type (HTYPE)
uint16_t hardwareType;
/** Protocol type (PTYPE). The permitted PTYPE values share a numbering space with those for EtherType */
/// Protocol type (PTYPE). The permitted PTYPE values share a numbering space with those for EtherType
uint16_t protocolType;
/** Hardware address length (HLEN). For IPv4, this has the value 0x0800 */
/// Hardware address length (HLEN). For IPv4, this has the value 0x0800
uint8_t hardwareSize;
/** Protocol length (PLEN). Length (in octets) of addresses used in the upper layer protocol. (The upper layer
* protocol specified in PTYPE.) IPv4 address size is 4 */
/// Protocol length (PLEN). Length (in octets) of addresses used in the upper layer protocol. (The upper layer
/// protocol specified in PTYPE.) IPv4 address size is 4
uint8_t protocolSize;
/** Specifies the operation that the sender is performing: 1 (::ARP_REQUEST) for request, 2 (::ARP_REPLY) for
* reply */
/// Specifies the operation that the sender is performing: 1 (::ARP_REQUEST) for request, 2 (::ARP_REPLY) for
/// reply
uint16_t opcode;
/** Sender hardware address (SHA) */
/// Sender hardware address (SHA)
uint8_t senderMacAddr[6];
/** Sender protocol address (SPA) */
/// Sender protocol address (SPA)
uint32_t senderIpAddr;
/** Target hardware address (THA) */
/// Target hardware address (THA)
uint8_t targetMacAddr[6];
/** Target protocol address (TPA) */
/// Target protocol address (TPA)
uint32_t targetIpAddr;
};
#pragma pack(pop)

/**
* An enum for ARP message type
*/
/// An enum for ARP message type
enum ArpOpcode
{
ARP_REQUEST = 0x0001, ///< ARP request
ARP_REPLY = 0x0002 ///< ARP reply (response)
};

/**
* @class ArpLayer
* Represents an ARP protocol layer. Currently only IPv4 ARP messages are supported
*/
/// @class ArpLayer
/// Represents an ARP protocol layer. Currently only IPv4 ARP messages are supported
class ArpLayer : public Layer
{
public:
/**
* A constructor that creates the layer from an existing packet raw data
* @param[in] data A pointer to the raw data (will be casted to @ref arphdr)
* @param[in] dataLen Size of the data in bytes
* @param[in] prevLayer A pointer to the previous layer
* @param[in] packet A pointer to the Packet instance where layer will be stored in
*/
/// A constructor that creates the layer from an existing packet raw data
/// @param[in] data A pointer to the raw data (will be casted to @ref arphdr)
/// @param[in] dataLen Size of the data in bytes
/// @param[in] prevLayer A pointer to the previous layer
/// @param[in] packet A pointer to the Packet instance where layer will be stored in
ArpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
: Layer(data, dataLen, prevLayer, packet, ARP)
{
m_DataLen = sizeof(arphdr);
}

/**
* A constructor that allocates a new ARP header
* @param[in] opCode ARP message type (ARP request or ARP reply)
* @param[in] senderMacAddr The sender MAC address (will be put in arphdr#senderMacAddr)
* @param[in] targetMacAddr The target MAC address (will be put in arphdr#targetMacAddr)
* @param[in] senderIpAddr The sender IP address (will be put in arphdr#senderIpAddr)
* @param[in] targetIpAddr The target IP address (will be put in arphdr#targetIpAddr)
*/
/// A constructor that allocates a new ARP header
/// @param[in] opCode ARP message type (ARP request or ARP reply)
/// @param[in] senderMacAddr The sender MAC address (will be put in arphdr#senderMacAddr)
/// @param[in] targetMacAddr The target MAC address (will be put in arphdr#targetMacAddr)
/// @param[in] senderIpAddr The sender IP address (will be put in arphdr#senderIpAddr)
/// @param[in] targetIpAddr The target IP address (will be put in arphdr#targetIpAddr)
ArpLayer(ArpOpcode opCode, const MacAddress& senderMacAddr, const MacAddress& targetMacAddr,
const IPv4Address& senderIpAddr, const IPv4Address& targetIpAddr);

~ArpLayer() override = default;

/**
* Get a pointer to the ARP header. Notice this points directly to the data, so every change will change the
* actual packet data
* @return A pointer to the @ref arphdr
*/
/// Get a pointer to the ARP header. Notice this points directly to the data, so every change will change the
/// actual packet data
/// @return A pointer to the @ref arphdr
inline arphdr* getArpHeader() const
{
return reinterpret_cast<arphdr*>(m_Data);
}

/**
* Get the sender hardware address (SHA) in the form of MacAddress
* @return A MacAddress containing the sender hardware address (SHA)
*/
/// Get the sender hardware address (SHA) in the form of MacAddress
/// @return A MacAddress containing the sender hardware address (SHA)
inline MacAddress getSenderMacAddress() const
{
return MacAddress(getArpHeader()->senderMacAddr);
}

/**
* Get the target hardware address (THA) in the form of MacAddress
* @return A MacAddress containing the target hardware address (THA)
*/
/// Get the target hardware address (THA) in the form of MacAddress
/// @return A MacAddress containing the target hardware address (THA)
inline MacAddress getTargetMacAddress() const
{
return MacAddress(getArpHeader()->targetMacAddr);
}

/**
* Get the sender protocol address (SPA) in the form of IPv4Address
* @return An IPv4Address containing the sender protocol address (SPA)
*/
/// Get the sender protocol address (SPA) in the form of IPv4Address
/// @return An IPv4Address containing the sender protocol address (SPA)
inline IPv4Address getSenderIpAddr() const
{
return getArpHeader()->senderIpAddr;
}

/**
* Get the target protocol address (TPA) in the form of IPv4Address
* @return An IPv4Address containing the target protocol address (TPA)
*/
/// Get the target protocol address (TPA) in the form of IPv4Address
/// @return An IPv4Address containing the target protocol address (TPA)
inline IPv4Address getTargetIpAddr() const
{
return getArpHeader()->targetIpAddr;
}

// implement abstract methods

/**
* Does nothing for this layer (ArpLayer is always last)
*/
/// Does nothing for this layer (ArpLayer is always last)
void parseNextLayer() override
{}

/**
* @return The size of @ref arphdr
*/
/// @return The size of @ref arphdr
size_t getHeaderLen() const override
{
return sizeof(arphdr);
}

/**
* Calculate the following fields:
* - @ref arphdr#hardwareType = Ethernet (1)
* - @ref arphdr#hardwareSize = 6
* - @ref arphdr#protocolType = ETHERTYPE_IP (assume IPv4 over ARP)
* - @ref arphdr#protocolSize = 4 (assume IPv4 over ARP)
* - if it's an ARP request: @ref arphdr#targetMacAddr = MacAddress("00:00:00:00:00:00")
*/
/// Calculate the following fields:
/// - @ref arphdr#hardwareType = Ethernet (1)
/// - @ref arphdr#hardwareSize = 6
/// - @ref arphdr#protocolType = ETHERTYPE_IP (assume IPv4 over ARP)
/// - @ref arphdr#protocolSize = 4 (assume IPv4 over ARP)
/// - if it's an ARP request: @ref arphdr#targetMacAddr = MacAddress("00:00:00:00:00:00")
void computeCalculateFields() override;

/**
* Is this packet an ARP request?
*/
/// Is this packet an ARP request?
bool isRequest() const;

/**
* Is this packet an ARP reply?
*/
/// Is this packet an ARP reply?
bool isReply() const;

std::string toString() const override;
Expand Down
Loading

0 comments on commit b58e835

Please sign in to comment.