diff --git a/include/arp.h b/include/arp.h index dacb152..bccaf08 100644 --- a/include/arp.h +++ b/include/arp.h @@ -50,11 +50,132 @@ namespace Tins { /* Getters */ /** - * \brief Getter for the sender's hardware's address. + * \brief Getter for the sender's hardware address. * - * \return The hardware address of the sender in an uint8_t*. + * \return Returns the sender's hardware address in an uint8_t*. */ - inline const uint8_t* sender_hw_address() { return this->_arp.ar_sha; } + inline const uint8_t* sender_hw_addr() { return this->_arp.ar_sha; } + + /** + * \brief Getter for the sender's IP address. + * + * \return Returns the sender's IP address in an uint32_t. + */ + inline const uint32_t sender_ip_addr() { return this->_arp.ar_sip; } + + /** + * \brief Getter for the target's hardware address. + * + * \return Returns the target's hardware address in an uint8_t*. + */ + inline const uint8_t* target_hw_addr() { return this->_arp.ar_tha; } + + /** + * \brief Getter for the target's IP address. + * + * \return Returns the target's IP address in an uint32_t. + */ + inline const uint32_t target_ip_addr() { return this->_arp.ar_tip; } + + /** + * \brief Getter for the hardware address format. + * + * \return Returns the hardware address' format in an uint16_t. + */ + inline uint16_t hw_addr_format() { return this->_arp.ar_hrd; } + + /** + * \brief Getter for the protocol address format. + * + * \return Returns the protocol address' format in an uint16_t. + */ + inline uint16_t prot_addr_format() { return this->_arp.ar_pro; } + + /** + * \brief Getter for the hardware address length. + * + * \return Returns the hardware address' length in an uint8_t. + */ + inline uint8_t hw_addr_length() { return this->_arp.ar_hln; } + + /** + * \brief Getter for the protocol address length. + * + * \return Returns the protocol address' length in an uint8_t. + */ + inline uint8_t prot_addr_length() { return this->_arp.ar_pln; } + + /** + * \brief Getter for the ARP opcode. + * + * \return Returns the ARP opcode in an uint16_t. + */ + inline uint16_t opcode() { return this->_arp.ar_op; } + + /* Setters */ + + /** + * \brief Setter for the sender's hardware address. + * + * \param new_snd_hw_addr uint8_t array containing the new sender's hardware address. + */ + void sender_hw_addr(uint8_t* new_snd_hw_addr); + + /** + * \brief Setter for the sender's IP address. + * + * \param new_snd_ip_addr uint32_t containing the new sender's IP address. + */ + void sender_ip_addr(uint32_t new_snd_ip_addr); + + /** + * \brief Setter for the target's hardware address. + * + * \param new_tgt_hw_addr uint8_t array containing the new target's hardware address. + */ + void target_hw_addr(uint8_t* new_tgt_hw_addr); + + /** + * \brief Setter for the target's IP address. + * + * \param new_tgt_ip_addr uint32_t containing the new target's IP address. + */ + void target_ip_addr(uint32_t new_tgt_ip_addr); + + /** + * \brief Setter for the hardware address format. + * + * \param new_hw_addr_fmt uint16_t with the new hardware address' format. + */ + void hw_addr_format(uint16_t new_hw_addr_fmt); + + /** + * \brief Setter for the protocol address format. + * + * \param new_prot_addr_fmt uint16_t with the new protocol address' format. + */ + void prot_addr_format(uint16_t new_prot_addr_fmt); + + /** + * \brief Setter for the hardware address length. + * + * \param new_hw_addr_len uint8_t with the new hardware address' length. + */ + void hw_addr_length(uint8_t new_hw_addr_len); + + /** + * \brief Setter for the protocol address length. + * + * \param new_prot_addr_len uint8_t with the new protocol address' length. + */ + void prot_addr_length(uint8_t new_prot_addr_len); + + /** + * \brief Setter for the ARP opcode. + * + * \param new_opcode Flag enum value of the ARP opcode to set. + */ + void opcode(Flags new_opcode); PDUType pdu_type() const { return PDU::ARP; } diff --git a/src/arp.cpp b/src/arp.cpp index b5ef713..eaf9dc1 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -37,6 +37,42 @@ Tins::ARP::ARP() : PDU(0x0608) { _arp.ar_pln = 4; } +void Tins::ARP::sender_hw_addr(uint8_t* new_snd_hw_addr) { + memcpy(this->_arp.ar_sha, new_snd_hw_addr, 6); //Should this use hardware address' length? +} + +void Tins::ARP::sender_ip_addr(uint32_t new_snd_ip_addr) { + this->_arp.ar_sip = new_snd_ip_addr; +} + +void Tins::ARP::target_hw_addr(uint8_t* new_tgt_hw_addr) { + memcpy(this->_arp.ar_tha, new_tgt_hw_addr, 6); //Should this use hardware address' length? +} + +void Tins::ARP::target_ip_addr(uint32_t new_tgt_ip_addr) { + this->_arp.ar_tip = new_tgt_ip_addr; +} + +void Tins::ARP::hw_addr_format(uint16_t new_hw_addr_fmt) { + this->_arp.ar_hrd = new_hw_addr_fmt; +} + +void Tins::ARP::prot_addr_format(uint16_t new_prot_addr_fmt) { + this->_arp.ar_pro = new_prot_addr_fmt; +} + +void Tins::ARP::hw_addr_length(uint8_t new_hw_addr_len) { + this->_arp.ar_hln = new_hw_addr_len; +} + +void Tins::ARP::prot_addr_length(uint8_t new_prot_addr_len) { + this->_arp.ar_pln = new_prot_addr_len; +} + +void Tins::ARP::opcode(Flags new_opcode) { + this->_arp.ar_op = new_opcode; +} + void Tins::ARP::set_arp_request(const string &ip_dst, const string &ip_src, const string &hw_src) { _arp.ar_tip = Utils::resolve_ip(ip_dst); _arp.ar_sip = Utils::resolve_ip(ip_src);