diff --git a/include/pdu.h b/include/pdu.h
index a627452..834032c 100644
--- a/include/pdu.h
+++ b/include/pdu.h
@@ -143,7 +143,8 @@ namespace Tins {
*
* This method makes this PDU to no longer own the inner
* PDU. The current inner PDU is returned, and is not
- * 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
* is already owned by another PDU.
diff --git a/include/tcp.h b/include/tcp.h
index dd22d1a..534cd29 100644
--- a/include/tcp.h
+++ b/include/tcp.h
@@ -26,6 +26,8 @@
#include
#include
#include
+#include
+#include
#include "pdu.h"
#include "endianness.h"
#include "small_uint.h"
@@ -41,7 +43,7 @@ namespace Tins {
class TCP : public PDU {
public:
/**
- * \brief This PDU's flag.
+ * This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::TCP;
@@ -90,17 +92,61 @@ namespace Tins {
/**
* \brief Class that represents a TCP option field.
*/
- struct TCPOption {
+ class TCPOption {
+ public:
/**
- * \brief Creates an instance of a TCPOption.
- * \param okind The option kind.
- * \param olength The option's data length.
- * \param odata The option's data(if any).
+ * \brief Constructs a TCPOption.
+ * \param opt The option type.
+ * \param length The option's data length.
+ * \param data The option's data(if any).
*/
- TCPOption(uint8_t opt = 0, uint8_t length = 0, const uint8_t *value = 0)
- : option(opt), value(value, (value) ? (value + length) : 0) {
+ TCPOption(uint8_t opt = 0, uint8_t length = 0, const uint8_t *data = 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
+ 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.
@@ -108,9 +154,31 @@ namespace Tins {
* \return The buffer pointer incremented by the size of this option.
*/
uint8_t *write(uint8_t *buffer);
-
- uint8_t option;
- std::vector value;
+ private:
+ typedef std::vector data_type;
+
+ uint8_t option_;
+ data_type value_;
+ };
+
+ /**
+ * The type used to store the options.
+ */
+ typedef std::vector options_type;
+
+ /**
+ * The type used to store the sack option.
+ */
+ typedef std::vector 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.
*/
- const std::list &options() const { return _options; }
+ const options_type &options() const { return _options; }
/**
* \brief Gets the value of a flag.
@@ -261,72 +329,60 @@ namespace Tins {
*/
void data_offset(small_uint<4> new_doff);
- /**
- * \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);
+ // Options
/**
* \brief Add a maximum segment size option.
*
* \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.
* \param value A pointer in which the option's value will be stored.
* \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.
*
* \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.
* \param value A pointer in which the option's value will be stored.
* \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.
*/
- void add_sack_permitted_option();
+ void sack_permitted();
/**
* \brief Searchs for a sack permitted option.
* \return True if the option was found, false otherwise.
*/
- bool search_sack_permitted_option();
+ bool has_sack_permitted() const;
/**
* \brief Add a sack option.
*
* \param value The new window scale.
*/
- void add_sack_option(const std::list &edges);
+ void sack(const sack_type &edges);
/**
* \brief Searchs for a sack 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_sack_option(std::list *edges);
+ sack_type sack() const;
/**
* \brief Add a timestamp option.
@@ -334,7 +390,7 @@ namespace Tins {
* \param value The current value of the timestamp clock.
* \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.
@@ -342,21 +398,21 @@ namespace Tins {
* \param reply A pointer in which the option's reply value will be stored.
* \return True if the option was found, false otherwise.
*/
- bool search_timestamp_option(uint32_t *value, uint32_t *reply);
+ std::pair timestamp() const;
/**
* \brief Add a alternate checksum option.
*
* \param value The new alternate checksum scale.
*/
- void add_altchecksum_option(AltChecksums value);
+ void altchecksum(AltChecksums value);
/**
* \brief Searchs for a alternate checksum 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_altchecksum_option(uint8_t *value);
+ AltChecksums altchecksum() const;
/**
* \brief Set a TCP flag value.
@@ -443,13 +499,12 @@ namespace Tins {
static const uint16_t DEFAULT_WINDOW;
- template bool generic_search(Option opt, T *value) {
+ template
+ T generic_search(Option opt) const {
const TCPOption *option = search_option(opt);
- if(option && option->value.size() == sizeof(T)) {
- *value = *(const T*)(&option->value[0]);
- return true;
- }
- return false;
+ if(option && option->data_size() == sizeof(T))
+ return *(const T*)(&option->data_ptr()[0]);
+ throw OptionNotFound();
}
/** \brief Serialices this TCP PDU.
* \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);
tcphdr _tcp;
- std::list _options;
+ options_type _options;
uint32_t _options_size, _total_options_size;
};
};
diff --git a/src/dot11.cpp b/src/dot11.cpp
index 9872121..3c0fa78 100644
--- a/src/dot11.cpp
+++ b/src/dot11.cpp
@@ -537,10 +537,16 @@ void Dot11ManagementFrame::erp_information(uint8_t value) {
void Dot11ManagementFrame::bss_load(const bss_load_type &data) {
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;
- *(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);
}
diff --git a/src/tcp.cpp b/src/tcp.cpp
index aaa7807..b4572d6 100644
--- a/src/tcp.cpp
+++ b/src/tcp.cpp
@@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include
#include
#include
#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);
}
-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) {
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);
add_option(MSS, 2, (uint8_t*)&value);
}
-bool TCP::search_mss_option(uint16_t *value) {
- if(!generic_search(MSS, value))
- return false;
- *value = Endian::host_to_be(*value);
- return true;
+uint16_t TCP::mss() const {
+ return Endian::host_to_be(generic_search(MSS));
}
-void TCP::add_winscale_option(uint8_t value) {
+void TCP::winscale(uint8_t value) {
add_option(WSCALE, 1, &value);
}
-bool TCP::search_winscale_option(uint8_t *value) {
- return generic_search(WSCALE, value);
+uint8_t TCP::winscale() const {
+ return generic_search(WSCALE);
}
-void TCP::add_sack_permitted_option() {
+void TCP::sack_permitted() {
add_option(SACK_OK, 0, 0);
}
-bool TCP::search_sack_permitted_option() {
+bool TCP::has_sack_permitted() const {
return search_option(SACK_OK);
}
-void TCP::add_sack_option(const std::list &edges) {
+void TCP::sack(const sack_type &edges) {
uint32_t *value = 0;
if(edges.size()) {
value = new uint32_t[edges.size()];
uint32_t *ptr = value;
- for(std::list::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);
}
add_option(SACK, (uint8_t)(sizeof(uint32_t) * edges.size()), (const uint8_t*)value);
delete[] value;
}
-bool TCP::search_sack_option(std::list *edges) {
+TCP::sack_type TCP::sack() const {
const TCPOption *option = search_option(SACK);
- if(!option || (option->value.size() % sizeof(uint32_t)) != 0)
- return false;
- const uint32_t *ptr = (const uint32_t*)&option->value[0];
- const uint32_t *end = ptr + (option->value.size() / sizeof(uint32_t));
+ if(!option || (option->data_size() % sizeof(uint32_t)) != 0)
+ throw OptionNotFound();
+ const uint32_t *ptr = (const uint32_t*)option->data_ptr();
+ 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)
- edges->push_back(Endian::host_to_be(*(ptr++)));
- return true;
+ *it++ = Endian::host_to_be(*(ptr++));
+ 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;
buffer = Endian::host_to_be(buffer);
add_option(TSOPT, 8, (uint8_t*)&buffer);
}
-bool TCP::search_timestamp_option(uint32_t *value, uint32_t *reply) {
+std::pair TCP::timestamp() const {
const TCPOption *option = search_option(TSOPT);
- if(!option || option->value.size() != (sizeof(uint32_t) << 1))
- return false;
- uint64_t buffer = *(const uint64_t*)&option->value[0];
+ if(!option || option->data_size() != (sizeof(uint32_t) << 1))
+ throw OptionNotFound();
+ uint64_t buffer = *(const uint64_t*)option->data_ptr();
buffer = Endian::be_to_host(buffer);
- *value = (buffer >> 32) & 0xffffffff;
- *reply = buffer & 0xffffffff;
- return true;
+ return std::make_pair((buffer >> 32) & 0xffffffff, buffer & 0xffffffff);
}
-void TCP::add_altchecksum_option(AltChecksums value) {
+void TCP::altchecksum(AltChecksums value) {
uint8_t int_value = value;
add_option(ALTCHK, 1, &int_value);
}
-bool TCP::search_altchecksum_option(uint8_t *value) {
- return generic_search(ALTCHK, value);
+TCP::AltChecksums TCP::altchecksum() const {
+ return static_cast(generic_search(ALTCHK));
}
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;
buffer += sizeof(tcphdr);
_tcp.doff = (sizeof(tcphdr) + _total_options_size) / sizeof(uint32_t);
- for(std::list::iterator it = _options.begin(); it != _options.end(); ++it)
+ for(options_type::iterator it = _options.begin(); it != _options.end(); ++it)
buffer = it->write(buffer);
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 {
- for(std::list::const_iterator it = _options.begin(); it != _options.end(); ++it) {
- if(it->option == opt)
+ for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
+ if(it->option() == opt)
return &(*it);
}
return 0;
@@ -324,15 +316,15 @@ const TCP::TCPOption *TCP::search_option(Option opt) const {
/* TCPOptions */
uint8_t *TCP::TCPOption::write(uint8_t *buffer) {
- if(option == 0 || option == 1) {
- *buffer = option;
+ if(option_ == 0 || option_ == 1) {
+ *buffer = option_;
return buffer + 1;
}
else {
- buffer[0] = option;
- buffer[1] = value.size() + (sizeof(uint8_t) << 1);
- if(!value.empty())
- std::copy(value.begin(), value.end(), buffer + 2);
+ buffer[0] = option_;
+ buffer[1] = data_size() + (sizeof(uint8_t) << 1);
+ if(!value_.empty())
+ std::copy(value_.begin() + 1, value_.end(), buffer + 2);
return buffer + buffer[1];
}
}
diff --git a/tests/depends.d b/tests/depends.d
index d035fc5..eedfa22 100644
--- a/tests/depends.d
+++ b/tests/depends.d
@@ -1,6 +1,6 @@
src/arp.o: src/arp.cpp ../include/arp.h ../include/pdu.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:
@@ -14,14 +14,12 @@ src/arp.o: src/arp.cpp ../include/arp.h ../include/pdu.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \
../include/pdu.h ../include/endianness.h ../include/ipaddress.h \
- ../include/hwaddress.h ../include/utils.h ../include/packetsender.h \
- ../include/ethernetII.h ../include/network_interface.h \
- ../include/hwaddress.h ../include/ipaddress.h
+ ../include/hwaddress.h ../include/utils.h ../include/ethernetII.h \
+ ../include/network_interface.h ../include/hwaddress.h \
+ ../include/ipaddress.h
../include/dhcp.h:
@@ -37,8 +35,6 @@ src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/ethernetII.h:
../include/network_interface.h:
@@ -47,8 +43,8 @@ src/dhcp.o: src/dhcp.cpp ../include/dhcp.h ../include/bootp.h \
../include/ipaddress.h:
src/dns.o: src/dns.cpp ../include/dns.h ../include/pdu.h \
- ../include/endianness.h ../include/utils.h ../include/packetsender.h \
- ../include/ipaddress.h ../include/hwaddress.h
+ ../include/endianness.h ../include/utils.h ../include/ipaddress.h \
+ ../include/hwaddress.h
../include/dns.h:
@@ -58,15 +54,13 @@ src/dns.o: src/dns.cpp ../include/dns.h ../include/pdu.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
src/ethernetII_test.o: src/ethernetII_test.cpp ../include/ethernetII.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.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:
@@ -82,15 +76,13 @@ src/ethernetII_test.o: src/ethernetII_test.cpp ../include/ethernetII.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/network_interface.h:
src/hwaddress.o: src/hwaddress.cpp ../include/hwaddress.h
../include/hwaddress.h:
src/icmp.o: src/icmp.cpp ../include/icmp.h ../include/pdu.h \
- ../include/endianness.h ../include/utils.h ../include/packetsender.h \
- ../include/ipaddress.h ../include/hwaddress.h
+ ../include/endianness.h ../include/utils.h ../include/ipaddress.h \
+ ../include/hwaddress.h
../include/icmp.h:
@@ -100,28 +92,22 @@ src/icmp.o: src/icmp.cpp ../include/icmp.h ../include/pdu.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
src/ipaddress.o: src/ipaddress.cpp ../include/ipaddress.h \
- ../include/utils.h ../include/packetsender.h ../include/ipaddress.h \
- ../include/hwaddress.h
+ ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h
../include/ipaddress.h:
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
src/ip.o: src/ip.cpp ../include/ip.h ../include/pdu.h \
../include/small_uint.h ../include/endianness.h ../include/ipaddress.h \
- ../include/ipaddress.h ../include/utils.h ../include/packetsender.h \
- ../include/hwaddress.h
+ ../include/ipaddress.h ../include/utils.h ../include/hwaddress.h
../include/ip.h:
@@ -137,8 +123,6 @@ src/ip.o: src/ip.cpp ../include/ip.h ../include/pdu.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/hwaddress.h:
src/llc.o: src/llc.cpp ../include/llc.h ../include/pdu.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/network_interface.o: src/network_interface.cpp \
../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:
@@ -160,11 +144,9 @@ src/network_interface.o: src/network_interface.cpp \
../include/ipaddress.h:
../include/utils.h:
-
-../include/packetsender.h:
src/snap.o: src/snap.cpp ../include/snap.h ../include/pdu.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:
@@ -176,14 +158,12 @@ src/snap.o: src/snap.cpp ../include/snap.h ../include/pdu.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
src/tcp.o: src/tcp.cpp ../include/tcp.h ../include/pdu.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:
@@ -195,8 +175,6 @@ src/tcp.o: src/tcp.cpp ../include/tcp.h ../include/pdu.h \
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
@@ -211,13 +189,11 @@ src/udp.o: src/udp.cpp ../include/udp.h ../include/pdu.h \
../include/pdu.h:
src/utils_test.o: src/utils_test.cpp ../include/utils.h \
- ../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h \
- ../include/endianness.h ../include/ipaddress.h
+ ../include/ipaddress.h ../include/hwaddress.h ../include/endianness.h \
+ ../include/ipaddress.h
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.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/small_uint.h ../include/network_interface.h \
../include/ipaddress.h include/tests/dot11.h include/tests/dot11.h \
- ../include/utils.h ../include/packetsender.h
+ ../include/utils.h
../include/dot11.h:
@@ -499,8 +475,6 @@ include/tests/dot11.h:
include/tests/dot11.h:
../include/utils.h:
-
-../include/packetsender.h:
src/dot11/probe_request.o: src/dot11/probe_request.cpp ../include/dot11.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.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/network_interface.h ../include/ipaddress.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:
@@ -737,7 +711,7 @@ include/tests/dot11.h:
../include/rsn_information.h:
-../include/packetsender.h:
+../include/packet_sender.h:
../include/snap.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 \
../include/pdu.h ../include/endianness.h ../include/hwaddress.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/ethernetII.h:
@@ -780,7 +754,7 @@ include/tests/dot11.h:
../include/ipaddress.h:
-../include/packetsender.h:
+../include/packet_sender.h:
../include/rawpdu.h:
@@ -791,7 +765,7 @@ include/tests/dot11.h:
../include/arp.h:
../src/icmp.o: ../src/icmp.cpp ../include/icmp.h ../include/pdu.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:
@@ -803,15 +777,13 @@ include/tests/dot11.h:
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
../src/ieee802_3.o: ../src/ieee802_3.cpp ../include/ieee802_3.h \
../include/pdu.h ../include/endianness.h ../include/hwaddress.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:
@@ -825,7 +797,7 @@ include/tests/dot11.h:
../include/ipaddress.h:
-../include/packetsender.h:
+../include/packet_sender.h:
../include/llc.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 \
../include/small_uint.h ../include/endianness.h ../include/ipaddress.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/ip.h:
@@ -860,10 +832,10 @@ include/tests/dot11.h:
../include/utils.h:
-../include/packetsender.h:
-
../include/hwaddress.h:
+../include/packet_sender.h:
+
../include/constants.h:
../src/llc.o: ../src/llc.cpp ../include/pdu.h ../include/llc.h \
../include/pdu.h ../include/endianness.h ../include/rawpdu.h
@@ -879,8 +851,7 @@ include/tests/dot11.h:
../include/rawpdu.h:
../src/network_interface.o: ../src/network_interface.cpp \
../include/network_interface.h ../include/hwaddress.h \
- ../include/ipaddress.h ../include/utils.h ../include/packetsender.h \
- ../include/endianness.h
+ ../include/ipaddress.h ../include/utils.h ../include/endianness.h
../include/network_interface.h:
@@ -890,17 +861,21 @@ include/tests/dot11.h:
../include/utils.h:
-../include/packetsender.h:
-
../include/endianness.h:
-../src/packetsender.o: ../src/packetsender.cpp ../include/packetsender.h \
- ../include/pdu.h
+../src/packet_sender.o: ../src/packet_sender.cpp ../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:
../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:
@@ -908,11 +883,11 @@ include/tests/dot11.h:
../include/pdu.h:
-../include/packetsender.h:
+../include/packet_sender.h:
../src/radiotap.o: ../src/radiotap.cpp ../include/radiotap.h \
../include/pdu.h ../include/endianness.h ../include/network_interface.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:
@@ -932,7 +907,7 @@ include/tests/dot11.h:
../include/utils.h:
-../include/packetsender.h:
+../include/packet_sender.h:
../src/rawpdu.o: ../src/rawpdu.cpp ../include/rawpdu.h ../include/pdu.h
../include/rawpdu.h:
@@ -991,7 +966,7 @@ include/tests/dot11.h:
../src/tcp.o: ../src/tcp.cpp ../include/tcp.h ../include/pdu.h \
../include/endianness.h ../include/small_uint.h ../include/ip.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:
@@ -1011,8 +986,6 @@ include/tests/dot11.h:
../include/utils.h:
-../include/packetsender.h:
-
../include/hwaddress.h:
../src/tcp_stream.o: ../src/tcp_stream.cpp ../include/rawpdu.h \
../include/pdu.h ../include/tcp_stream.h ../include/sniffer.h \
@@ -1048,8 +1021,8 @@ include/tests/dot11.h:
../include/ip.h:
../src/udp.o: ../src/udp.cpp ../include/udp.h ../include/pdu.h \
../include/endianness.h ../include/constants.h ../include/utils.h \
- ../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h \
- ../include/ip.h ../include/small_uint.h ../include/rawpdu.h
+ ../include/ipaddress.h ../include/hwaddress.h ../include/ip.h \
+ ../include/small_uint.h ../include/rawpdu.h
../include/udp.h:
@@ -1061,8 +1034,6 @@ include/tests/dot11.h:
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
@@ -1073,15 +1044,14 @@ include/tests/dot11.h:
../include/rawpdu.h:
../src/utils.o: ../src/utils.cpp ../include/utils.h \
- ../include/packetsender.h ../include/ipaddress.h ../include/hwaddress.h \
- ../include/pdu.h ../include/ip.h ../include/pdu.h \
- ../include/small_uint.h ../include/endianness.h ../include/icmp.h \
- ../include/arp.h ../include/endianness.h ../include/network_interface.h
+ ../include/ipaddress.h ../include/hwaddress.h ../include/pdu.h \
+ ../include/ip.h ../include/pdu.h ../include/small_uint.h \
+ ../include/endianness.h ../include/icmp.h ../include/arp.h \
+ ../include/endianness.h ../include/network_interface.h \
+ ../include/packet_sender.h
../include/utils.h:
-../include/packetsender.h:
-
../include/ipaddress.h:
../include/hwaddress.h:
@@ -1103,3 +1073,5 @@ include/tests/dot11.h:
../include/endianness.h:
../include/network_interface.h:
+
+../include/packet_sender.h:
diff --git a/tests/src/tcp.cpp b/tests/src/tcp.cpp
index 5bd4730..722754d 100644
--- a/tests/src/tcp.cpp
+++ b/tests/src/tcp.cpp
@@ -121,58 +121,43 @@ TEST_F(TCPTest, SetFlag) {
TEST_F(TCPTest, MSS) {
TCP tcp;
- uint16_t mss = 0x456f, found_mss;
- tcp.add_mss_option(mss);
- ASSERT_TRUE(tcp.search_mss_option(&found_mss));
- EXPECT_EQ(mss, found_mss);
+ tcp.mss(0x456f);
+ EXPECT_EQ(0x456f, tcp.mss());
}
TEST_F(TCPTest, WindowScale) {
TCP tcp;
- uint8_t scale = 0x4f, found_scale;
- tcp.add_winscale_option(scale);
- ASSERT_TRUE(tcp.search_winscale_option(&found_scale));
- EXPECT_EQ(scale, found_scale);
+ tcp.winscale(0x4f);
+ EXPECT_EQ(0x4f, tcp.winscale());
}
TEST_F(TCPTest, SackPermitted) {
TCP tcp;
- tcp.add_sack_permitted_option();
- ASSERT_TRUE(tcp.search_sack_permitted_option());
+ tcp.sack_permitted();
+ ASSERT_TRUE(tcp.has_sack_permitted());
}
TEST_F(TCPTest, Sack) {
TCP tcp;
- list edges, edges_found;
+ TCP::sack_type edges;
edges.push_back(0x13);
edges.push_back(0x63fa1d7a);
edges.push_back(0xff1c);
- tcp.add_sack_option(edges);
- ASSERT_TRUE(tcp.search_sack_option(&edges_found));
- ASSERT_EQ(edges.size(), edges_found.size());
- while(edges.size()) {
- EXPECT_EQ(edges.front(), edges_found.front());
- edges.pop_front();
- edges_found.pop_front();
- }
+ tcp.sack(edges);
+ ASSERT_EQ(edges, tcp.sack());
}
TEST_F(TCPTest, AlternateChecksum) {
TCP tcp;
- uint8_t found;
- tcp.add_altchecksum_option(TCP::CHK_16FLETCHER);
- ASSERT_TRUE(tcp.search_altchecksum_option(&found));
- EXPECT_EQ(found, TCP::CHK_16FLETCHER);
+ tcp.altchecksum(TCP::CHK_16FLETCHER);
+ EXPECT_EQ(TCP::CHK_16FLETCHER, tcp.altchecksum());
}
TEST_F(TCPTest, Timestamp) {
TCP tcp;
- uint32_t value = 0x456fa23d, found_value;
- uint32_t reply = 0xfa12d345, found_reply;
- tcp.add_timestamp_option(value, reply);
- ASSERT_TRUE(tcp.search_timestamp_option(&found_value, &found_reply));
- EXPECT_EQ(value, found_value);
- EXPECT_EQ(reply, found_reply);
+ std::pair data(0x456fa23d, 0xfa12d345);
+ tcp.timestamp(data.first, data.second);
+ EXPECT_EQ(tcp.timestamp(), data);
}
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.
TEST_F(TCPTest, ConstructorFromBuffer) {
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.sport(), 0x7f4d);
@@ -202,23 +184,19 @@ TEST_F(TCPTest, ConstructorFromBuffer) {
EXPECT_EQ(tcp1.urg_ptr(), 0x1fae);
EXPECT_EQ(tcp1.data_offset(), 0xd);
- ASSERT_TRUE(tcp1.search_timestamp_option(&value32, &ovalue32));
- EXPECT_EQ(value32, 0x4fd23acb);
- EXPECT_EQ(ovalue32, 0x89fe1234);
+ EXPECT_EQ(tcp1.timestamp(), (std::pair(0x4fd23acb, 0x89fe1234)));
- EXPECT_TRUE(tcp1.search_sack_permitted_option());
+ EXPECT_TRUE(tcp1.has_sack_permitted());
- ASSERT_TRUE(tcp1.search_winscale_option(&value8));
- EXPECT_EQ(value8, 0x7a);
+ EXPECT_EQ(tcp1.winscale(), 0x7a);
- ASSERT_TRUE(tcp1.search_mss_option(&value16));
- EXPECT_EQ(value16, 0x98fa);
+ EXPECT_EQ(tcp1.mss(), 0x98fa);
- list edges;
- ASSERT_TRUE(tcp1.search_sack_option(&edges));
+ TCP::sack_type edges = tcp1.sack();
+ TCP::sack_type::const_iterator iter = edges.begin();
ASSERT_EQ(edges.size(), 2);
- EXPECT_EQ(edges.front(), 0x00010203); edges.pop_front();
- EXPECT_EQ(edges.front(), 0x04050607);
+ EXPECT_EQ(*iter++, 0x00010203);
+ EXPECT_EQ(*iter++, 0x04050607);
PDU::serialization_type buffer = tcp1.serialize();