mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 04:34:27 +01:00
Fixed endianess issues in several classes. Everything is working on big endian architectures so far.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "bootp.h"
|
||||
#include "ipaddress.h"
|
||||
|
||||
|
||||
namespace Tins {
|
||||
@@ -152,14 +153,10 @@ namespace Tins {
|
||||
* \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;
|
||||
};
|
||||
|
||||
@@ -220,14 +217,14 @@ namespace Tins {
|
||||
* \param ip The ip of the server.
|
||||
* \return True if the option was added successfully. \sa DHCP::add_option
|
||||
*/
|
||||
bool add_server_identifier(uint32_t ip);
|
||||
bool add_server_identifier(IPv4Address ip);
|
||||
|
||||
/**
|
||||
* \brief Searchs for a server identifier option.
|
||||
* \param value A pointer in which the option's value will be stored.
|
||||
* \return True if the option was found, false otherwise.
|
||||
*/
|
||||
bool search_server_identifier(uint32_t *value);
|
||||
bool search_server_identifier(IPv4Address *value);
|
||||
|
||||
/**
|
||||
* \brief Adds an IP address lease time option.
|
||||
@@ -276,70 +273,70 @@ namespace Tins {
|
||||
* \param mask The subnet mask.
|
||||
* \return True if the option was added successfully. \sa DHCP::add_option
|
||||
*/
|
||||
bool add_subnet_mask(uint32_t mask);
|
||||
bool add_subnet_mask(IPv4Address mask);
|
||||
|
||||
/**
|
||||
* \brief Searchs for a subnet mask option.
|
||||
* \param value A pointer in which the option's value will be stored.
|
||||
* \return True if the option was found, false otherwise.
|
||||
*/
|
||||
bool search_subnet_mask(uint32_t *value);
|
||||
bool search_subnet_mask(IPv4Address *value);
|
||||
|
||||
/**
|
||||
* \brief Adds a routers option.
|
||||
* \param routers A list of ip addresses in integer notation.
|
||||
* \param routers A list of ip addresses.
|
||||
* \return True if the option was added successfully. \sa DHCP::add_option
|
||||
*/
|
||||
bool add_routers_option(const std::list<uint32_t> &routers);
|
||||
bool add_routers_option(const std::list<IPv4Address> &routers);
|
||||
|
||||
/**
|
||||
* \brief Searchs for a routers option.
|
||||
* \param routers A pointer in which the option's value will be stored.
|
||||
* \return True if the option was found, false otherwise.
|
||||
*/
|
||||
bool search_routers_option(std::list<uint32_t> *routers);
|
||||
bool search_routers_option(std::list<IPv4Address> *routers);
|
||||
|
||||
/**
|
||||
* \brief Adds a domain name servers option.
|
||||
* \param dns A list of ip addresses in integer notation.
|
||||
* \param dns A list of ip addresses.
|
||||
* \return True if the option was added successfully. \sa DHCP::add_option
|
||||
*/
|
||||
bool add_dns_option(const std::list<uint32_t> &dns);
|
||||
bool add_dns_option(const std::list<IPv4Address> &dns);
|
||||
|
||||
/**
|
||||
* \brief Searchs for a dns option.
|
||||
* \param dns A pointer in which the option's value will be stored.
|
||||
* \return True if the option was found, false otherwise.
|
||||
*/
|
||||
bool search_dns_option(std::list<uint32_t> *dns);
|
||||
bool search_dns_option(std::list<IPv4Address> *dns);
|
||||
|
||||
/**
|
||||
* \brief Adds a broadcast address option.
|
||||
* \param addr The broadcast address.
|
||||
* \return True if the option was added successfully. \sa DHCP::add_option
|
||||
*/
|
||||
bool add_broadcast_option(uint32_t addr);
|
||||
bool add_broadcast_option(IPv4Address addr);
|
||||
|
||||
/**
|
||||
* \brief Searchs for a broadcast option.
|
||||
* \param value A pointer in which the option's value will be stored.
|
||||
* \return True if the option was found, false otherwise.
|
||||
*/
|
||||
bool search_broadcast_option(uint32_t *value);
|
||||
bool search_broadcast_option(IPv4Address *value);
|
||||
|
||||
/**
|
||||
* \brief Adds a requested address option.
|
||||
* \param addr The requested address.
|
||||
* \return True if the option was added successfully. \sa DHCP::add_option
|
||||
*/
|
||||
bool add_requested_ip_option(uint32_t addr);
|
||||
bool add_requested_ip_option(IPv4Address addr);
|
||||
|
||||
/**
|
||||
* \brief Searchs for a requested option.
|
||||
* \param value A pointer in which the option's value will be stored.
|
||||
* \return True if the option was found, false otherwise.
|
||||
*/
|
||||
bool search_requested_ip_option(uint32_t *value);
|
||||
bool search_requested_ip_option(IPv4Address *value);
|
||||
|
||||
/**
|
||||
* \brief Adds a domain name option.
|
||||
@@ -385,7 +382,8 @@ namespace Tins {
|
||||
void copy_fields(const DHCP *other);
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
template<class T> bool generic_search(Options opt, T *value) {
|
||||
template<class T>
|
||||
bool generic_search(Options opt, T *value) {
|
||||
const DHCPOption *option = search_option(opt);
|
||||
if(option && option->value.size() == sizeof(T)) {
|
||||
*value = *(T*)&option->value[0];
|
||||
@@ -394,11 +392,14 @@ namespace Tins {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool generic_search(Options opt, std::list<IPv4Address> *container);
|
||||
bool generic_search(Options opt, std::list<uint32_t> *container);
|
||||
bool generic_search(Options opt, std::string *str);
|
||||
bool generic_search(Options opt, uint32_t *value);
|
||||
bool generic_search(Options opt, IPv4Address *value);
|
||||
|
||||
uint8_t *serialize_list(const std::list<uint32_t> &int_list, uint32_t &sz);
|
||||
uint8_t *serialize_list(const std::list<IPv4Address> &ip_list, uint32_t &sz);
|
||||
|
||||
options_type _options;
|
||||
uint32_t _size;
|
||||
|
||||
@@ -480,17 +480,31 @@ namespace Tins {
|
||||
private:
|
||||
struct dnshdr {
|
||||
uint16_t id;
|
||||
uint16_t
|
||||
rd:1,
|
||||
tc:1,
|
||||
aa:1,
|
||||
opcode:4,
|
||||
qr:1,
|
||||
rcode:4,
|
||||
cd:1,
|
||||
ad:1,
|
||||
z:1,
|
||||
ra:1;
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
uint16_t
|
||||
rd:1,
|
||||
tc:1,
|
||||
aa:1,
|
||||
opcode:4,
|
||||
qr:1,
|
||||
rcode:4,
|
||||
cd:1,
|
||||
ad:1,
|
||||
z:1,
|
||||
ra:1;
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
uint16_t
|
||||
qr:1,
|
||||
opcode:4,
|
||||
aa:1,
|
||||
tc:1,
|
||||
rd:1,
|
||||
ra:1,
|
||||
z:1,
|
||||
ad:1,
|
||||
cd:1,
|
||||
rcode:4;
|
||||
#endif
|
||||
uint16_t questions, answers,
|
||||
authority, additional;
|
||||
} __attribute__((packed));
|
||||
|
||||
@@ -319,28 +319,53 @@ namespace Tins {
|
||||
uint8_t ssap;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct info_control_field {
|
||||
uint16_t
|
||||
type_bit:1,
|
||||
send_seq_num:7,
|
||||
poll_final_bit:1,
|
||||
recv_seq_num:7;
|
||||
} __attribute__((__packed__));
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
struct info_control_field {
|
||||
uint16_t
|
||||
type_bit:1,
|
||||
send_seq_num:7,
|
||||
poll_final_bit:1,
|
||||
recv_seq_num:7;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct super_control_field {
|
||||
uint16_t type_bit:2,
|
||||
supervisory_func:2,
|
||||
unused:4,
|
||||
poll_final_bit:1,
|
||||
recv_seq_num:7;
|
||||
} __attribute__((__packed__));
|
||||
struct super_control_field {
|
||||
uint16_t type_bit:2,
|
||||
supervisory_func:2,
|
||||
unused:4,
|
||||
poll_final_bit:1,
|
||||
recv_seq_num:7;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct un_control_field {
|
||||
uint8_t type_bits:2,
|
||||
mod_func1:2,
|
||||
poll_final_bit:1,
|
||||
mod_func2:3;
|
||||
} __attribute__((__packed__));
|
||||
struct un_control_field {
|
||||
uint8_t type_bits:2,
|
||||
mod_func1:2,
|
||||
poll_final_bit:1,
|
||||
mod_func2:3;
|
||||
} __attribute__((__packed__));
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
struct info_control_field {
|
||||
uint16_t send_seq_num:7,
|
||||
type_bit:1,
|
||||
recv_seq_num:7,
|
||||
poll_final_bit:1;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct super_control_field {
|
||||
uint16_t unused:4,
|
||||
supervisory_func:2,
|
||||
type_bit:2,
|
||||
recv_seq_num:7,
|
||||
poll_final_bit:1;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct un_control_field {
|
||||
uint8_t mod_func2:3,
|
||||
poll_final_bit:1,
|
||||
mod_func1:2,
|
||||
type_bits:2;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
#endif
|
||||
|
||||
void copy_fields(const LLC *other);
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
@@ -156,11 +156,19 @@ namespace Tins {
|
||||
struct snaphdr {
|
||||
uint8_t dsap;
|
||||
uint8_t ssap;
|
||||
uint32_t id:2,
|
||||
reserved1:2,
|
||||
poll:2,
|
||||
reserved2:2,
|
||||
org_code:24;
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
uint32_t id:2,
|
||||
reserved1:2,
|
||||
poll:2,
|
||||
reserved2:2,
|
||||
org_code:24;
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
uint32_t reserved1:2,
|
||||
poll:2,
|
||||
reserved2:2,
|
||||
id:2,
|
||||
org_code:24;
|
||||
#endif
|
||||
uint16_t eth_type;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
#include "hwaddress.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
#define TINS_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
|
||||
#define TINS_IS_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
* \brief Network utils namespace.
|
||||
@@ -183,7 +186,7 @@ namespace Tins {
|
||||
(change_endian(((uint32_t)(data >> 32)))));
|
||||
}
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
/**
|
||||
* \brief Convert any integral type to big endian.
|
||||
*
|
||||
@@ -225,7 +228,7 @@ namespace Tins {
|
||||
inline T le_to_host(T data) {
|
||||
return data;
|
||||
}
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
/**
|
||||
* \brief Convert any integral type to big endian.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user