mirror of
https://github.com/mfontanini/libtins
synced 2026-01-26 20:01:35 +01:00
Documented many header files. Done some minor code refactoring over PDU::clone_packet.
This commit is contained in:
@@ -39,12 +39,15 @@ namespace Tins {
|
||||
* \brief Enum which indicates the type of ARP packet.
|
||||
*/
|
||||
enum Flags {
|
||||
REQUEST = 0x0100,
|
||||
REPLY = 0x0200
|
||||
REQUEST = 0x0001,
|
||||
REPLY = 0x0002
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Default constructor for ARP PDU objects.
|
||||
*
|
||||
* ARP requests and replies can be constructed easily using
|
||||
* ARP::make_arp_request/reply static functions.
|
||||
*/
|
||||
ARP();
|
||||
|
||||
@@ -112,6 +115,11 @@ namespace Tins {
|
||||
*/
|
||||
inline uint16_t opcode() { return this->_arp.ar_op; }
|
||||
|
||||
/** \brief Getter for the header size.
|
||||
* \return Returns the ARP header size.
|
||||
* \sa PDU::header_size
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
/* Setters */
|
||||
|
||||
/**
|
||||
@@ -176,27 +184,11 @@ namespace Tins {
|
||||
* \param new_opcode Flag enum value of the ARP opcode to set.
|
||||
*/
|
||||
void opcode(Flags new_opcode);
|
||||
|
||||
/** \brief Check wether ptr points to a valid response for this PDU.
|
||||
*
|
||||
* \sa PDU::matches_response
|
||||
* \param ptr The pointer to the buffer.
|
||||
* \param total_sz The size of the buffer.
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
bool matches_response(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
uint32_t header_size() const;
|
||||
|
||||
/** \brief Clones this pdu, filling the corresponding header with data
|
||||
* extracted from a buffer.
|
||||
*
|
||||
* \param ptr The pointer to the from from which the data will be extracted.
|
||||
* \param total_sz The size of the buffer.
|
||||
* \return The cloned PDU.
|
||||
* \sa PDU::clone_packet
|
||||
*/
|
||||
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
PDUType pdu_type() const { return PDU::ARP; }
|
||||
|
||||
/**
|
||||
@@ -281,6 +273,24 @@ namespace Tins {
|
||||
* \param hw_snd uint8_t array of 6 bytes containing the sender's hardware address.
|
||||
*/
|
||||
void set_arp_reply(const std::string& ip_tgt, const std::string& ip_snd, const uint8_t* hw_tgt, const uint8_t* hw_snd);
|
||||
|
||||
/** \brief Check wether ptr points to a valid response for this PDU.
|
||||
*
|
||||
* \sa PDU::matches_response
|
||||
* \param ptr The pointer to the buffer.
|
||||
* \param total_sz The size of the buffer.
|
||||
*/
|
||||
bool matches_response(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
/** \brief Clones this pdu, filling the corresponding header with data
|
||||
* extracted from a buffer.
|
||||
*
|
||||
* \param ptr The pointer to the from from which the data will be extracted.
|
||||
* \param total_sz The size of the buffer.
|
||||
* \return The cloned PDU.
|
||||
* \sa PDU::clone_packet
|
||||
*/
|
||||
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
private:
|
||||
struct arphdr {
|
||||
|
||||
@@ -147,6 +147,10 @@ namespace Tins {
|
||||
*/
|
||||
PDU *recv_response(PacketSender *sender);
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::ETHERNET_II; }
|
||||
|
||||
/** \brief Clones this pdu, filling the corresponding header with data
|
||||
|
||||
@@ -150,11 +150,13 @@ namespace Tins {
|
||||
*/
|
||||
uint8_t code() const { return _icmp.code; }
|
||||
|
||||
/** \brief Returns the echo id.
|
||||
/** \brief Getter for the echo id.
|
||||
* \return Returns the echo id.
|
||||
*/
|
||||
uint16_t id() const { return _icmp.un.echo.id; }
|
||||
|
||||
/** \brief Returns the echo sequence number.
|
||||
/** \brief Getter for the echo sequence number.
|
||||
* \return Returns the echo sequence number.
|
||||
*/
|
||||
uint16_t sequence() const { return _icmp.un.echo.sequence; }
|
||||
|
||||
@@ -166,7 +168,11 @@ namespace Tins {
|
||||
uint32_t header_size() const;
|
||||
|
||||
bool matches_response(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::ICMP; }
|
||||
|
||||
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
@@ -123,7 +123,11 @@ namespace Tins {
|
||||
bool matches_response(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
PDU *recv_response(PacketSender *sender);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::IP; }
|
||||
|
||||
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
@@ -157,10 +157,24 @@ namespace Tins {
|
||||
*/
|
||||
virtual PDU *clone_packet(uint8_t *ptr, uint32_t total_sz) { return 0; }
|
||||
protected:
|
||||
/* Serialize this PDU storing the result in buffer. */
|
||||
/** \brief Serializes this PDU and propagates this action to child PDUs.
|
||||
*
|
||||
* \param buffer The buffer in which to store this PDU's serialization.
|
||||
* \param total_sz The total size of the buffer.
|
||||
* \param parent The parent PDU. Will be 0 if there's the parent does not exist.
|
||||
*/
|
||||
void serialize(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
/** \brief Clones the inner pdu(if any).
|
||||
*
|
||||
* This method clones the inner pdu using data from a buffer.
|
||||
* \param ptr The pointer from which the child PDU must be cloned.
|
||||
* \param total_sz The total size of the buffer.
|
||||
* \return Returns the cloned PDU. Will be 0 if cloning failed.
|
||||
*/
|
||||
PDU *clone_inner_pdu(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
/** \brief Serialices this TCP PDU.
|
||||
/** \brief Serializes this TCP PDU.
|
||||
*
|
||||
* Each PDU must override this method and implement it's own
|
||||
* serialization.
|
||||
@@ -170,7 +184,25 @@ namespace Tins {
|
||||
*/
|
||||
virtual void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) = 0;
|
||||
|
||||
/** \brief Does the 16 bits sum of all 2 bytes elements between start and end.
|
||||
*
|
||||
* This is the checksum used by IP, UDP and TCP. If there's and odd number of
|
||||
* bytes, the last one is padded and added to the checksum. The checksum is performed
|
||||
* using network endiannes.
|
||||
* \param start The pointer to the start of the buffer.
|
||||
* \param end The pointer to the end of the buffer(excluding the last element).
|
||||
* \return Returns the checksum between start and end(non inclusive).
|
||||
*/
|
||||
static uint32_t do_checksum(uint8_t *start, uint8_t *end);
|
||||
|
||||
/** \brief Performs the pseudo header checksum used in TCP and UDP PDUs.
|
||||
*
|
||||
* \param source_ip The source ip address.
|
||||
* \param dest_ip The destination ip address.
|
||||
* \param len The length to be included in the pseudo header.
|
||||
* \param flag The flag to use in the protocol field of the pseudo header.
|
||||
* \return The pseudo header checksum.
|
||||
*/
|
||||
static uint32_t pseudoheader_checksum(uint32_t source_ip, uint32_t dest_ip, uint32_t len, uint32_t flag);
|
||||
private:
|
||||
uint32_t _flag;
|
||||
|
||||
@@ -50,6 +50,10 @@ namespace Tins {
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::RAW; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -189,6 +189,10 @@ namespace Tins {
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::TCP; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -82,7 +82,11 @@ namespace Tins {
|
||||
* payload and options size. \sa PDU::header_size
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
* \sa PDU::pdu_type
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::UDP; }
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user