1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 21:14:28 +01:00

Fixed some bugs, added some tests.

This commit is contained in:
Matias Fontanini
2012-08-02 21:21:10 -03:00
parent 383deb8641
commit c4a92d2b96
10 changed files with 223 additions and 152 deletions

View File

@@ -67,7 +67,7 @@ namespace Tins {
*
* \param other The object which will be copied.
*/
ARP(const ARP &other);
//ARP(const ARP &other);
/* Getters */
/**
@@ -75,63 +75,63 @@ namespace Tins {
*
* \return Returns the sender's hardware address in an uint8_t*.
*/
inline const uint8_t* sender_hw_addr() { return this->_arp.ar_sha; }
const uint8_t* sender_hw_addr() const { 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 IPv4Address sender_ip_addr() { return Utils::net_to_host_l(this->_arp.ar_sip); }
IPv4Address sender_ip_addr() const { return Utils::net_to_host_l(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; }
const uint8_t* target_hw_addr() const { 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 IPv4Address target_ip_addr() { return Utils::net_to_host_l(this->_arp.ar_tip); }
IPv4Address target_ip_addr() const { return Utils::net_to_host_l(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 Utils::net_to_host_s(this->_arp.ar_hrd); }
uint16_t hw_addr_format() const { return Utils::net_to_host_s(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 Utils::net_to_host_s(this->_arp.ar_pro); }
uint16_t prot_addr_format() const { return Utils::net_to_host_s(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; }
uint8_t hw_addr_length() const { 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; }
uint8_t prot_addr_length() const { 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 Utils::net_to_host_s(this->_arp.ar_op); }
uint16_t opcode() const { return Utils::net_to_host_s(this->_arp.ar_op); }
/** \brief Getter for the header size.
* \return Returns the ARP header size.

View File

@@ -24,6 +24,7 @@
#include <list>
#include <vector>
#include <string>
#include "bootp.h"
@@ -131,19 +132,6 @@ namespace Tins {
* \brief DHCP options struct.
*/
struct DHCPOption {
/**
* \brief The option number.
*/
uint8_t option;
/**
* \brief The value's length in bytes.
*/
uint8_t length;
/**
* \brief The option's value.
*/
uint8_t *value;
/**
* \brief Creates an instance of DHCPOption.
*
@@ -154,8 +142,24 @@ namespace Tins {
* \param val The option's value.
*/
DHCPOption(uint8_t opt, uint8_t len, const uint8_t *val);
/**
* \brief The option number.
*/
uint8_t option;
/**
* \brief The value's length in bytes.
*/
//uint8_t length;
/**
* \brief The option's value.
*/
//uint8_t *value;
std::vector<uint8_t> value;
};
typedef std::list<DHCPOption> options_type;
/**
* \brief Creates an instance of DHCP.
*
@@ -366,7 +370,7 @@ namespace Tins {
/** \brief Getter for the options list.
* \return The option list.
*/
const std::list<DHCPOption> options() const { return _options; }
const options_type options() const { return _options; }
/**
* \brief Getter for the PDU's type.
@@ -395,8 +399,8 @@ namespace Tins {
template<class T> bool generic_search(Options opt, T *value) {
const DHCPOption *option = search_option(opt);
if(option && option->length == sizeof(T)) {
*value = *(T*)option->value;
if(option && option->value.size() == sizeof(T)) {
*value = *(T*)&option->value[0];
return true;
}
return false;
@@ -408,7 +412,7 @@ namespace Tins {
uint8_t *serialize_list(const std::list<uint32_t> &int_list, uint32_t &sz);
std::list<DHCPOption> _options;
options_type _options;
uint32_t _size;
};
};