1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Refactored TCP's interface.

This commit is contained in:
Matias Fontanini
2012-09-07 11:56:36 -03:00
parent 10681eee8f
commit 83ec6e6bad
6 changed files with 219 additions and 215 deletions

View File

@@ -143,7 +143,8 @@ namespace Tins {
* *
* This method makes this PDU to <b>no longer own</b> the inner * This method makes this PDU to <b>no longer own</b> the inner
* PDU. The current inner PDU is returned, and is <b>not</b> * PDU. The current inner PDU is returned, and is <b>not</b>
* destroyed. * destroyed. That means after calling this function, you are
* responsible for using operator delete on the returned pointer.
* *
* Use this method if you want to somehow re-use a PDU that * Use this method if you want to somehow re-use a PDU that
* is already owned by another PDU. * is already owned by another PDU.

View File

@@ -26,6 +26,8 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <stdint.h> #include <stdint.h>
#include <stdexcept>
#include <utility>
#include "pdu.h" #include "pdu.h"
#include "endianness.h" #include "endianness.h"
#include "small_uint.h" #include "small_uint.h"
@@ -41,7 +43,7 @@ namespace Tins {
class TCP : public PDU { class TCP : public PDU {
public: public:
/** /**
* \brief This PDU's flag. * This PDU's flag.
*/ */
static const PDU::PDUType pdu_flag = PDU::TCP; static const PDU::PDUType pdu_flag = PDU::TCP;
@@ -90,17 +92,61 @@ namespace Tins {
/** /**
* \brief Class that represents a TCP option field. * \brief Class that represents a TCP option field.
*/ */
struct TCPOption { class TCPOption {
public:
/** /**
* \brief Creates an instance of a TCPOption. * \brief Constructs a TCPOption.
* \param okind The option kind. * \param opt The option type.
* \param olength The option's data length. * \param length The option's data length.
* \param odata The option's data(if any). * \param data The option's data(if any).
*/ */
TCPOption(uint8_t opt = 0, uint8_t length = 0, const uint8_t *value = 0) TCPOption(uint8_t opt = 0, uint8_t length = 0, const uint8_t *data = 0)
: option(opt), value(value, (value) ? (value + length) : 0) { : option_(opt) {
value_.push_back(length);
if(data)
value_.insert(value_.end(), data, data + length);
}
/**
* Constructs a TCPOption from iterators, which indicate
* the data to be stored in it.
* \param opt The option type.
* \param start The beginning of the option data.
* \param end The end of the option data.
*/
template<typename ForwardIterator>
TCPOption(uint8_t opt, ForwardIterator start, ForwardIterator end)
: option_(opt), value_(start, end) {
} }
/**
* Retrieves this option's type.
* \return uint8_t containing this option's size.
*/
uint8_t option() const {
return option_;
}
/**
* Retrieves this option's data.
*
* If this method is called when data_size() == 0,
* dereferencing the returned pointer will result in undefined
* behaviour.
*
* \return const value_type& containing this option's value.
*/
const uint8_t *data_ptr() const {
return &value_[1];
}
/**
* Retrieves the length of this option's data.
*/
size_t data_size() const {
return value_.size() - 1;
}
/** /**
* \brief Writes the option into a buffer. * \brief Writes the option into a buffer.
@@ -108,9 +154,31 @@ namespace Tins {
* \return The buffer pointer incremented by the size of this option. * \return The buffer pointer incremented by the size of this option.
*/ */
uint8_t *write(uint8_t *buffer); uint8_t *write(uint8_t *buffer);
private:
uint8_t option; typedef std::vector<uint8_t> data_type;
std::vector<uint8_t> value;
uint8_t option_;
data_type value_;
};
/**
* The type used to store the options.
*/
typedef std::vector<TCPOption> options_type;
/**
* The type used to store the sack option.
*/
typedef std::vector<uint32_t> sack_type;
/**
* \brief Exception thrown when an option is not found.
*/
class OptionNotFound : public std::exception {
public:
const char* what() const throw() {
return "Option not found";
}
}; };
/** /**
@@ -193,7 +261,7 @@ namespace Tins {
* *
* \return The options list. * \return The options list.
*/ */
const std::list<TCPOption> &options() const { return _options; } const options_type &options() const { return _options; }
/** /**
* \brief Gets the value of a flag. * \brief Gets the value of a flag.
@@ -261,72 +329,60 @@ namespace Tins {
*/ */
void data_offset(small_uint<4> new_doff); void data_offset(small_uint<4> new_doff);
/** // Options
* \brief Set the payload.
*
* Payload is NOT copied. Therefore, pointers provided as
* payloads must be freed manually by the user. This actually
* creates a RawPDU that holds the payload, and sets it as the
* inner_pdu. Therefore, if an inner_pdu was set previously,
* a call to TCP::payload will delete it.
*
* \param new_payload New payload.
* \param new_payload_size New payload's size
*/
void payload(uint8_t *new_payload, uint32_t new_payload_size);
/** /**
* \brief Add a maximum segment size option. * \brief Add a maximum segment size option.
* *
* \param value The new maximum segment size. * \param value The new maximum segment size.
*/ */
void add_mss_option(uint16_t value); void mss(uint16_t value);
/** /**
* \brief Searchs for a maximum segment size option. * \brief Searchs for a maximum segment size option.
* \param value A pointer in which the option's value will be stored. * \param value A pointer in which the option's value will be stored.
* \return True if the option was found, false otherwise. * \return True if the option was found, false otherwise.
*/ */
bool search_mss_option(uint16_t *value); uint16_t mss() const;
/** /**
* \brief Add a window scale option. * \brief Add a window scale option.
* *
* \param value The new window scale. * \param value The new window scale.
*/ */
void add_winscale_option(uint8_t value); void winscale(uint8_t value);
/** /**
* \brief Searchs for a window scale option. * \brief Searchs for a window scale option.
* \param value A pointer in which the option's value will be stored. * \param value A pointer in which the option's value will be stored.
* \return True if the option was found, false otherwise. * \return True if the option was found, false otherwise.
*/ */
bool search_winscale_option(uint8_t *value); uint8_t winscale() const;
/** /**
* \brief Add a sack permitted option. * \brief Add a sack permitted option.
*/ */
void add_sack_permitted_option(); void sack_permitted();
/** /**
* \brief Searchs for a sack permitted option. * \brief Searchs for a sack permitted option.
* \return True if the option was found, false otherwise. * \return True if the option was found, false otherwise.
*/ */
bool search_sack_permitted_option(); bool has_sack_permitted() const;
/** /**
* \brief Add a sack option. * \brief Add a sack option.
* *
* \param value The new window scale. * \param value The new window scale.
*/ */
void add_sack_option(const std::list<uint32_t> &edges); void sack(const sack_type &edges);
/** /**
* \brief Searchs for a sack option. * \brief Searchs for a sack option.
* \param value A pointer in which the option's value will be stored. * \param value A pointer in which the option's value will be stored.
* \return True if the option was found, false otherwise. * \return True if the option was found, false otherwise.
*/ */
bool search_sack_option(std::list<uint32_t> *edges); sack_type sack() const;
/** /**
* \brief Add a timestamp option. * \brief Add a timestamp option.
@@ -334,7 +390,7 @@ namespace Tins {
* \param value The current value of the timestamp clock. * \param value The current value of the timestamp clock.
* \param reply The echo reply field. * \param reply The echo reply field.
*/ */
void add_timestamp_option(uint32_t value, uint32_t reply); void timestamp(uint32_t value, uint32_t reply);
/** /**
* \brief Searchs for a timestamp option. * \brief Searchs for a timestamp option.
@@ -342,21 +398,21 @@ namespace Tins {
* \param reply A pointer in which the option's reply value will be stored. * \param reply A pointer in which the option's reply value will be stored.
* \return True if the option was found, false otherwise. * \return True if the option was found, false otherwise.
*/ */
bool search_timestamp_option(uint32_t *value, uint32_t *reply); std::pair<uint32_t, uint32_t> timestamp() const;
/** /**
* \brief Add a alternate checksum option. * \brief Add a alternate checksum option.
* *
* \param value The new alternate checksum scale. * \param value The new alternate checksum scale.
*/ */
void add_altchecksum_option(AltChecksums value); void altchecksum(AltChecksums value);
/** /**
* \brief Searchs for a alternate checksum option. * \brief Searchs for a alternate checksum option.
* \param value A pointer in which the option's value will be stored. * \param value A pointer in which the option's value will be stored.
* \return True if the option was found, false otherwise. * \return True if the option was found, false otherwise.
*/ */
bool search_altchecksum_option(uint8_t *value); AltChecksums altchecksum() const;
/** /**
* \brief Set a TCP flag value. * \brief Set a TCP flag value.
@@ -443,13 +499,12 @@ namespace Tins {
static const uint16_t DEFAULT_WINDOW; static const uint16_t DEFAULT_WINDOW;
template<class T> bool generic_search(Option opt, T *value) { template<class T>
T generic_search(Option opt) const {
const TCPOption *option = search_option(opt); const TCPOption *option = search_option(opt);
if(option && option->value.size() == sizeof(T)) { if(option && option->data_size() == sizeof(T))
*value = *(const T*)(&option->value[0]); return *(const T*)(&option->data_ptr()[0]);
return true; throw OptionNotFound();
}
return false;
} }
/** \brief Serialices this TCP PDU. /** \brief Serialices this TCP PDU.
* \param buffer The buffer in which the PDU will be serialized. * \param buffer The buffer in which the PDU will be serialized.
@@ -459,7 +514,7 @@ namespace Tins {
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent); void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
tcphdr _tcp; tcphdr _tcp;
std::list<TCPOption> _options; options_type _options;
uint32_t _options_size, _total_options_size; uint32_t _options_size, _total_options_size;
}; };
}; };

View File

@@ -537,10 +537,16 @@ void Dot11ManagementFrame::erp_information(uint8_t value) {
void Dot11ManagementFrame::bss_load(const bss_load_type &data) { void Dot11ManagementFrame::bss_load(const bss_load_type &data) {
uint8_t buffer[5]; uint8_t buffer[5];
uint16_t dummy = Endian::host_to_le(data.station_count);
*(uint16_t*)buffer = Endian::host_to_le(data.station_count); //*(uint16_t*)buffer = Endian::host_to_le(data.station_count);
buffer[0] = dummy & 0xff;
buffer[1] = (dummy >> 8) & 0xff;
buffer[2] = data.channel_utilization; buffer[2] = data.channel_utilization;
*(uint16_t*)(buffer + 3) = Endian::host_to_le(data.available_capacity); dummy = Endian::host_to_le(data.available_capacity);
buffer[3] = dummy & 0xff;
buffer[4] = (dummy >> 8) & 0xff;
//*(uint16_t*)(buffer + 3) = Endian::host_to_le(data.available_capacity);
add_tagged_option(BSS_LOAD, sizeof(buffer), buffer); add_tagged_option(BSS_LOAD, sizeof(buffer), buffer);
} }

View File

@@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <stdexcept>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include "tcp.h" #include "tcp.h"
@@ -116,89 +115,82 @@ void TCP::urg_ptr(uint16_t new_urg_ptr) {
_tcp.urg_ptr = Endian::host_to_be(new_urg_ptr); _tcp.urg_ptr = Endian::host_to_be(new_urg_ptr);
} }
void TCP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
inner_pdu(new RawPDU(new_payload, new_payload_size));
}
void TCP::data_offset(small_uint<4> new_doff) { void TCP::data_offset(small_uint<4> new_doff) {
this->_tcp.doff = new_doff; this->_tcp.doff = new_doff;
} }
void TCP::add_mss_option(uint16_t value) { void TCP::mss(uint16_t value) {
value = Endian::host_to_be(value); value = Endian::host_to_be(value);
add_option(MSS, 2, (uint8_t*)&value); add_option(MSS, 2, (uint8_t*)&value);
} }
bool TCP::search_mss_option(uint16_t *value) { uint16_t TCP::mss() const {
if(!generic_search(MSS, value)) return Endian::host_to_be(generic_search<uint16_t>(MSS));
return false;
*value = Endian::host_to_be(*value);
return true;
} }
void TCP::add_winscale_option(uint8_t value) { void TCP::winscale(uint8_t value) {
add_option(WSCALE, 1, &value); add_option(WSCALE, 1, &value);
} }
bool TCP::search_winscale_option(uint8_t *value) { uint8_t TCP::winscale() const {
return generic_search(WSCALE, value); return generic_search<uint8_t>(WSCALE);
} }
void TCP::add_sack_permitted_option() { void TCP::sack_permitted() {
add_option(SACK_OK, 0, 0); add_option(SACK_OK, 0, 0);
} }
bool TCP::search_sack_permitted_option() { bool TCP::has_sack_permitted() const {
return search_option(SACK_OK); return search_option(SACK_OK);
} }
void TCP::add_sack_option(const std::list<uint32_t> &edges) { void TCP::sack(const sack_type &edges) {
uint32_t *value = 0; uint32_t *value = 0;
if(edges.size()) { if(edges.size()) {
value = new uint32_t[edges.size()]; value = new uint32_t[edges.size()];
uint32_t *ptr = value; uint32_t *ptr = value;
for(std::list<uint32_t>::const_iterator it = edges.begin(); it != edges.end(); ++it) for(sack_type::const_iterator it = edges.begin(); it != edges.end(); ++it)
*(ptr++) = Endian::host_to_be(*it); *(ptr++) = Endian::host_to_be(*it);
} }
add_option(SACK, (uint8_t)(sizeof(uint32_t) * edges.size()), (const uint8_t*)value); add_option(SACK, (uint8_t)(sizeof(uint32_t) * edges.size()), (const uint8_t*)value);
delete[] value; delete[] value;
} }
bool TCP::search_sack_option(std::list<uint32_t> *edges) { TCP::sack_type TCP::sack() const {
const TCPOption *option = search_option(SACK); const TCPOption *option = search_option(SACK);
if(!option || (option->value.size() % sizeof(uint32_t)) != 0) if(!option || (option->data_size() % sizeof(uint32_t)) != 0)
return false; throw OptionNotFound();
const uint32_t *ptr = (const uint32_t*)&option->value[0]; const uint32_t *ptr = (const uint32_t*)option->data_ptr();
const uint32_t *end = ptr + (option->value.size() / sizeof(uint32_t)); const uint32_t *end = ptr + (option->data_size() / sizeof(uint32_t));
sack_type edges(end - ptr);
sack_type::iterator it = edges.begin();
while(ptr < end) while(ptr < end)
edges->push_back(Endian::host_to_be(*(ptr++))); *it++ = Endian::host_to_be(*(ptr++));
return true; return edges;
} }
void TCP::add_timestamp_option(uint32_t value, uint32_t reply) { void TCP::timestamp(uint32_t value, uint32_t reply) {
uint64_t buffer = (uint64_t(value) << 32) | reply; uint64_t buffer = (uint64_t(value) << 32) | reply;
buffer = Endian::host_to_be(buffer); buffer = Endian::host_to_be(buffer);
add_option(TSOPT, 8, (uint8_t*)&buffer); add_option(TSOPT, 8, (uint8_t*)&buffer);
} }
bool TCP::search_timestamp_option(uint32_t *value, uint32_t *reply) { std::pair<uint32_t, uint32_t> TCP::timestamp() const {
const TCPOption *option = search_option(TSOPT); const TCPOption *option = search_option(TSOPT);
if(!option || option->value.size() != (sizeof(uint32_t) << 1)) if(!option || option->data_size() != (sizeof(uint32_t) << 1))
return false; throw OptionNotFound();
uint64_t buffer = *(const uint64_t*)&option->value[0]; uint64_t buffer = *(const uint64_t*)option->data_ptr();
buffer = Endian::be_to_host(buffer); buffer = Endian::be_to_host(buffer);
*value = (buffer >> 32) & 0xffffffff; return std::make_pair((buffer >> 32) & 0xffffffff, buffer & 0xffffffff);
*reply = buffer & 0xffffffff;
return true;
} }
void TCP::add_altchecksum_option(AltChecksums value) { void TCP::altchecksum(AltChecksums value) {
uint8_t int_value = value; uint8_t int_value = value;
add_option(ALTCHK, 1, &int_value); add_option(ALTCHK, 1, &int_value);
} }
bool TCP::search_altchecksum_option(uint8_t *value) { TCP::AltChecksums TCP::altchecksum() const {
return generic_search(ALTCHK, value); return static_cast<AltChecksums>(generic_search<uint8_t>(ALTCHK));
} }
small_uint<1> TCP::get_flag(Flags tcp_flag) { small_uint<1> TCP::get_flag(Flags tcp_flag) {
@@ -287,7 +279,7 @@ void TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par
uint8_t *tcp_start = buffer; uint8_t *tcp_start = buffer;
buffer += sizeof(tcphdr); buffer += sizeof(tcphdr);
_tcp.doff = (sizeof(tcphdr) + _total_options_size) / sizeof(uint32_t); _tcp.doff = (sizeof(tcphdr) + _total_options_size) / sizeof(uint32_t);
for(std::list<TCPOption>::iterator it = _options.begin(); it != _options.end(); ++it) for(options_type::iterator it = _options.begin(); it != _options.end(); ++it)
buffer = it->write(buffer); buffer = it->write(buffer);
if(_options_size < _total_options_size) { if(_options_size < _total_options_size) {
@@ -314,8 +306,8 @@ void TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par
} }
const TCP::TCPOption *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) { for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
if(it->option == opt) if(it->option() == opt)
return &(*it); return &(*it);
} }
return 0; return 0;
@@ -324,15 +316,15 @@ const TCP::TCPOption *TCP::search_option(Option opt) const {
/* TCPOptions */ /* TCPOptions */
uint8_t *TCP::TCPOption::write(uint8_t *buffer) { uint8_t *TCP::TCPOption::write(uint8_t *buffer) {
if(option == 0 || option == 1) { if(option_ == 0 || option_ == 1) {
*buffer = option; *buffer = option_;
return buffer + 1; return buffer + 1;
} }
else { else {
buffer[0] = option; buffer[0] = option_;
buffer[1] = value.size() + (sizeof(uint8_t) << 1); buffer[1] = data_size() + (sizeof(uint8_t) << 1);
if(!value.empty()) if(!value_.empty())
std::copy(value.begin(), value.end(), buffer + 2); std::copy(value_.begin() + 1, value_.end(), buffer + 2);
return buffer + buffer[1]; return buffer + buffer[1];
} }
} }

View File

@@ -1,6 +1,6 @@
src/arp.o: src/arp.cpp ../include/arp.h ../include/pdu.h \ src/arp.o: src/arp.cpp ../include/arp.h ../include/pdu.h \
../include/endianness.h ../include/hwaddress.h ../include/ipaddress.h \ ../include/endianness.h ../include/hwaddress.h ../include/ipaddress.h \
../include/utils.h ../include/packetsender.h ../include/ipaddress.h ../include/utils.h ../include/ipaddress.h
../include/arp.h: ../include/arp.h:
@@ -14,14 +14,12 @@ src/arp.o: src/arp.cpp ../include/arp.h ../include/pdu.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \ src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \
../include/pdu.h ../include/endianness.h ../include/ipaddress.h \ ../include/pdu.h ../include/endianness.h ../include/ipaddress.h \
../include/hwaddress.h ../include/utils.h ../include/packetsender.h \ ../include/hwaddress.h ../include/utils.h ../include/ethernetII.h \
../include/ethernetII.h ../include/network_interface.h \ ../include/network_interface.h ../include/hwaddress.h \
../include/hwaddress.h ../include/ipaddress.h ../include/ipaddress.h
../include/dhcp.h: ../include/dhcp.h:
@@ -37,8 +35,6 @@ src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ethernetII.h: ../include/ethernetII.h:
../include/network_interface.h: ../include/network_interface.h:
@@ -47,8 +43,8 @@ src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \
../include/ipaddress.h: ../include/ipaddress.h:
src/dns.o: src/dns.cpp ../include/dns.h ../include/pdu.h \ src/dns.o: src/dns.cpp ../include/dns.h ../include/pdu.h \
../include/endianness.h ../include/utils.h ../include/packetsender.h \ ../include/endianness.h ../include/utils.h ../include/ipaddress.h \
../include/ipaddress.h ../include/hwaddress.h ../include/hwaddress.h
../include/dns.h: ../include/dns.h:
@@ -58,15 +54,13 @@ src/dns.o: src/dns.cpp ../include/dns.h ../include/pdu.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
src/ethernetII_test.o: src/ethernetII_test.cpp ../include/ethernetII.h \ src/ethernetII_test.o: src/ethernetII_test.cpp ../include/ethernetII.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.h \ ../include/pdu.h ../include/endianness.h ../include/hwaddress.h \
../include/network_interface.h ../include/ipaddress.h ../include/utils.h \ ../include/network_interface.h ../include/ipaddress.h ../include/utils.h \
../include/packetsender.h ../include/network_interface.h ../include/network_interface.h
../include/ethernetII.h: ../include/ethernetII.h:
@@ -82,15 +76,13 @@ src/ethernetII_test.o: src/ethernetII_test.cpp ../include/ethernetII.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/network_interface.h: ../include/network_interface.h:
src/hwaddress.o: src/hwaddress.cpp ../include/hwaddress.h src/hwaddress.o: src/hwaddress.cpp ../include/hwaddress.h
../include/hwaddress.h: ../include/hwaddress.h:
src/icmp.o: src/icmp.cpp ../include/icmp.h ../include/pdu.h \ src/icmp.o: src/icmp.cpp ../include/icmp.h ../include/pdu.h \
../include/endianness.h ../include/utils.h ../include/packetsender.h \ ../include/endianness.h ../include/utils.h ../include/ipaddress.h \
../include/ipaddress.h ../include/hwaddress.h ../include/hwaddress.h
../include/icmp.h: ../include/icmp.h:
@@ -100,28 +92,22 @@ src/icmp.o: src/icmp.cpp ../include/icmp.h ../include/pdu.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
src/ipaddress.o: src/ipaddress.cpp ../include/ipaddress.h \ src/ipaddress.o: src/ipaddress.cpp ../include/ipaddress.h \
../include/utils.h ../include/packetsender.h ../include/ipaddress.h \ ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h
../include/hwaddress.h
../include/ipaddress.h: ../include/ipaddress.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
src/ip.o: src/ip.cpp ../include/ip.h ../include/pdu.h \ src/ip.o: src/ip.cpp ../include/ip.h ../include/pdu.h \
../include/small_uint.h ../include/endianness.h ../include/ipaddress.h \ ../include/small_uint.h ../include/endianness.h ../include/ipaddress.h \
../include/ipaddress.h ../include/utils.h ../include/packetsender.h \ ../include/ipaddress.h ../include/utils.h ../include/hwaddress.h
../include/hwaddress.h
../include/ip.h: ../include/ip.h:
@@ -137,8 +123,6 @@ src/ip.o: src/ip.cpp ../include/ip.h ../include/pdu.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/hwaddress.h: ../include/hwaddress.h:
src/llc.o: src/llc.cpp ../include/llc.h ../include/pdu.h \ src/llc.o: src/llc.cpp ../include/llc.h ../include/pdu.h \
../include/endianness.h ../include/endianness.h
@@ -151,7 +135,7 @@ src/llc.o: src/llc.cpp ../include/llc.h ../include/pdu.h \
src/main.o: src/main.cpp src/main.o: src/main.cpp
src/network_interface.o: src/network_interface.cpp \ src/network_interface.o: src/network_interface.cpp \
../include/network_interface.h ../include/hwaddress.h \ ../include/network_interface.h ../include/hwaddress.h \
../include/ipaddress.h ../include/utils.h ../include/packetsender.h ../include/ipaddress.h ../include/utils.h
../include/network_interface.h: ../include/network_interface.h:
@@ -160,11 +144,9 @@ src/network_interface.o: src/network_interface.cpp \
../include/ipaddress.h: ../include/ipaddress.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
src/snap.o: src/snap.cpp ../include/snap.h ../include/pdu.h \ src/snap.o: src/snap.cpp ../include/snap.h ../include/pdu.h \
../include/endianness.h ../include/small_uint.h ../include/utils.h \ ../include/endianness.h ../include/small_uint.h ../include/utils.h \
../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h ../include/ipaddress.h ../include/hwaddress.h
../include/snap.h: ../include/snap.h:
@@ -176,14 +158,12 @@ src/snap.o: src/snap.cpp ../include/snap.h ../include/pdu.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
src/tcp.o: src/tcp.cpp ../include/tcp.h ../include/pdu.h \ src/tcp.o: src/tcp.cpp ../include/tcp.h ../include/pdu.h \
../include/endianness.h ../include/small_uint.h ../include/utils.h \ ../include/endianness.h ../include/small_uint.h ../include/utils.h \
../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h ../include/ipaddress.h ../include/hwaddress.h
../include/tcp.h: ../include/tcp.h:
@@ -195,8 +175,6 @@ src/tcp.o: src/tcp.cpp ../include/tcp.h ../include/pdu.h \
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
@@ -211,13 +189,11 @@ src/udp.o: src/udp.cpp ../include/udp.h ../include/pdu.h \
../include/pdu.h: ../include/pdu.h:
src/utils_test.o: src/utils_test.cpp ../include/utils.h \ src/utils_test.o: src/utils_test.cpp ../include/utils.h \
../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h \ ../include/ipaddress.h ../include/hwaddress.h ../include/endianness.h \
../include/endianness.h ../include/ipaddress.h ../include/ipaddress.h
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
@@ -478,7 +454,7 @@ src/dot11/dot11.o: src/dot11/dot11.cpp ../include/dot11.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.h \ ../include/pdu.h ../include/endianness.h ../include/hwaddress.h \
../include/small_uint.h ../include/network_interface.h \ ../include/small_uint.h ../include/network_interface.h \
../include/ipaddress.h include/tests/dot11.h include/tests/dot11.h \ ../include/ipaddress.h include/tests/dot11.h include/tests/dot11.h \
../include/utils.h ../include/packetsender.h ../include/utils.h
../include/dot11.h: ../include/dot11.h:
@@ -499,8 +475,6 @@ include/tests/dot11.h:
include/tests/dot11.h: include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
src/dot11/probe_request.o: src/dot11/probe_request.cpp ../include/dot11.h \ src/dot11/probe_request.o: src/dot11/probe_request.cpp ../include/dot11.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.h \ ../include/pdu.h ../include/endianness.h ../include/hwaddress.h \
../include/small_uint.h ../include/network_interface.h \ ../include/small_uint.h ../include/network_interface.h \
@@ -715,7 +689,7 @@ include/tests/dot11.h:
../include/endianness.h ../include/hwaddress.h ../include/small_uint.h \ ../include/endianness.h ../include/hwaddress.h ../include/small_uint.h \
../include/network_interface.h ../include/ipaddress.h \ ../include/network_interface.h ../include/ipaddress.h \
../include/rawpdu.h ../include/radiotap.h ../include/rsn_information.h \ ../include/rawpdu.h ../include/radiotap.h ../include/rsn_information.h \
../include/packetsender.h ../include/snap.h ../include/packet_sender.h ../include/snap.h
../include/dot11.h: ../include/dot11.h:
@@ -737,7 +711,7 @@ include/tests/dot11.h:
../include/rsn_information.h: ../include/rsn_information.h:
../include/packetsender.h: ../include/packet_sender.h:
../include/snap.h: ../include/snap.h:
../src/eapol.o: ../src/eapol.cpp ../include/eapol.h ../include/pdu.h \ ../src/eapol.o: ../src/eapol.cpp ../include/eapol.h ../include/pdu.h \
@@ -765,7 +739,7 @@ include/tests/dot11.h:
../src/ethernetII.o: ../src/ethernetII.cpp ../include/ethernetII.h \ ../src/ethernetII.o: ../src/ethernetII.cpp ../include/ethernetII.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.h \ ../include/pdu.h ../include/endianness.h ../include/hwaddress.h \
../include/network_interface.h ../include/ipaddress.h \ ../include/network_interface.h ../include/ipaddress.h \
../include/packetsender.h ../include/rawpdu.h ../include/ip.h \ ../include/packet_sender.h ../include/rawpdu.h ../include/ip.h \
../include/small_uint.h ../include/arp.h ../include/small_uint.h ../include/arp.h
../include/ethernetII.h: ../include/ethernetII.h:
@@ -780,7 +754,7 @@ include/tests/dot11.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/packetsender.h: ../include/packet_sender.h:
../include/rawpdu.h: ../include/rawpdu.h:
@@ -791,7 +765,7 @@ include/tests/dot11.h:
../include/arp.h: ../include/arp.h:
../src/icmp.o: ../src/icmp.cpp ../include/icmp.h ../include/pdu.h \ ../src/icmp.o: ../src/icmp.cpp ../include/icmp.h ../include/pdu.h \
../include/endianness.h ../include/rawpdu.h ../include/utils.h \ ../include/endianness.h ../include/rawpdu.h ../include/utils.h \
../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h ../include/ipaddress.h ../include/hwaddress.h
../include/icmp.h: ../include/icmp.h:
@@ -803,15 +777,13 @@ include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
../src/ieee802_3.o: ../src/ieee802_3.cpp ../include/ieee802_3.h \ ../src/ieee802_3.o: ../src/ieee802_3.cpp ../include/ieee802_3.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.h \ ../include/pdu.h ../include/endianness.h ../include/hwaddress.h \
../include/network_interface.h ../include/ipaddress.h \ ../include/network_interface.h ../include/ipaddress.h \
../include/packetsender.h ../include/llc.h ../include/packet_sender.h ../include/llc.h
../include/ieee802_3.h: ../include/ieee802_3.h:
@@ -825,7 +797,7 @@ include/tests/dot11.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/packetsender.h: ../include/packet_sender.h:
../include/llc.h: ../include/llc.h:
../src/ipaddress.o: ../src/ipaddress.cpp ../include/ipaddress.h \ ../src/ipaddress.o: ../src/ipaddress.cpp ../include/ipaddress.h \
@@ -837,7 +809,7 @@ include/tests/dot11.h:
../src/ip.o: ../src/ip.cpp ../include/ip.h ../include/pdu.h \ ../src/ip.o: ../src/ip.cpp ../include/ip.h ../include/pdu.h \
../include/small_uint.h ../include/endianness.h ../include/ipaddress.h \ ../include/small_uint.h ../include/endianness.h ../include/ipaddress.h \
../include/tcp.h ../include/udp.h ../include/icmp.h ../include/rawpdu.h \ ../include/tcp.h ../include/udp.h ../include/icmp.h ../include/rawpdu.h \
../include/utils.h ../include/packetsender.h ../include/hwaddress.h \ ../include/utils.h ../include/hwaddress.h ../include/packet_sender.h \
../include/constants.h ../include/constants.h
../include/ip.h: ../include/ip.h:
@@ -860,10 +832,10 @@ include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/hwaddress.h: ../include/hwaddress.h:
../include/packet_sender.h:
../include/constants.h: ../include/constants.h:
../src/llc.o: ../src/llc.cpp ../include/pdu.h ../include/llc.h \ ../src/llc.o: ../src/llc.cpp ../include/pdu.h ../include/llc.h \
../include/pdu.h ../include/endianness.h ../include/rawpdu.h ../include/pdu.h ../include/endianness.h ../include/rawpdu.h
@@ -879,8 +851,7 @@ include/tests/dot11.h:
../include/rawpdu.h: ../include/rawpdu.h:
../src/network_interface.o: ../src/network_interface.cpp \ ../src/network_interface.o: ../src/network_interface.cpp \
../include/network_interface.h ../include/hwaddress.h \ ../include/network_interface.h ../include/hwaddress.h \
../include/ipaddress.h ../include/utils.h ../include/packetsender.h \ ../include/ipaddress.h ../include/utils.h ../include/endianness.h
../include/endianness.h
../include/network_interface.h: ../include/network_interface.h:
@@ -890,17 +861,21 @@ include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/endianness.h: ../include/endianness.h:
../src/packetsender.o: ../src/packetsender.cpp ../include/packetsender.h \ ../src/packet_sender.o: ../src/packet_sender.cpp ../include/pdu.h \
../include/pdu.h ../include/packet_sender.h
../include/packetsender.h: ../include/pdu.h:
../include/packet_sender.h:
../src/packet_writer.o: ../src/packet_writer.cpp \
../include/packet_writer.h ../include/pdu.h
../include/packet_writer.h:
../include/pdu.h: ../include/pdu.h:
../src/pdu.o: ../src/pdu.cpp ../include/pdu.h ../include/rawpdu.h \ ../src/pdu.o: ../src/pdu.cpp ../include/pdu.h ../include/rawpdu.h \
../include/pdu.h ../include/packetsender.h ../include/pdu.h ../include/packet_sender.h
../include/pdu.h: ../include/pdu.h:
@@ -908,11 +883,11 @@ include/tests/dot11.h:
../include/pdu.h: ../include/pdu.h:
../include/packetsender.h: ../include/packet_sender.h:
../src/radiotap.o: ../src/radiotap.cpp ../include/radiotap.h \ ../src/radiotap.o: ../src/radiotap.cpp ../include/radiotap.h \
../include/pdu.h ../include/endianness.h ../include/network_interface.h \ ../include/pdu.h ../include/endianness.h ../include/network_interface.h \
../include/hwaddress.h ../include/ipaddress.h ../include/dot11.h \ ../include/hwaddress.h ../include/ipaddress.h ../include/dot11.h \
../include/small_uint.h ../include/utils.h ../include/packetsender.h ../include/small_uint.h ../include/utils.h ../include/packet_sender.h
../include/radiotap.h: ../include/radiotap.h:
@@ -932,7 +907,7 @@ include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h: ../include/packet_sender.h:
../src/rawpdu.o: ../src/rawpdu.cpp ../include/rawpdu.h ../include/pdu.h ../src/rawpdu.o: ../src/rawpdu.cpp ../include/rawpdu.h ../include/pdu.h
../include/rawpdu.h: ../include/rawpdu.h:
@@ -991,7 +966,7 @@ include/tests/dot11.h:
../src/tcp.o: ../src/tcp.cpp ../include/tcp.h ../include/pdu.h \ ../src/tcp.o: ../src/tcp.cpp ../include/tcp.h ../include/pdu.h \
../include/endianness.h ../include/small_uint.h ../include/ip.h \ ../include/endianness.h ../include/small_uint.h ../include/ip.h \
../include/ipaddress.h ../include/constants.h ../include/rawpdu.h \ ../include/ipaddress.h ../include/constants.h ../include/rawpdu.h \
../include/utils.h ../include/packetsender.h ../include/hwaddress.h ../include/utils.h ../include/hwaddress.h
../include/tcp.h: ../include/tcp.h:
@@ -1011,8 +986,6 @@ include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/hwaddress.h: ../include/hwaddress.h:
../src/tcp_stream.o: ../src/tcp_stream.cpp ../include/rawpdu.h \ ../src/tcp_stream.o: ../src/tcp_stream.cpp ../include/rawpdu.h \
../include/pdu.h ../include/tcp_stream.h ../include/sniffer.h \ ../include/pdu.h ../include/tcp_stream.h ../include/sniffer.h \
@@ -1048,8 +1021,8 @@ include/tests/dot11.h:
../include/ip.h: ../include/ip.h:
../src/udp.o: ../src/udp.cpp ../include/udp.h ../include/pdu.h \ ../src/udp.o: ../src/udp.cpp ../include/udp.h ../include/pdu.h \
../include/endianness.h ../include/constants.h ../include/utils.h \ ../include/endianness.h ../include/constants.h ../include/utils.h \
../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h \ ../include/ipaddress.h ../include/hwaddress.h ../include/ip.h \
../include/ip.h ../include/small_uint.h ../include/rawpdu.h ../include/small_uint.h ../include/rawpdu.h
../include/udp.h: ../include/udp.h:
@@ -1061,8 +1034,6 @@ include/tests/dot11.h:
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
@@ -1073,15 +1044,14 @@ include/tests/dot11.h:
../include/rawpdu.h: ../include/rawpdu.h:
../src/utils.o: ../src/utils.cpp ../include/utils.h \ ../src/utils.o: ../src/utils.cpp ../include/utils.h \
../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h \ ../include/ipaddress.h ../include/hwaddress.h ../include/pdu.h \
../include/pdu.h ../include/ip.h ../include/pdu.h \ ../include/ip.h ../include/pdu.h ../include/small_uint.h \
../include/small_uint.h ../include/endianness.h ../include/icmp.h \ ../include/endianness.h ../include/icmp.h ../include/arp.h \
../include/arp.h ../include/endianness.h ../include/network_interface.h ../include/endianness.h ../include/network_interface.h \
../include/packet_sender.h
../include/utils.h: ../include/utils.h:
../include/packetsender.h:
../include/ipaddress.h: ../include/ipaddress.h:
../include/hwaddress.h: ../include/hwaddress.h:
@@ -1103,3 +1073,5 @@ include/tests/dot11.h:
../include/endianness.h: ../include/endianness.h:
../include/network_interface.h: ../include/network_interface.h:
../include/packet_sender.h:

View File

@@ -121,58 +121,43 @@ TEST_F(TCPTest, SetFlag) {
TEST_F(TCPTest, MSS) { TEST_F(TCPTest, MSS) {
TCP tcp; TCP tcp;
uint16_t mss = 0x456f, found_mss; tcp.mss(0x456f);
tcp.add_mss_option(mss); EXPECT_EQ(0x456f, tcp.mss());
ASSERT_TRUE(tcp.search_mss_option(&found_mss));
EXPECT_EQ(mss, found_mss);
} }
TEST_F(TCPTest, WindowScale) { TEST_F(TCPTest, WindowScale) {
TCP tcp; TCP tcp;
uint8_t scale = 0x4f, found_scale; tcp.winscale(0x4f);
tcp.add_winscale_option(scale); EXPECT_EQ(0x4f, tcp.winscale());
ASSERT_TRUE(tcp.search_winscale_option(&found_scale));
EXPECT_EQ(scale, found_scale);
} }
TEST_F(TCPTest, SackPermitted) { TEST_F(TCPTest, SackPermitted) {
TCP tcp; TCP tcp;
tcp.add_sack_permitted_option(); tcp.sack_permitted();
ASSERT_TRUE(tcp.search_sack_permitted_option()); ASSERT_TRUE(tcp.has_sack_permitted());
} }
TEST_F(TCPTest, Sack) { TEST_F(TCPTest, Sack) {
TCP tcp; TCP tcp;
list<uint32_t> edges, edges_found; TCP::sack_type edges;
edges.push_back(0x13); edges.push_back(0x13);
edges.push_back(0x63fa1d7a); edges.push_back(0x63fa1d7a);
edges.push_back(0xff1c); edges.push_back(0xff1c);
tcp.add_sack_option(edges); tcp.sack(edges);
ASSERT_TRUE(tcp.search_sack_option(&edges_found)); ASSERT_EQ(edges, tcp.sack());
ASSERT_EQ(edges.size(), edges_found.size());
while(edges.size()) {
EXPECT_EQ(edges.front(), edges_found.front());
edges.pop_front();
edges_found.pop_front();
}
} }
TEST_F(TCPTest, AlternateChecksum) { TEST_F(TCPTest, AlternateChecksum) {
TCP tcp; TCP tcp;
uint8_t found; tcp.altchecksum(TCP::CHK_16FLETCHER);
tcp.add_altchecksum_option(TCP::CHK_16FLETCHER); EXPECT_EQ(TCP::CHK_16FLETCHER, tcp.altchecksum());
ASSERT_TRUE(tcp.search_altchecksum_option(&found));
EXPECT_EQ(found, TCP::CHK_16FLETCHER);
} }
TEST_F(TCPTest, Timestamp) { TEST_F(TCPTest, Timestamp) {
TCP tcp; TCP tcp;
uint32_t value = 0x456fa23d, found_value; std::pair<uint32_t, uint32_t> data(0x456fa23d, 0xfa12d345);
uint32_t reply = 0xfa12d345, found_reply; tcp.timestamp(data.first, data.second);
tcp.add_timestamp_option(value, reply); EXPECT_EQ(tcp.timestamp(), data);
ASSERT_TRUE(tcp.search_timestamp_option(&found_value, &found_reply));
EXPECT_EQ(value, found_value);
EXPECT_EQ(reply, found_reply);
} }
void TCPTest::test_equals(const TCP &tcp1, const TCP &tcp2) { void TCPTest::test_equals(const TCP &tcp1, const TCP &tcp2) {
@@ -190,9 +175,6 @@ void TCPTest::test_equals(const TCP &tcp1, const TCP &tcp2) {
// This is not working, but i don't want to fix it right now. // This is not working, but i don't want to fix it right now.
TEST_F(TCPTest, ConstructorFromBuffer) { TEST_F(TCPTest, ConstructorFromBuffer) {
TCP tcp1(expected_packet, sizeof(expected_packet)); TCP tcp1(expected_packet, sizeof(expected_packet));
uint32_t value32, ovalue32;
uint16_t value16;
uint8_t value8;
EXPECT_EQ(tcp1.dport(), 0x4f1d); EXPECT_EQ(tcp1.dport(), 0x4f1d);
EXPECT_EQ(tcp1.sport(), 0x7f4d); EXPECT_EQ(tcp1.sport(), 0x7f4d);
@@ -202,23 +184,19 @@ TEST_F(TCPTest, ConstructorFromBuffer) {
EXPECT_EQ(tcp1.urg_ptr(), 0x1fae); EXPECT_EQ(tcp1.urg_ptr(), 0x1fae);
EXPECT_EQ(tcp1.data_offset(), 0xd); EXPECT_EQ(tcp1.data_offset(), 0xd);
ASSERT_TRUE(tcp1.search_timestamp_option(&value32, &ovalue32)); EXPECT_EQ(tcp1.timestamp(), (std::pair<uint32_t, uint32_t>(0x4fd23acb, 0x89fe1234)));
EXPECT_EQ(value32, 0x4fd23acb);
EXPECT_EQ(ovalue32, 0x89fe1234);
EXPECT_TRUE(tcp1.search_sack_permitted_option()); EXPECT_TRUE(tcp1.has_sack_permitted());
ASSERT_TRUE(tcp1.search_winscale_option(&value8)); EXPECT_EQ(tcp1.winscale(), 0x7a);
EXPECT_EQ(value8, 0x7a);
ASSERT_TRUE(tcp1.search_mss_option(&value16)); EXPECT_EQ(tcp1.mss(), 0x98fa);
EXPECT_EQ(value16, 0x98fa);
list<uint32_t> edges; TCP::sack_type edges = tcp1.sack();
ASSERT_TRUE(tcp1.search_sack_option(&edges)); TCP::sack_type::const_iterator iter = edges.begin();
ASSERT_EQ(edges.size(), 2); ASSERT_EQ(edges.size(), 2);
EXPECT_EQ(edges.front(), 0x00010203); edges.pop_front(); EXPECT_EQ(*iter++, 0x00010203);
EXPECT_EQ(edges.front(), 0x04050607); EXPECT_EQ(*iter++, 0x04050607);
PDU::serialization_type buffer = tcp1.serialize(); PDU::serialization_type buffer = tcp1.serialize();