1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-25 19:51:34 +01:00

Fixed endianess issues in several classes. Everything is working on big endian architectures so far.

This commit is contained in:
Matias Fontanini
2012-08-21 00:03:55 -03:00
parent 3ef29f831b
commit 80198909eb
12 changed files with 281 additions and 134 deletions

View File

@@ -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;

View File

@@ -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));

View File

@@ -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);

View File

@@ -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__));

View File

@@ -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.
*

View File

@@ -98,19 +98,20 @@ const DHCP::DHCPOption *DHCP::search_option(Options opt) const{
}
bool DHCP::add_type_option(Flags type) {
return add_option(DHCP_MESSAGE_TYPE, sizeof(uint8_t), (const uint8_t*)&type);
uint8_t int_type = type;
return add_option(DHCP_MESSAGE_TYPE, sizeof(uint8_t), &int_type);
}
bool DHCP::search_type_option(uint8_t *value) {
return generic_search(DHCP_MESSAGE_TYPE, value);
}
bool DHCP::add_server_identifier(uint32_t ip) {
ip = Utils::host_to_be(ip);
return add_option(DHCP_SERVER_IDENTIFIER, sizeof(uint32_t), (const uint8_t*)&ip);
bool DHCP::add_server_identifier(IPv4Address ip) {
uint32_t ip_int = ip;
return add_option(DHCP_SERVER_IDENTIFIER, sizeof(uint32_t), (const uint8_t*)&ip_int);
}
bool DHCP::search_server_identifier(uint32_t *value) {
bool DHCP::search_server_identifier(IPv4Address *value) {
return generic_search(DHCP_SERVER_IDENTIFIER, value);
}
@@ -132,16 +133,16 @@ bool DHCP::search_renewal_time(uint32_t *value) {
return generic_search(DHCP_RENEWAL_TIME, value);
}
bool DHCP::add_subnet_mask(uint32_t mask) {
mask = Utils::host_to_be(mask);
return add_option(SUBNET_MASK, sizeof(uint32_t), (const uint8_t*)&mask);
bool DHCP::add_subnet_mask(IPv4Address mask) {
uint32_t mask_int = mask;
return add_option(SUBNET_MASK, sizeof(uint32_t), (const uint8_t*)&mask_int);
}
bool DHCP::search_subnet_mask(uint32_t *value) {
bool DHCP::search_subnet_mask(IPv4Address *value) {
return generic_search(SUBNET_MASK, value);
}
bool DHCP::add_routers_option(const list<uint32_t> &routers) {
bool DHCP::add_routers_option(const list<IPv4Address> &routers) {
uint32_t size;
uint8_t *buffer = serialize_list(routers, size);
bool ret = add_option(ROUTERS, size, buffer);
@@ -149,11 +150,11 @@ bool DHCP::add_routers_option(const list<uint32_t> &routers) {
return ret;
}
bool DHCP::search_routers_option(std::list<uint32_t> *routers) {
bool DHCP::search_routers_option(std::list<IPv4Address> *routers) {
return generic_search(ROUTERS, routers);
}
bool DHCP::add_dns_option(const list<uint32_t> &dns) {
bool DHCP::add_dns_option(const list<IPv4Address> &dns) {
uint32_t size;
uint8_t *buffer = serialize_list(dns, size);
bool ret = add_option(DOMAIN_NAME_SERVERS, size, buffer);
@@ -161,25 +162,25 @@ bool DHCP::add_dns_option(const list<uint32_t> &dns) {
return ret;
}
bool DHCP::search_dns_option(std::list<uint32_t> *dns) {
bool DHCP::search_dns_option(std::list<IPv4Address> *dns) {
return generic_search(DOMAIN_NAME_SERVERS, dns);
}
bool DHCP::add_broadcast_option(uint32_t addr) {
addr = Utils::host_to_be(addr);
return add_option(BROADCAST_ADDRESS, sizeof(uint32_t), (uint8_t*)&addr);
bool DHCP::add_broadcast_option(IPv4Address addr) {
uint32_t int_addr = addr;
return add_option(BROADCAST_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr);
}
bool DHCP::search_broadcast_option(uint32_t *value) {
bool DHCP::search_broadcast_option(IPv4Address *value) {
return generic_search(BROADCAST_ADDRESS, value);
}
bool DHCP::add_requested_ip_option(uint32_t addr) {
addr = Utils::host_to_be(addr);
return add_option(DHCP_REQUESTED_ADDRESS, sizeof(uint32_t), (uint8_t*)&addr);
bool DHCP::add_requested_ip_option(IPv4Address addr) {
uint32_t int_addr = addr;
return add_option(DHCP_REQUESTED_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr);
}
bool DHCP::search_requested_ip_option(uint32_t *value) {
bool DHCP::search_requested_ip_option(IPv4Address *value) {
return generic_search(DHCP_REQUESTED_ADDRESS, value);
}
@@ -209,6 +210,16 @@ uint8_t *DHCP::serialize_list(const list<uint32_t> &int_list, uint32_t &sz) {
return buffer;
}
uint8_t *DHCP::serialize_list(const list<IPv4Address> &ip_list, uint32_t &sz) {
uint8_t *buffer = new uint8_t[ip_list.size() * sizeof(uint32_t)];
uint32_t *ptr = (uint32_t*)buffer;
for(list<IPv4Address>::const_iterator it = ip_list.begin(); it != ip_list.end(); ++it)
*(ptr++) = Utils::host_to_be(*it);
sz = sizeof(uint32_t) * ip_list.size();
return buffer;
}
uint32_t DHCP::header_size() const {
return BootP::header_size() - vend_size() + _size;
}
@@ -257,6 +268,21 @@ bool DHCP::generic_search(Options opt, std::list<uint32_t> *container) {
return true;
}
bool DHCP::generic_search(Options opt, std::list<IPv4Address> *container) {
const DHCPOption *option = search_option(opt);
if(!option)
return false;
const uint32_t *ptr = (const uint32_t*)&option->value[0];
uint32_t len = option->value.size();
if((len % sizeof(uint32_t)) != 0)
return false;
while(len) {
container->push_back(Utils::be_to_host(*(ptr++)));
len -= sizeof(uint32_t);
}
return true;
}
bool DHCP::generic_search(Options opt, std::string *str) {
const DHCPOption *option = search_option(opt);
if(!option)
@@ -272,4 +298,13 @@ bool DHCP::generic_search(Options opt, uint32_t *value) {
}
return false;
}
bool DHCP::generic_search(Options opt, IPv4Address *value) {
uint32_t ip_int;
if(generic_search(opt, &ip_int)) {
*value = ip_int;
return true;
}
return false;
}
}

View File

@@ -28,10 +28,11 @@
#include "rawpdu.h"
#include "utils.h"
namespace Tins {
const uint16_t Tins::TCP::DEFAULT_WINDOW = 32678;
const uint16_t TCP::DEFAULT_WINDOW = 32678;
Tins::TCP::TCP(uint16_t dport, uint16_t sport)
TCP::TCP(uint16_t dport, uint16_t sport)
: PDU(Constants::IP::PROTO_TCP), _options_size(0), _total_options_size(0)
{
std::memset(&_tcp, 0, sizeof(tcphdr));
@@ -41,7 +42,7 @@ Tins::TCP::TCP(uint16_t dport, uint16_t sport)
window(DEFAULT_WINDOW);
}
Tins::TCP::TCP(const uint8_t *buffer, uint32_t total_sz)
TCP::TCP(const uint8_t *buffer, uint32_t total_sz)
: PDU(Constants::IP::PROTO_TCP)
{
if(total_sz < sizeof(tcphdr))
@@ -87,71 +88,71 @@ Tins::TCP::TCP(const uint8_t *buffer, uint32_t total_sz)
inner_pdu(new RawPDU(buffer, total_sz));
}
void Tins::TCP::dport(uint16_t new_dport) {
void TCP::dport(uint16_t new_dport) {
_tcp.dport = Utils::host_to_be(new_dport);
}
void Tins::TCP::sport(uint16_t new_sport) {
void TCP::sport(uint16_t new_sport) {
_tcp.sport = Utils::host_to_be(new_sport);
}
void Tins::TCP::seq(uint32_t new_seq) {
void TCP::seq(uint32_t new_seq) {
_tcp.seq = Utils::host_to_be(new_seq);
}
void Tins::TCP::ack_seq(uint32_t new_ack_seq) {
void TCP::ack_seq(uint32_t new_ack_seq) {
_tcp.ack_seq = Utils::host_to_be(new_ack_seq);
}
void Tins::TCP::window(uint16_t new_window) {
void TCP::window(uint16_t new_window) {
_tcp.window = Utils::host_to_be(new_window);
}
void Tins::TCP::check(uint16_t new_check) {
void TCP::check(uint16_t new_check) {
_tcp.check = Utils::host_to_be(new_check);
}
void Tins::TCP::urg_ptr(uint16_t new_urg_ptr) {
void TCP::urg_ptr(uint16_t new_urg_ptr) {
_tcp.urg_ptr = Utils::host_to_be(new_urg_ptr);
}
void Tins::TCP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
void TCP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
inner_pdu(new RawPDU(new_payload, new_payload_size));
}
void Tins::TCP::data_offset(uint8_t new_doff) {
void TCP::data_offset(uint8_t new_doff) {
this->_tcp.doff = new_doff;
}
void Tins::TCP::add_mss_option(uint16_t value) {
void TCP::add_mss_option(uint16_t value) {
value = Utils::host_to_be(value);
add_option(MSS, 2, (uint8_t*)&value);
}
bool Tins::TCP::search_mss_option(uint16_t *value) {
bool TCP::search_mss_option(uint16_t *value) {
if(!generic_search(MSS, value))
return false;
*value = Utils::host_to_be(*value);
return true;
}
void Tins::TCP::add_winscale_option(uint8_t value) {
void TCP::add_winscale_option(uint8_t value) {
add_option(WSCALE, 1, &value);
}
bool Tins::TCP::search_winscale_option(uint8_t *value) {
bool TCP::search_winscale_option(uint8_t *value) {
return generic_search(WSCALE, value);
}
void Tins::TCP::add_sack_permitted_option() {
void TCP::add_sack_permitted_option() {
add_option(SACK_OK, 0, 0);
}
bool Tins::TCP::search_sack_permitted_option() {
bool TCP::search_sack_permitted_option() {
return search_option(SACK_OK);
}
void Tins::TCP::add_sack_option(const std::list<uint32_t> &edges) {
void TCP::add_sack_option(const std::list<uint32_t> &edges) {
uint32_t *value = 0;
if(edges.size()) {
value = new uint32_t[edges.size()];
@@ -163,7 +164,7 @@ void Tins::TCP::add_sack_option(const std::list<uint32_t> &edges) {
delete[] value;
}
bool Tins::TCP::search_sack_option(std::list<uint32_t> *edges) {
bool TCP::search_sack_option(std::list<uint32_t> *edges) {
const TCPOption *option = search_option(SACK);
if(!option || (option->value.size() % sizeof(uint32_t)) != 0)
return false;
@@ -174,30 +175,33 @@ bool Tins::TCP::search_sack_option(std::list<uint32_t> *edges) {
return true;
}
void Tins::TCP::add_timestamp_option(uint32_t value, uint32_t reply) {
uint64_t buffer = ((uint64_t)Utils::host_to_be(reply) << 32) | Utils::host_to_be(value);
void TCP::add_timestamp_option(uint32_t value, uint32_t reply) {
uint64_t buffer = (uint64_t(value) << 32) | reply;
buffer = Utils::host_to_be(buffer);
add_option(TSOPT, 8, (uint8_t*)&buffer);
}
bool Tins::TCP::search_timestamp_option(uint32_t *value, uint32_t *reply) {
bool TCP::search_timestamp_option(uint32_t *value, uint32_t *reply) {
const TCPOption *option = search_option(TSOPT);
if(!option || option->value.size() != (sizeof(uint32_t) << 1))
return false;
const uint32_t *ptr = (const uint32_t*)&option->value[0];
*value = Utils::host_to_be(*(ptr++));
*reply = Utils::host_to_be(*(ptr));
uint64_t buffer = *(const uint64_t*)&option->value[0];
buffer = Utils::be_to_host(buffer);
*value = (buffer >> 32) & 0xffffffff;
*reply = buffer & 0xffffffff;
return true;
}
void Tins::TCP::add_altchecksum_option(AltChecksums value) {
add_option(ALTCHK, 1, (const uint8_t*)&value);
void TCP::add_altchecksum_option(AltChecksums value) {
uint8_t int_value = value;
add_option(ALTCHK, 1, &int_value);
}
bool Tins::TCP::search_altchecksum_option(uint8_t *value) {
bool TCP::search_altchecksum_option(uint8_t *value) {
return generic_search(ALTCHK, value);
}
uint8_t Tins::TCP::get_flag(Flags tcp_flag) {
uint8_t TCP::get_flag(Flags tcp_flag) {
switch(tcp_flag) {
case FIN:
return _tcp.fin;
@@ -229,7 +233,7 @@ uint8_t Tins::TCP::get_flag(Flags tcp_flag) {
};
}
void Tins::TCP::set_flag(Flags tcp_flag, uint8_t value) {
void TCP::set_flag(Flags tcp_flag, uint8_t value) {
switch(tcp_flag) {
case FIN:
_tcp.fin = value;
@@ -258,7 +262,7 @@ void Tins::TCP::set_flag(Flags tcp_flag, uint8_t value) {
};
}
void Tins::TCP::add_option(Option tcp_option, uint8_t length, const uint8_t *data) {
void TCP::add_option(Option tcp_option, uint8_t length, const uint8_t *data) {
uint8_t padding;
_options.push_back(TCPOption(tcp_option, length, data));
@@ -274,11 +278,11 @@ void Tins::TCP::add_option(Option tcp_option, uint8_t length, const uint8_t *dat
_total_options_size = (padding) ? _options_size - padding + 4 : _options_size;
}
uint32_t Tins::TCP::header_size() const {
uint32_t TCP::header_size() const {
return sizeof(tcphdr) + _total_options_size;
}
void Tins::TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
void TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
assert(total_sz >= header_size());
uint8_t *tcp_start = buffer;
buffer += sizeof(tcphdr);
@@ -309,7 +313,7 @@ void Tins::TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PD
_tcp.check = 0;
}
const Tins::TCP::TCPOption *Tins::TCP::search_option(Option opt) const {
const TCP::TCPOption *TCP::search_option(Option opt) const {
for(std::list<TCPOption>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
if(it->option == opt)
return &(*it);
@@ -319,7 +323,7 @@ const Tins::TCP::TCPOption *Tins::TCP::search_option(Option opt) const {
/* TCPOptions */
uint8_t *Tins::TCP::TCPOption::write(uint8_t *buffer) {
uint8_t *TCP::TCPOption::write(uint8_t *buffer) {
if(option == 0 || option == 1) {
*buffer = option;
return buffer + 1;
@@ -333,3 +337,4 @@ uint8_t *Tins::TCP::TCPOption::write(uint8_t *buffer) {
}
}
}

View File

@@ -1,7 +1,7 @@
CXX=@CXX@
CFLAGS=-c -Wall @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@
LDFLAGS=-lpcap -lgtest -lpthread
SOURCES=$(wildcard src/*.cpp ../src/*.cpp)
SOURCES=$(wildcard src/*.cpp src/dot11/*.cpp ../src/*.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
INCLUDE=-Iinclude/ -I../include

View File

@@ -264,6 +264,54 @@ src/utils_test.o: src/utils_test.cpp ../include/utils.h \
../include/network_interface.h:
../include/ipaddress.h:
src/dot11/beacon.o: src/dot11/beacon.cpp ../include/dot11.h \
../include/pdu.h ../include/packetsender.h ../include/utils.h \
../include/ipaddress.h ../include/hwaddress.h \
../include/network_interface.h include/tests/dot11.h \
include/tests/dot11.h
../include/dot11.h:
../include/pdu.h:
../include/packetsender.h:
../include/utils.h:
../include/ipaddress.h:
../include/hwaddress.h:
../include/network_interface.h:
include/tests/dot11.h:
include/tests/dot11.h:
src/dot11/dot11.o: src/dot11/dot11.cpp ../include/dot11.h \
../include/pdu.h ../include/packetsender.h ../include/utils.h \
../include/ipaddress.h ../include/hwaddress.h \
../include/network_interface.h include/tests/dot11.h \
include/tests/dot11.h ../include/utils.h
../include/dot11.h:
../include/pdu.h:
../include/packetsender.h:
../include/utils.h:
../include/ipaddress.h:
../include/hwaddress.h:
../include/network_interface.h:
include/tests/dot11.h:
include/tests/dot11.h:
../include/utils.h:
../src/arp.o: ../src/arp.cpp ../include/arp.h ../include/pdu.h \
../include/packetsender.h ../include/ipaddress.h ../include/utils.h \
../include/hwaddress.h ../include/network_interface.h ../include/ip.h \

View File

@@ -39,7 +39,7 @@ const uint8_t DHCPTest::file[] = "\x16\xab\x54\x12\xfa\xca\x56\x7f\x1b\x65\x11\x
"\x16\xab\x54\x12\xfa\xca\x56\x7f\x1b\x65\x11\xfa\xda\xfb\x19\x18";
const IPv4Address DHCPTest::addr("192.168.8.1");
const uint8_t DHCPTest::expected_packet[] = {'\x01', '\x01', '\x06', '\x1f', '?', '\xab', '#', '\xde',
/*const uint8_t DHCPTest::expected_packet[] = {'\x01', '\x01', '\x06', '\x1f', '?', '\xab', '#', '\xde',
'\x9f', '\x1a', '\x00', '\x00', '\xc0', '\xa8', '\x00', 'f', '\xf3', '\x16', '"', 'b', '\xa7', ' ',
'\x0b', '\x9a', '{', '+', '7', '\xfe', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
@@ -58,7 +58,9 @@ const uint8_t DHCPTest::expected_packet[] = {'\x01', '\x01', '\x06', '\x1f', '?'
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', 'c', '\x82', 'S', 'c', '6', '\x04', '\xc0', '\xa8', '\x04', '\x02',
'\x01', '\x04', '\xff', '\xff', ' ', '\x0b', '5', '\x01', '\x04'};
'\x01', '\x04', '\xff', '\xff', ' ', '\x0b', '5', '\x01', '\x04'};*/
const uint8_t DHCPTest::expected_packet[] = {'\x01', '\x01', '\x06', '\x1f', '?', '\xab', '#', '\xde', '\x9f', '\x1a', '\x00', '\x00', '\xc0', '\xa8', '\x00', 'f', '\xf3', '\x16', '"', 'b', '\xa7', ' ', '\x0b', '\x9a', '{', '+', '7', '\xfe', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'c', '\x82', 'S', 'c', '6', '\x04', '\xc0', '\xa8', '\x04', '\x02', '\x01', '\x04', '\xff', '\xff', ' ', '\x0b', '5', '\x01', '\x04', '\x03', '\x08', '\xc0', '\xa8', '\x00', '\x01', '\x7f', '\x00', '\x00', '\x01', '\x06', '\x08', '\xc0', '\xa8', '\x00', '\x02', '\x7f', '\x00', '\x00', '\x01'};
TEST_F(DHCPTest, DefaultConstructor) {
DHCP dhcp;
@@ -184,14 +186,14 @@ void DHCPTest::test_option(const DHCP &dhcp, DHCP::Options opt, uint32_t len, ui
TEST_F(DHCPTest, TypeOption) {
DHCP dhcp;
uint8_t value = DHCP::REQUEST, value_found;
dhcp.add_type_option((DHCP::Flags)value);
dhcp.add_type_option(DHCP::REQUEST);
ASSERT_TRUE(dhcp.search_type_option(&value_found));
EXPECT_EQ(value, value_found);
}
TEST_F(DHCPTest, ServerIdentifierOption) {
DHCP dhcp;
uint32_t ip = 0xf3ba34f1, ip_found;
IPv4Address ip = "192.168.0.1", ip_found;
dhcp.add_server_identifier(ip);
ASSERT_TRUE(dhcp.search_server_identifier(&ip_found));
EXPECT_EQ(ip, ip_found);
@@ -207,7 +209,7 @@ TEST_F(DHCPTest, LeaseTimeOption) {
TEST_F(DHCPTest, SubnetMaskOption) {
DHCP dhcp;
uint32_t ip = 0xf3ba34f1, ip_found;
IPv4Address ip = "192.168.0.1", ip_found;
dhcp.add_subnet_mask(ip);
ASSERT_TRUE(dhcp.search_subnet_mask(&ip_found));
EXPECT_EQ(ip, ip_found);
@@ -215,12 +217,12 @@ TEST_F(DHCPTest, SubnetMaskOption) {
TEST_F(DHCPTest, RoutersOption) {
DHCP dhcp;
list<uint32_t> routers;
routers.push_back(Utils::ip_to_int("192.168.0.253"));
routers.push_back(Utils::ip_to_int("10.123.45.67"));
list<IPv4Address> routers;
routers.push_back("192.168.0.253");
routers.push_back("10.123.45.67");
dhcp.add_routers_option(routers);
list<uint32_t> routers2;
list<IPv4Address> routers2;
ASSERT_TRUE(dhcp.search_routers_option(&routers2));
ASSERT_EQ(routers.size(), routers2.size());
while(routers.size()) {
@@ -232,12 +234,12 @@ TEST_F(DHCPTest, RoutersOption) {
TEST_F(DHCPTest, DNSOption) {
DHCP dhcp;
list<uint32_t> dns;
dns.push_back(Utils::ip_to_int("192.168.0.253"));
dns.push_back(Utils::ip_to_int("10.123.45.67"));
list<IPv4Address> dns;
dns.push_back("192.168.0.253");
dns.push_back("10.123.45.67");
dhcp.add_dns_option(dns);
list<uint32_t> dns2;
list<IPv4Address> dns2;
ASSERT_TRUE(dhcp.search_dns_option(&dns2));
ASSERT_EQ(dns.size(), dns2.size());
while(dns.size()) {
@@ -257,7 +259,7 @@ TEST_F(DHCPTest, DomainNameOption) {
TEST_F(DHCPTest, BroadcastOption) {
DHCP dhcp;
uint32_t ip = 0xf3ba34f1, ip_found;
IPv4Address ip = "192.168.0.1", ip_found;
dhcp.add_broadcast_option(ip);
ASSERT_TRUE(dhcp.search_broadcast_option(&ip_found));
EXPECT_EQ(ip, ip_found);
@@ -293,7 +295,9 @@ void DHCPTest::test_equals(const DHCP &dhcp1, const DHCP &dhcp2) {
TEST_F(DHCPTest, ConstructorFromBuffer) {
DHCP dhcp1(expected_packet, sizeof(expected_packet));
uint32_t ip;
IPv4Address ip;
std::list<IPv4Address> routers;
IPv4Address expected_routers[] = { "192.168.0.1", "127.0.0.1" };
EXPECT_EQ(dhcp1.opcode(), DHCP::DISCOVER);
EXPECT_EQ(dhcp1.htype(), 1);
@@ -307,8 +311,13 @@ TEST_F(DHCPTest, ConstructorFromBuffer) {
EXPECT_EQ(dhcp1.giaddr(), IPv4Address("123.43.55.254"));
EXPECT_EQ(dhcp1.siaddr(), IPv4Address("167.32.11.154"));
ASSERT_TRUE(dhcp1.search_server_identifier(&ip));
EXPECT_EQ(ip, Utils::net_to_host_l(IPv4Address("192.168.4.2")));
EXPECT_EQ(ip, IPv4Address("192.168.4.2"));
ASSERT_TRUE(dhcp1.search_routers_option(&routers));
ASSERT_EQ(routers.size(), sizeof(expected_routers) / sizeof(IPv4Address));
ASSERT_TRUE(std::equal(routers.begin(), routers.end(), expected_routers));
uint32_t size;
uint8_t *buffer = dhcp1.serialize(size);

View File

@@ -198,7 +198,6 @@ TEST_F(DNSTest, Answers) {
DNS::resources_type resources(dns.dns_answers());
for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
std::cout << it->dname << "\n";
EXPECT_TRUE(it->dname == "www.example.com" || it->dname == "www.example2.com");
if(it->dname == "www.example.com") {
EXPECT_EQ(it->type, DNS::A);

View File

@@ -162,7 +162,7 @@ TEST_F(TCPTest, AlternateChecksum) {
uint8_t found;
tcp.add_altchecksum_option(TCP::CHK_16FLETCHER);
ASSERT_TRUE(tcp.search_altchecksum_option(&found));
EXPECT_EQ(found, (uint8_t)TCP::CHK_16FLETCHER);
EXPECT_EQ(found, TCP::CHK_16FLETCHER);
}
TEST_F(TCPTest, Timestamp) {