mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Moved endianness change functions to endianness.h.
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
#include <string>
|
||||
#include "pdu.h"
|
||||
#include "ipaddress.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "hwaddress.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
@@ -115,14 +115,14 @@ namespace Tins {
|
||||
*
|
||||
* \return Returns the hardware address' format in an uint16_t.
|
||||
*/
|
||||
uint16_t hw_addr_format() const { return Utils::be_to_host(_arp.ar_hrd); }
|
||||
uint16_t hw_addr_format() const { return Endian::be_to_host(_arp.ar_hrd); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the protocol address format.
|
||||
*
|
||||
* \return Returns the protocol address' format in an uint16_t.
|
||||
*/
|
||||
uint16_t prot_addr_format() const { return Utils::be_to_host(_arp.ar_pro); }
|
||||
uint16_t prot_addr_format() const { return Endian::be_to_host(_arp.ar_pro); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the hardware address length.
|
||||
@@ -143,7 +143,7 @@ namespace Tins {
|
||||
*
|
||||
* \return Returns the ARP opcode in an uint16_t.
|
||||
*/
|
||||
uint16_t opcode() const { return Utils::be_to_host(_arp.ar_op); }
|
||||
uint16_t opcode() const { return Endian::be_to_host(_arp.ar_op); }
|
||||
|
||||
/** \brief Getter for the header size.
|
||||
* \return Returns the ARP header size.
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "ipaddress.h"
|
||||
#include "hwaddress.h"
|
||||
|
||||
@@ -114,18 +114,18 @@ namespace Tins {
|
||||
* \brief Getter for the xid field.
|
||||
* \return The xid field for this BootP PDU.
|
||||
*/
|
||||
uint32_t xid() const { return Utils::be_to_host(_bootp.xid); }
|
||||
uint32_t xid() const { return Endian::be_to_host(_bootp.xid); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the secs field.
|
||||
* \return The secs field for this BootP PDU.
|
||||
*/
|
||||
uint16_t secs() const { return Utils::be_to_host(_bootp.secs); }
|
||||
uint16_t secs() const { return Endian::be_to_host(_bootp.secs); }
|
||||
|
||||
/** \brief Getter for the padding field.
|
||||
* \return The padding field for this BootP PDU.
|
||||
*/
|
||||
uint16_t padding() const { return Utils::be_to_host(_bootp.padding); }
|
||||
uint16_t padding() const { return Endian::be_to_host(_bootp.padding); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the ciaddr field.
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "ipaddress.h"
|
||||
|
||||
namespace Tins {
|
||||
class DNS : public PDU {
|
||||
@@ -175,7 +176,7 @@ namespace Tins {
|
||||
*
|
||||
* \return uint16_t containing the value of the id field.
|
||||
*/
|
||||
uint16_t id() const { return Utils::be_to_host(dns.id); }
|
||||
uint16_t id() const { return Endian::be_to_host(dns.id); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the query response field.
|
||||
@@ -258,28 +259,28 @@ namespace Tins {
|
||||
*
|
||||
* \return uint16_t containing the value of the questions field.
|
||||
*/
|
||||
uint16_t questions() const { return Utils::be_to_host(dns.questions); }
|
||||
uint16_t questions() const { return Endian::be_to_host(dns.questions); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the answers field.
|
||||
*
|
||||
* \return uint16_t containing the value of the answers field.
|
||||
*/
|
||||
uint16_t answers() const { return Utils::be_to_host(dns.answers); }
|
||||
uint16_t answers() const { return Endian::be_to_host(dns.answers); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the authority field.
|
||||
*
|
||||
* \return uint16_t containing the value of the authority field.
|
||||
*/
|
||||
uint16_t authority() const { return Utils::be_to_host(dns.authority); }
|
||||
uint16_t authority() const { return Endian::be_to_host(dns.authority); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the additional field.
|
||||
*
|
||||
* \return uint16_t containing the value of the additional field.
|
||||
*/
|
||||
uint16_t additional() const { return Utils::be_to_host(dns.additional); }
|
||||
uint16_t additional() const { return Endian::be_to_host(dns.additional); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "network_interface.h"
|
||||
#include "hwaddress.h"
|
||||
#include "small_uint.h"
|
||||
@@ -290,7 +290,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The value of the duration/id field in an uint16_t.
|
||||
*/
|
||||
uint16_t duration_id() const { return Utils::le_to_host(_header.duration_id); }
|
||||
uint16_t duration_id() const { return Endian::le_to_host(_header.duration_id); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the first address.
|
||||
@@ -979,7 +979,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The sequence number as an uint16_t.
|
||||
*/
|
||||
uint16_t seq_num() const { return Utils::le_to_host(_ext_header.seq_control.seq_number); }
|
||||
uint16_t seq_num() const { return Endian::le_to_host(_ext_header.seq_control.seq_number); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the fourth address.
|
||||
@@ -1525,14 +1525,14 @@ namespace Tins {
|
||||
*
|
||||
* \return Timestamp value in an uint64_t.
|
||||
*/
|
||||
uint64_t timestamp() const { return Utils::le_to_host(_body.timestamp); }
|
||||
uint64_t timestamp() const { return Endian::le_to_host(_body.timestamp); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the interval field.
|
||||
*
|
||||
* \return Timestamp value in an uint16_t.
|
||||
*/
|
||||
uint16_t interval() const { return Utils::le_to_host(_body.interval); }
|
||||
uint16_t interval() const { return Endian::le_to_host(_body.interval); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the Capabilities Information structure.
|
||||
@@ -1644,7 +1644,7 @@ namespace Tins {
|
||||
*
|
||||
* \return uint16_t with the reason code.
|
||||
*/
|
||||
uint16_t reason_code() const { return Utils::le_to_host(_body.reason_code); }
|
||||
uint16_t reason_code() const { return Endian::le_to_host(_body.reason_code); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the reason code.
|
||||
@@ -1747,7 +1747,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The listen interval in an uint16_t.
|
||||
*/
|
||||
uint16_t listen_interval() const { return Utils::le_to_host(_body.listen_interval); }
|
||||
uint16_t listen_interval() const { return Endian::le_to_host(_body.listen_interval); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the listen interval.
|
||||
@@ -1851,14 +1851,14 @@ namespace Tins {
|
||||
*
|
||||
* \return The status code in an uint16_t.
|
||||
*/
|
||||
uint16_t status_code() const { return Utils::le_to_host(_body.status_code); }
|
||||
uint16_t status_code() const { return Endian::le_to_host(_body.status_code); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the AID field.
|
||||
*
|
||||
* \return The AID field value in an uint16_t.
|
||||
*/
|
||||
uint16_t aid() const { return Utils::le_to_host(_body.aid); }
|
||||
uint16_t aid() const { return Endian::le_to_host(_body.aid); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the status code.
|
||||
@@ -1970,7 +1970,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The listen interval in an uint16_t.
|
||||
*/
|
||||
uint16_t listen_interval() const { return Utils::le_to_host(_body.listen_interval); }
|
||||
uint16_t listen_interval() const { return Endian::le_to_host(_body.listen_interval); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the current ap field.
|
||||
@@ -2089,14 +2089,14 @@ namespace Tins {
|
||||
*
|
||||
* \return The status code in an uint16_t.
|
||||
*/
|
||||
uint16_t status_code() const { return Utils::le_to_host(_body.status_code); }
|
||||
uint16_t status_code() const { return Endian::le_to_host(_body.status_code); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the AID field.
|
||||
*
|
||||
* \return The AID field value in an uint16_t.
|
||||
*/
|
||||
uint16_t aid() const { return Utils::le_to_host(_body.aid); }
|
||||
uint16_t aid() const { return Endian::le_to_host(_body.aid); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the status code.
|
||||
@@ -2194,21 +2194,21 @@ namespace Tins {
|
||||
*
|
||||
* \return The authentication algorithm number in an uint16_t.
|
||||
*/
|
||||
uint16_t auth_algorithm() const {return Utils::le_to_host(_body.auth_algorithm); }
|
||||
uint16_t auth_algorithm() const {return Endian::le_to_host(_body.auth_algorithm); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the Authetication Sequence Number.
|
||||
*
|
||||
* \return The authentication sequence number in an uint16_t.
|
||||
*/
|
||||
uint16_t auth_seq_number() const {return Utils::le_to_host(_body.auth_seq_number); }
|
||||
uint16_t auth_seq_number() const {return Endian::le_to_host(_body.auth_seq_number); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the status code.
|
||||
*
|
||||
* \return The status code in an uint16_t.
|
||||
*/
|
||||
uint16_t status_code() const { return Utils::le_to_host(_body.status_code); }
|
||||
uint16_t status_code() const { return Endian::le_to_host(_body.status_code); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the Authetication Algorithm Number.
|
||||
@@ -2314,7 +2314,7 @@ namespace Tins {
|
||||
*
|
||||
* \return uint16_t with the reason code.
|
||||
*/
|
||||
uint16_t reason_code() const { return Utils::le_to_host(_body.reason_code); }
|
||||
uint16_t reason_code() const { return Endian::le_to_host(_body.reason_code); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the reason code.
|
||||
@@ -2463,14 +2463,14 @@ namespace Tins {
|
||||
*
|
||||
* \return Timestamp value in an uint64_t.
|
||||
*/
|
||||
uint64_t timestamp() const { return Utils::le_to_host(_body.timestamp); }
|
||||
uint64_t timestamp() const { return Endian::le_to_host(_body.timestamp); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the interval field.
|
||||
*
|
||||
* \return Timestamp value in an uint16_t.
|
||||
*/
|
||||
uint16_t interval() const { return Utils::le_to_host(_body.interval); }
|
||||
uint16_t interval() const { return Endian::le_to_host(_body.interval); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the Capabilities Information.
|
||||
@@ -2591,7 +2591,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The sequence number as an uint16_t.
|
||||
*/
|
||||
uint16_t seq_num() const { return Utils::le_to_host(_ext_header.seq_control.seq_number); }
|
||||
uint16_t seq_num() const { return Endian::le_to_host(_ext_header.seq_control.seq_number); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the fourth address.
|
||||
@@ -2725,7 +2725,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The value of the qos_control field in an uint16_t.
|
||||
*/
|
||||
uint16_t qos_control() const { return Utils::le_to_host(_qos_control); }
|
||||
uint16_t qos_control() const { return Endian::le_to_host(_qos_control); }
|
||||
|
||||
/**
|
||||
* \brief Setter for the qos_control field.
|
||||
@@ -3196,13 +3196,13 @@ namespace Tins {
|
||||
* \brief Getter for the bar control field.
|
||||
* \return The bar control field.
|
||||
*/
|
||||
uint16_t bar_control() const { return Utils::le_to_host(_bar_control.tid); }
|
||||
uint16_t bar_control() const { return Endian::le_to_host(_bar_control.tid); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the start sequence field.
|
||||
* \return The bar start sequence.
|
||||
*/
|
||||
uint16_t start_sequence() const { return Utils::le_to_host(_start_sequence.seq); }
|
||||
uint16_t start_sequence() const { return Endian::le_to_host(_start_sequence.seq); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the fragment number field.
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "pdu.h"
|
||||
#include "small_uint.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
|
||||
namespace Tins {
|
||||
@@ -78,7 +78,7 @@ namespace Tins {
|
||||
* \brief Getter for the length field.
|
||||
* \return The length field.
|
||||
*/
|
||||
uint16_t length() const { return Utils::be_to_host(_header.length); }
|
||||
uint16_t length() const { return Endian::be_to_host(_header.length); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the type field.
|
||||
@@ -198,13 +198,13 @@ namespace Tins {
|
||||
* \brief Getter for the key length field.
|
||||
* \return The key length field.
|
||||
*/
|
||||
uint16_t key_length() const { return Utils::be_to_host(_header.key_length); }
|
||||
uint16_t key_length() const { return Endian::be_to_host(_header.key_length); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the replay counter field.
|
||||
* \return The replay counter field.
|
||||
*/
|
||||
uint64_t replay_counter() const { return Utils::be_to_host(_header.replay_counter); }
|
||||
uint64_t replay_counter() const { return Endian::be_to_host(_header.replay_counter); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the key IV field.
|
||||
@@ -366,13 +366,13 @@ namespace Tins {
|
||||
* \brief Getter for the key length field.
|
||||
* \return The key length field.
|
||||
*/
|
||||
uint16_t key_length() const { return Utils::be_to_host(_header.key_length); }
|
||||
uint16_t key_length() const { return Endian::be_to_host(_header.key_length); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the replay counter field.
|
||||
* \return The replay counter field.
|
||||
*/
|
||||
uint64_t replay_counter() const { return Utils::be_to_host(_header.replay_counter); }
|
||||
uint64_t replay_counter() const { return Endian::be_to_host(_header.replay_counter); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the key IV field.
|
||||
@@ -390,13 +390,13 @@ namespace Tins {
|
||||
* \brief Getter for the rsc field.
|
||||
* \return The rsc field.
|
||||
*/
|
||||
uint64_t rsc() const { return Utils::be_to_host(_header.rsc); }
|
||||
uint64_t rsc() const { return Endian::be_to_host(_header.rsc); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the id field.
|
||||
* \return The id field.
|
||||
*/
|
||||
uint64_t id() const { return Utils::be_to_host(_header.id); }
|
||||
uint64_t id() const { return Endian::be_to_host(_header.id); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the mic field.
|
||||
@@ -408,7 +408,7 @@ namespace Tins {
|
||||
* \brief Getter for the wpa length field.
|
||||
* \return The wpa length field.
|
||||
*/
|
||||
uint16_t wpa_length() const { return Utils::be_to_host(_header.wpa_length); }
|
||||
uint16_t wpa_length() const { return Endian::be_to_host(_header.wpa_length); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the key field.
|
||||
|
||||
153
include/endianness.h
Normal file
153
include/endianness.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* libtins is a net packet wrapper library for crafting and
|
||||
* interpreting sniffed packets.
|
||||
*
|
||||
* Copyright (C) 2011 Nasel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef TINS_ENDIANNESS_H
|
||||
#define TINS_ENDIANNESS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef WIN32
|
||||
#include <endian.h>
|
||||
#endif
|
||||
#include "small_uint.h"
|
||||
|
||||
#define TINS_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
|
||||
#define TINS_IS_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
|
||||
namespace Tins {
|
||||
namespace Endian {
|
||||
/**
|
||||
* \brief Changes a 16-bit integral value's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint16_t change_endian(uint16_t data) {
|
||||
return ((data & 0xff00) >> 8) | ((data & 0x00ff) << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Changes a 32-bit integral value's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint32_t change_endian(uint32_t data) {
|
||||
return (((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |
|
||||
((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Changes a 64-bit integral value's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint64_t change_endian(uint64_t data) {
|
||||
return (((uint64_t)(change_endian((uint32_t)((data << 32) >> 32))) << 32) |
|
||||
(change_endian(((uint32_t)(data >> 32)))));
|
||||
}
|
||||
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
/**
|
||||
* \brief Convert any integral type to big endian.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_be(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any integral type to little endian.
|
||||
*
|
||||
* On little endian platforms, the parameter is simply returned.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_le(T data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any big endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T be_to_host(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any little endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T le_to_host(T data) {
|
||||
return data;
|
||||
}
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
/**
|
||||
* \brief Convert any integral type to big endian.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_be(T data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any integral type to little endian.
|
||||
*
|
||||
* On little endian platforms, the parameter is simply returned.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_le(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any big endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T be_to_host(T data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any little endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T le_to_host(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TINS_ENDIANNESS_H
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "hwaddress.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Tins {
|
||||
* \brief Getter for the payload_type
|
||||
* \return The payload type.
|
||||
*/
|
||||
uint16_t payload_type() const { return Utils::be_to_host(_eth.payload_type); };
|
||||
uint16_t payload_type() const { return Endian::be_to_host(_eth.payload_type); };
|
||||
|
||||
/* Setters */
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -230,28 +230,28 @@ namespace Tins {
|
||||
*
|
||||
* \return Returns the checksum as an unit16_t.
|
||||
*/
|
||||
uint16_t check() const { return Utils::be_to_host(this->_icmp.check); }
|
||||
uint16_t check() const { return Endian::be_to_host(this->_icmp.check); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the echo id.
|
||||
*
|
||||
* \return Returns the echo id.
|
||||
*/
|
||||
uint16_t id() const { return Utils::be_to_host(_icmp.un.echo.id); }
|
||||
uint16_t id() const { return Endian::be_to_host(_icmp.un.echo.id); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the echo sequence number.
|
||||
*
|
||||
* \return Returns the echo sequence number.
|
||||
*/
|
||||
uint16_t sequence() const { return Utils::be_to_host(_icmp.un.echo.sequence); }
|
||||
uint16_t sequence() const { return Endian::be_to_host(_icmp.un.echo.sequence); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the gateway field.
|
||||
*
|
||||
* \return Returns the gateways in an unit32_t.
|
||||
*/
|
||||
uint32_t gateway() const { return Utils::be_to_host(this->_icmp.un.gateway); }
|
||||
uint32_t gateway() const { return Endian::be_to_host(this->_icmp.un.gateway); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the pointer field.
|
||||
@@ -265,7 +265,7 @@ namespace Tins {
|
||||
*
|
||||
* \return Returns the mtu value in an uint16_t.
|
||||
*/
|
||||
uint16_t mtu() const { return Utils::be_to_host(this->_icmp.un.frag.mtu); }
|
||||
uint16_t mtu() const { return Endian::be_to_host(this->_icmp.un.frag.mtu); }
|
||||
|
||||
/**
|
||||
* \brief Returns the header size.
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "hwaddress.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Tins {
|
||||
* \brief Getter for the length field.
|
||||
* \return The length field value.
|
||||
*/
|
||||
uint16_t length() const { return Utils::be_to_host(_eth.length); };
|
||||
uint16_t length() const { return Endian::be_to_host(_eth.length); };
|
||||
|
||||
/* Setters */
|
||||
|
||||
|
||||
10
include/ip.h
10
include/ip.h
@@ -31,7 +31,7 @@
|
||||
#include "pdu.h"
|
||||
#include "small_uint.h"
|
||||
#include "ipaddress.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -174,21 +174,21 @@ namespace Tins {
|
||||
*
|
||||
* \return The total length of this IP PDU.
|
||||
*/
|
||||
uint16_t tot_len() const { return Utils::be_to_host(_ip.tot_len); }
|
||||
uint16_t tot_len() const { return Endian::be_to_host(_ip.tot_len); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the id field.
|
||||
*
|
||||
* \return The id for this IP PDU.
|
||||
*/
|
||||
uint16_t id() const { return Utils::be_to_host(_ip.id); }
|
||||
uint16_t id() const { return Endian::be_to_host(_ip.id); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the fragment offset field.
|
||||
*
|
||||
* \return The fragment offset for this IP PDU.
|
||||
*/
|
||||
uint16_t frag_off() const { return Utils::be_to_host(_ip.frag_off); }
|
||||
uint16_t frag_off() const { return Endian::be_to_host(_ip.frag_off); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the time to live field.
|
||||
@@ -209,7 +209,7 @@ namespace Tins {
|
||||
*
|
||||
* \return The checksum for this IP PDU.
|
||||
*/
|
||||
uint16_t check() const { return Utils::be_to_host(_ip.check); }
|
||||
uint16_t check() const { return Endian::be_to_host(_ip.check); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the source address field.
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <utility>
|
||||
#include <stdint.h>
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
namespace Tins {
|
||||
@@ -185,67 +186,67 @@ namespace Tins {
|
||||
* \brief Getter for the version field.
|
||||
* \return The version field.
|
||||
*/
|
||||
inline uint8_t version() const { return _radio.it_version; }
|
||||
uint8_t version() const { return _radio.it_version; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the padding field.
|
||||
* \return The padding field.
|
||||
*/
|
||||
inline uint8_t padding() const { return _radio.it_pad; }
|
||||
uint8_t padding() const { return _radio.it_pad; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the length field.
|
||||
* \return The length field.
|
||||
*/
|
||||
inline uint8_t length() const { return _radio.it_len; }
|
||||
uint8_t length() const { return _radio.it_len; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the tsft field.
|
||||
* \return The tsft field.
|
||||
*/
|
||||
inline uint64_t tsft() const { return _tsft; }
|
||||
uint64_t tsft() const { return Endian::le_to_host(_tsft); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the flags field.
|
||||
* \return The flags field.
|
||||
*/
|
||||
inline FrameFlags flags() const { return (FrameFlags)_flags; }
|
||||
FrameFlags flags() const { return (FrameFlags)_flags; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the rate field.
|
||||
* \return The rate field.
|
||||
*/
|
||||
inline uint8_t rate() const { return _rate; }
|
||||
uint8_t rate() const { return _rate; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the channel frequency field.
|
||||
* \return The channel frequency field.
|
||||
*/
|
||||
inline uint16_t channel_freq() const { return _channel_freq; }
|
||||
uint16_t channel_freq() const { return Endian::le_to_host(_channel_freq); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the channel type field.
|
||||
* \return The channel type field.
|
||||
*/
|
||||
inline uint16_t channel_type() const { return _channel_type; }
|
||||
uint16_t channel_type() const { return Endian::le_to_host(_channel_type); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the dbm signal field.
|
||||
* \return The dbm signal field.
|
||||
*/
|
||||
inline uint8_t dbm_signal() const { return _dbm_signal; }
|
||||
uint8_t dbm_signal() const { return _dbm_signal; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the antenna field.
|
||||
* \return The antenna field.
|
||||
*/
|
||||
inline uint8_t antenna() const { return _antenna; }
|
||||
uint8_t antenna() const { return _antenna; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the rx flags field.
|
||||
* \return The rx flags field.
|
||||
*/
|
||||
inline uint16_t rx_flags() const { return _rx_flags; }
|
||||
uint16_t rx_flags() const { return Endian::le_to_host(_rx_flags); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the present bit fields.
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
namespace Tins{
|
||||
/**
|
||||
@@ -72,6 +72,12 @@ namespace Tins{
|
||||
*/
|
||||
RSNInformation();
|
||||
|
||||
/**
|
||||
* \brief Constructor from buffer.
|
||||
*
|
||||
* \param buffer The buffer from which this object will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
RSNInformation(const uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
/**
|
||||
@@ -123,13 +129,13 @@ namespace Tins{
|
||||
* \brief Getter for the version field.
|
||||
* \return The version field.
|
||||
*/
|
||||
uint16_t version() const { return Utils::le_to_host(_version); }
|
||||
uint16_t version() const { return Endian::le_to_host(_version); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the capabilities field.
|
||||
* \return The version field.
|
||||
*/
|
||||
uint16_t capabilities() const { return Utils::le_to_host(_capabilities); }
|
||||
uint16_t capabilities() const { return Endian::le_to_host(_capabilities); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the pairwise cypher suite list.
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef TINS_IEEE8022_H
|
||||
#define TINS_IEEE8022_H
|
||||
#ifndef TINS_SNAP_H
|
||||
#define TINS_SNAP_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -58,35 +59,19 @@ namespace Tins {
|
||||
*/
|
||||
SNAP(const uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
/**
|
||||
* \brief Copy constructor.
|
||||
*/
|
||||
SNAP(const SNAP &other);
|
||||
|
||||
/**
|
||||
* \brief Copy assignment operator.
|
||||
*/
|
||||
SNAP &operator= (const SNAP &other);
|
||||
|
||||
/* Setters */
|
||||
|
||||
/**
|
||||
* \brief Setter for the id field.
|
||||
* \param new_id The new id to be set.
|
||||
* \brief Setter for the control field.
|
||||
* \param new_id The new control to be set.
|
||||
*/
|
||||
void id(uint8_t new_id);
|
||||
|
||||
/**
|
||||
* \brief Setter for the poll field.
|
||||
* \param new_poll The new poll to be set.
|
||||
*/
|
||||
void poll(uint8_t new_poll);
|
||||
void control(uint8_t new_control);
|
||||
|
||||
/**
|
||||
* \brief Setter for the org code field.
|
||||
* \param new_org The new org code to be set.
|
||||
*/
|
||||
void org_code(uint32_t new_org);
|
||||
void org_code(small_uint<24> new_org);
|
||||
|
||||
/**
|
||||
* \brief Setter for the eth type field.
|
||||
@@ -109,28 +94,28 @@ namespace Tins {
|
||||
uint8_t ssap() const { return _snap.ssap; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the id field.
|
||||
* \return The id field.
|
||||
* \brief Getter for the control field.
|
||||
* \return The control field.
|
||||
*/
|
||||
uint8_t id() const { return _snap.id; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the poll field.
|
||||
* \return The poll field.
|
||||
*/
|
||||
uint8_t poll() const { return _snap.poll; }
|
||||
uint8_t control() const { return _snap.control; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the org code field.
|
||||
* \return The org code field.
|
||||
*/
|
||||
uint32_t org_code() const { return _snap.org_code; }
|
||||
small_uint<24> org_code() const {
|
||||
#ifdef TINS_IS_LITTLE_ENDIAN
|
||||
return Endian::be_to_host<uint32_t>(_snap.org_code << 8);
|
||||
#else
|
||||
return Endian::be_to_host(_snap.org_code);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the eth type field.
|
||||
* \return The eth field.
|
||||
*/
|
||||
uint16_t eth_type() const { return Utils::be_to_host(_snap.eth_type); }
|
||||
uint16_t eth_type() const { return Endian::be_to_host(_snap.eth_type); }
|
||||
|
||||
/**
|
||||
* \brief Returns the SNAP frame's header length.
|
||||
@@ -151,28 +136,23 @@ namespace Tins {
|
||||
*
|
||||
* \sa PDU::clone_pdu
|
||||
*/
|
||||
PDU *clone_pdu() const;
|
||||
SNAP *clone_pdu() const {
|
||||
return new SNAP(*this);
|
||||
}
|
||||
private:
|
||||
struct snaphdr {
|
||||
uint8_t dsap;
|
||||
uint8_t ssap;
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
uint32_t id:2,
|
||||
reserved1:2,
|
||||
poll:2,
|
||||
reserved2:2,
|
||||
uint32_t control:8,
|
||||
org_code:24;
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
uint32_t reserved1:2,
|
||||
poll:2,
|
||||
reserved2:2,
|
||||
id:2,
|
||||
org_code:24;
|
||||
uint32_t org_code:24,
|
||||
control:8;
|
||||
#endif
|
||||
uint16_t eth_type;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
void copy_fields(const SNAP *other);
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
snaphdr _snap;
|
||||
@@ -180,4 +160,4 @@ namespace Tins {
|
||||
|
||||
};
|
||||
|
||||
#endif // TINS_IEEE8022_H
|
||||
#endif // TINS_SNAP_H
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#endif
|
||||
#include "pdu.h"
|
||||
#include "small_uint.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
|
||||
namespace Tins {
|
||||
@@ -142,49 +142,49 @@ namespace Tins {
|
||||
*
|
||||
* \return The destination port in an uint16_t.
|
||||
*/
|
||||
uint16_t dport() const { return Utils::be_to_host(_tcp.dport); }
|
||||
uint16_t dport() const { return Endian::be_to_host(_tcp.dport); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the source port field.
|
||||
*
|
||||
* \return The source port in an uint16_t.
|
||||
*/
|
||||
uint16_t sport() const { return Utils::be_to_host(_tcp.sport); }
|
||||
uint16_t sport() const { return Endian::be_to_host(_tcp.sport); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the sequence number field.
|
||||
*
|
||||
* \return The sequence number in an uint32_t.
|
||||
*/
|
||||
uint32_t seq() const { return Utils::be_to_host(_tcp.seq); }
|
||||
uint32_t seq() const { return Endian::be_to_host(_tcp.seq); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the acknowledge number field.
|
||||
*
|
||||
* \return The acknowledge number in an uint32_t.
|
||||
*/
|
||||
uint32_t ack_seq() const { return Utils::be_to_host(_tcp.ack_seq); }
|
||||
uint32_t ack_seq() const { return Endian::be_to_host(_tcp.ack_seq); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the window size field.
|
||||
*
|
||||
* \return The window size in an uint32_t.
|
||||
*/
|
||||
uint16_t window() const { return Utils::be_to_host(_tcp.window); }
|
||||
uint16_t window() const { return Endian::be_to_host(_tcp.window); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the checksum field.
|
||||
*
|
||||
* \return The checksum field in an uint16_t.
|
||||
*/
|
||||
uint16_t check() const { return Utils::be_to_host(_tcp.check); }
|
||||
uint16_t check() const { return Endian::be_to_host(_tcp.check); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the urgent pointer field.
|
||||
*
|
||||
* \return The urgent pointer in an uint16_t.
|
||||
*/
|
||||
uint16_t urg_ptr() const { return Utils::be_to_host(_tcp.urg_ptr); }
|
||||
uint16_t urg_ptr() const { return Endian::be_to_host(_tcp.urg_ptr); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the data offset field.
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __UDP_H
|
||||
#define __UDP_H
|
||||
#ifndef TINS_UDP_H
|
||||
#define TINS_UDP_H
|
||||
|
||||
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -63,19 +63,19 @@ namespace Tins {
|
||||
* \brief Getter for the destination port.
|
||||
* \return The datagram's destination port.
|
||||
*/
|
||||
uint16_t dport() const { return Utils::be_to_host(_udp.dport); }
|
||||
uint16_t dport() const { return Endian::be_to_host(_udp.dport); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the source port.
|
||||
* \return The datagram's source port.
|
||||
*/
|
||||
uint16_t sport() const { return Utils::be_to_host(_udp.sport); }
|
||||
uint16_t sport() const { return Endian::be_to_host(_udp.sport); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the length of the datagram.
|
||||
* \return The length of the datagram.
|
||||
*/
|
||||
uint16_t length() const { return Utils::be_to_host(_udp.len); }
|
||||
uint16_t length() const { return Endian::be_to_host(_udp.len); }
|
||||
|
||||
/**
|
||||
* \brief Set the destination port.
|
||||
@@ -95,18 +95,6 @@ namespace Tins {
|
||||
*/
|
||||
void length(uint16_t new_len);
|
||||
|
||||
/** \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 UDP::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 Returns the header size.
|
||||
*
|
||||
* This metod overrides PDU::header_size. This size includes the
|
||||
@@ -124,7 +112,7 @@ namespace Tins {
|
||||
* \sa PDU::clone_pdu
|
||||
*/
|
||||
PDU *clone_pdu() const {
|
||||
return do_clone_pdu<UDP>();
|
||||
return new UDP(*this);
|
||||
}
|
||||
private:
|
||||
struct udphdr {
|
||||
@@ -141,4 +129,4 @@ namespace Tins {
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // TINS_UDP_H
|
||||
|
||||
149
include/utils.h
149
include/utils.h
@@ -19,8 +19,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __UTILS_H
|
||||
#define __UTILS_H
|
||||
#ifndef TINS_UTILS_H
|
||||
#define TINS_UTILS_H
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -143,149 +143,6 @@ namespace Tins {
|
||||
template<class ForwardIterator>
|
||||
void route_entries(ForwardIterator output);
|
||||
|
||||
/**
|
||||
* \brief Changes a 16-bit integral value's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint16_t change_endian(uint16_t data) {
|
||||
return ((data & 0xff00) >> 8) | ((data & 0x00ff) << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Changes a 32-bit integral value's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint32_t change_endian(uint32_t data) {
|
||||
return (((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |
|
||||
((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Changes a 64-bit integral value's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint64_t change_endian(uint64_t data) {
|
||||
return (((uint64_t)(change_endian((uint32_t)((data << 32) >> 32))) << 32) |
|
||||
(change_endian(((uint32_t)(data >> 32)))));
|
||||
}
|
||||
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
/**
|
||||
* \brief Convert any integral type to big endian.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_be(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any integral type to little endian.
|
||||
*
|
||||
* On little endian platforms, the parameter is simply returned.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_le(T data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any big endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T be_to_host(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any little endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T le_to_host(T data) {
|
||||
return data;
|
||||
}
|
||||
#elif TINS_IS_BIG_ENDIAN
|
||||
/**
|
||||
* \brief Convert any integral type to big endian.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_be(T data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any integral type to little endian.
|
||||
*
|
||||
* On little endian platforms, the parameter is simply returned.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T host_to_le(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any big endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T be_to_host(T data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert any little endian value to the host's endianess.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T le_to_host(T data) {
|
||||
return change_endian(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \brief Convert 16 bit integer into network byte order.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint16_t net_to_host_s(uint16_t data) {
|
||||
return ((data & 0xff00) >> 8) | ((data & 0x00ff) << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert 32 bit integer into network byte order.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint32_t net_to_host_l(uint32_t data) {
|
||||
return (((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |
|
||||
((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Convert 64 bit integer into network byte order.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
*/
|
||||
inline uint64_t net_to_host_ll(uint64_t data) {
|
||||
return (((uint64_t)(net_to_host_l((uint32_t)((data << 32) >> 32))) << 32) |
|
||||
(net_to_host_l(((uint32_t)(data >> 32)))));
|
||||
}
|
||||
|
||||
/** \brief Returns the 32 bit crc of the given buffer.
|
||||
*
|
||||
* \param data The input buffer.
|
||||
@@ -371,4 +228,4 @@ void Tins::Utils::route_entries(ForwardIterator output) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // TINS_UTILS_H
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "ip.h"
|
||||
#include "ethernetII.h"
|
||||
#include "rawpdu.h"
|
||||
#include "utils.h"
|
||||
#include "constants.h"
|
||||
|
||||
|
||||
@@ -52,7 +51,7 @@ ARP::ARP(ipaddress_type target_ip, ipaddress_type sender_ip,
|
||||
}
|
||||
|
||||
ARP::ARP(const uint8_t *buffer, uint32_t total_sz)
|
||||
: PDU(Utils::host_to_be<uint16_t>(Constants::Ethernet::ARP))
|
||||
: PDU(Endian::host_to_be<uint16_t>(Constants::Ethernet::ARP))
|
||||
{
|
||||
if(total_sz < sizeof(arphdr))
|
||||
throw runtime_error("Not enough size for an ARP header in the buffer.");
|
||||
@@ -79,11 +78,11 @@ void ARP::target_ip_addr(ipaddress_type new_tgt_ip_addr) {
|
||||
}
|
||||
|
||||
void ARP::hw_addr_format(uint16_t new_hw_addr_fmt) {
|
||||
this->_arp.ar_hrd = Utils::host_to_be(new_hw_addr_fmt);
|
||||
this->_arp.ar_hrd = Endian::host_to_be(new_hw_addr_fmt);
|
||||
}
|
||||
|
||||
void ARP::prot_addr_format(uint16_t new_prot_addr_fmt) {
|
||||
this->_arp.ar_pro = Utils::host_to_be(new_prot_addr_fmt);
|
||||
this->_arp.ar_pro = Endian::host_to_be(new_prot_addr_fmt);
|
||||
}
|
||||
|
||||
void ARP::hw_addr_length(uint8_t new_hw_addr_len) {
|
||||
@@ -95,7 +94,7 @@ void ARP::prot_addr_length(uint8_t new_prot_addr_len) {
|
||||
}
|
||||
|
||||
void ARP::opcode(Flags new_opcode) {
|
||||
this->_arp.ar_op = Utils::host_to_be<uint16_t>(new_opcode);
|
||||
this->_arp.ar_op = Endian::host_to_be<uint16_t>(new_opcode);
|
||||
}
|
||||
|
||||
uint32_t ARP::header_size() const {
|
||||
|
||||
@@ -63,15 +63,15 @@ void BootP::hops(uint8_t new_hops) {
|
||||
}
|
||||
|
||||
void BootP::xid(uint32_t new_xid) {
|
||||
_bootp.xid = Utils::host_to_be(new_xid);
|
||||
_bootp.xid = Endian::host_to_be(new_xid);
|
||||
}
|
||||
|
||||
void BootP::secs(uint16_t new_secs) {
|
||||
_bootp.secs = Utils::host_to_be(new_secs);
|
||||
_bootp.secs = Endian::host_to_be(new_secs);
|
||||
}
|
||||
|
||||
void BootP::padding(uint16_t new_padding) {
|
||||
_bootp.padding = Utils::host_to_be(new_padding);
|
||||
_bootp.padding = Endian::host_to_be(new_padding);
|
||||
}
|
||||
|
||||
void BootP::ciaddr(ipaddress_type new_ciaddr) {
|
||||
|
||||
19
src/dhcp.cpp
19
src/dhcp.cpp
@@ -22,7 +22,7 @@
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "dhcp.h"
|
||||
#include "ethernetII.h"
|
||||
|
||||
@@ -33,8 +33,7 @@ using std::runtime_error;
|
||||
namespace Tins {
|
||||
const uint32_t DHCP::MAX_DHCP_SIZE = 312;
|
||||
|
||||
/* Magic cookie: uint32_t.
|
||||
* end of options: 1 byte. */
|
||||
// Magic cookie: uint32_t.
|
||||
DHCP::DHCP() : _size(sizeof(uint32_t)) {
|
||||
opcode(BOOTREQUEST);
|
||||
htype(1); //ethernet
|
||||
@@ -47,7 +46,7 @@ DHCP::DHCP(const uint8_t *buffer, uint32_t total_sz)
|
||||
buffer += BootP::header_size() - vend().size();
|
||||
total_sz -= BootP::header_size() - vend().size();
|
||||
uint8_t args[2] = {0};
|
||||
if(total_sz < sizeof(uint32_t) || *(uint32_t*)buffer != Utils::host_to_be<uint32_t>(0x63825363))
|
||||
if(total_sz < sizeof(uint32_t) || *(uint32_t*)buffer != Endian::host_to_be<uint32_t>(0x63825363))
|
||||
throw std::runtime_error("Not enough size for a DHCP header in the buffer.");
|
||||
buffer += sizeof(uint32_t);
|
||||
total_sz -= sizeof(uint32_t);
|
||||
@@ -115,7 +114,7 @@ bool DHCP::search_server_identifier(ipaddress_type *value) {
|
||||
}
|
||||
|
||||
bool DHCP::add_lease_time(uint32_t time) {
|
||||
time = Utils::host_to_be(time);
|
||||
time = Endian::host_to_be(time);
|
||||
return add_option(DHCP_LEASE_TIME, sizeof(uint32_t), (const uint8_t*)&time);
|
||||
}
|
||||
|
||||
@@ -124,7 +123,7 @@ bool DHCP::search_lease_time(uint32_t *value) {
|
||||
}
|
||||
|
||||
bool DHCP::add_renewal_time(uint32_t time) {
|
||||
time = Utils::host_to_be(time);
|
||||
time = Endian::host_to_be(time);
|
||||
return add_option(DHCP_RENEWAL_TIME, sizeof(uint32_t), (const uint8_t*)&time);
|
||||
}
|
||||
|
||||
@@ -192,7 +191,7 @@ bool DHCP::search_domain_name(std::string *value) {
|
||||
}
|
||||
|
||||
bool DHCP::add_rebind_time(uint32_t time) {
|
||||
time = Utils::host_to_be(time);
|
||||
time = Endian::host_to_be(time);
|
||||
return add_option(DHCP_REBINDING_TIME, sizeof(uint32_t), (uint8_t*)&time);
|
||||
}
|
||||
|
||||
@@ -220,7 +219,7 @@ void DHCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa
|
||||
result.resize(_size);
|
||||
uint8_t *ptr = &result[0] + sizeof(uint32_t);
|
||||
// Magic cookie
|
||||
*((uint32_t*)&result[0]) = Utils::host_to_be<uint32_t>(0x63825363);
|
||||
*((uint32_t*)&result[0]) = Endian::host_to_be<uint32_t>(0x63825363);
|
||||
for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
|
||||
*(ptr++) = it->option;
|
||||
*(ptr++) = it->value.size();
|
||||
@@ -256,7 +255,7 @@ bool DHCP::generic_search(Options opt, std::string *str) {
|
||||
|
||||
bool DHCP::generic_search(Options opt, uint32_t *value) {
|
||||
if(generic_search<uint32_t>(opt, value)) {
|
||||
*value = Utils::host_to_be(*value);
|
||||
*value = Endian::host_to_be(*value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -265,7 +264,7 @@ bool DHCP::generic_search(Options opt, uint32_t *value) {
|
||||
bool DHCP::generic_search(Options opt, ipaddress_type *value) {
|
||||
uint32_t ip_int;
|
||||
if(generic_search(opt, &ip_int)) {
|
||||
*value = IPv4Address(Utils::host_to_be(ip_int));
|
||||
*value = IPv4Address(Endian::host_to_be(ip_int));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
52
src/dns.cpp
52
src/dns.cpp
@@ -101,8 +101,8 @@ const uint8_t *DNS::build_resource_list(list<ResourceRecord*> &lst, const uint8_
|
||||
// Probably convert to be this constant
|
||||
if((*ptr & 0xc0)) {
|
||||
uint16_t offset(*reinterpret_cast<const uint16_t*>(ptr));
|
||||
offset = Utils::be_to_host(offset) & 0x3fff;
|
||||
res.reset(new OffsetedResourceRecord(Utils::host_to_be(offset)));
|
||||
offset = Endian::be_to_host(offset) & 0x3fff;
|
||||
res.reset(new OffsetedResourceRecord(Endian::host_to_be(offset)));
|
||||
ptr += sizeof(uint16_t);
|
||||
}
|
||||
else {
|
||||
@@ -124,7 +124,7 @@ const uint8_t *DNS::build_resource_list(list<ResourceRecord*> &lst, const uint8_
|
||||
|
||||
// Store the option size.
|
||||
res->data.resize(
|
||||
Utils::be_to_host(*reinterpret_cast<const uint16_t*>(ptr))
|
||||
Endian::be_to_host(*reinterpret_cast<const uint16_t*>(ptr))
|
||||
);
|
||||
ptr += sizeof(uint16_t);
|
||||
if(ptr + res->data.size() > ptr_end)
|
||||
@@ -149,7 +149,7 @@ uint32_t DNS::header_size() const {
|
||||
}
|
||||
|
||||
void DNS::id(uint16_t new_id) {
|
||||
dns.id = Utils::host_to_be(new_id);
|
||||
dns.id = Endian::host_to_be(new_id);
|
||||
}
|
||||
|
||||
void DNS::type(QRType new_qr) {
|
||||
@@ -193,7 +193,7 @@ void DNS::rcode(uint8_t new_rcode) {
|
||||
}
|
||||
|
||||
bool DNS::contains_dname(uint16_t type) {
|
||||
type = Utils::be_to_host(type);
|
||||
type = Endian::be_to_host(type);
|
||||
return type == MX || type == CNAME ||
|
||||
type == PTR || type == NS;
|
||||
}
|
||||
@@ -204,11 +204,11 @@ void DNS::add_query(const string &name, QueryType type, QueryClass qclass) {
|
||||
|
||||
queries.push_back(
|
||||
Query(new_str,
|
||||
Utils::host_to_be<uint16_t>(type),
|
||||
Utils::host_to_be<uint16_t>(qclass))
|
||||
Endian::host_to_be<uint16_t>(type),
|
||||
Endian::host_to_be<uint16_t>(qclass))
|
||||
);
|
||||
extra_size += new_str.size() + 1 + (sizeof(uint16_t) << 1);
|
||||
dns.questions = Utils::host_to_be<uint16_t>(queries.size());
|
||||
dns.questions = Endian::host_to_be<uint16_t>(queries.size());
|
||||
}
|
||||
|
||||
void DNS::add_query(const Query &query) {
|
||||
@@ -220,9 +220,9 @@ void DNS::add_query(const Query &query) {
|
||||
}
|
||||
|
||||
void DNS::add_answer(const string &name, QueryType type, QueryClass qclass, uint32_t ttl, IPv4Address ip) {
|
||||
ResourceRecord *res = make_record(name, type, qclass, ttl, Utils::host_to_be((uint32_t)ip));
|
||||
ResourceRecord *res = make_record(name, type, qclass, ttl, Endian::host_to_be((uint32_t)ip));
|
||||
ans.push_back(res);
|
||||
dns.answers = Utils::host_to_be<uint16_t>(ans.size());
|
||||
dns.answers = Endian::host_to_be<uint16_t>(ans.size());
|
||||
}
|
||||
|
||||
void DNS::add_answer(const std::string &name, QueryType type, QueryClass qclass,
|
||||
@@ -231,31 +231,31 @@ void DNS::add_answer(const std::string &name, QueryType type, QueryClass qclass,
|
||||
parse_domain_name(dname, new_str);
|
||||
ResourceRecord *res = make_record(name, type, qclass, ttl, new_str);
|
||||
ans.push_back(res);
|
||||
dns.answers = Utils::host_to_be<uint16_t>(ans.size());
|
||||
dns.answers = Endian::host_to_be<uint16_t>(ans.size());
|
||||
}
|
||||
|
||||
void DNS::add_answer(const std::string &name, QueryType type, QueryClass qclass,
|
||||
uint32_t ttl, const uint8_t *data, uint32_t sz) {
|
||||
ResourceRecord *res = make_record(name, type, qclass, ttl, data, sz);
|
||||
ans.push_back(res);
|
||||
dns.answers = Utils::host_to_be<uint16_t>(ans.size());
|
||||
dns.answers = Endian::host_to_be<uint16_t>(ans.size());
|
||||
}
|
||||
|
||||
void DNS::add_authority(const string &name, QueryType type,
|
||||
QueryClass qclass, uint32_t ttl, const uint8_t *data, uint32_t sz) {
|
||||
ResourceRecord *res = make_record(name, type, qclass, ttl, data, sz);
|
||||
arity.push_back(res);
|
||||
dns.authority = Utils::host_to_be<uint16_t>(arity.size());
|
||||
dns.authority = Endian::host_to_be<uint16_t>(arity.size());
|
||||
}
|
||||
|
||||
void DNS::add_additional(const string &name, QueryType type, QueryClass qclass, uint32_t ttl, uint32_t ip) {
|
||||
ResourceRecord *res = make_record(name, type, qclass, ttl, ip);
|
||||
addit.push_back(res);
|
||||
dns.additional = Utils::host_to_be<uint16_t>(addit.size());
|
||||
dns.additional = Endian::host_to_be<uint16_t>(addit.size());
|
||||
}
|
||||
|
||||
DNS::ResourceRecord *DNS::make_record(const std::string &name, QueryType type, QueryClass qclass, uint32_t ttl, uint32_t ip) {
|
||||
ip = Utils::host_to_be(ip);
|
||||
ip = Endian::host_to_be(ip);
|
||||
return make_record(name, type, qclass, ttl, reinterpret_cast<uint8_t*>(&ip), sizeof(ip));
|
||||
}
|
||||
|
||||
@@ -269,12 +269,12 @@ DNS::ResourceRecord *DNS::make_record(const std::string &name, QueryType type, Q
|
||||
uint16_t index = find_domain_name(nm);
|
||||
ResourceRecord *res;
|
||||
if(index)
|
||||
res = new OffsetedResourceRecord(Utils::host_to_be(index), ptr, len);
|
||||
res = new OffsetedResourceRecord(Endian::host_to_be(index), ptr, len);
|
||||
else
|
||||
res = new NamedResourceRecord(nm, ptr, len);
|
||||
res->info.type = Utils::host_to_be<uint16_t>(type);
|
||||
res->info.qclass = Utils::host_to_be<uint16_t>(qclass);
|
||||
res->info.ttl = Utils::host_to_be(ttl);
|
||||
res->info.type = Endian::host_to_be<uint16_t>(type);
|
||||
res->info.qclass = Endian::host_to_be<uint16_t>(qclass);
|
||||
res->info.ttl = Endian::host_to_be(ttl);
|
||||
extra_size += res->size();
|
||||
return res;
|
||||
}
|
||||
@@ -389,7 +389,7 @@ uint32_t DNS::build_suffix_map(uint32_t index, const list<ResourceRecord*> &lst)
|
||||
index += sizeof(ResourceRecord::Info) + sizeof(uint16_t);
|
||||
uint32_t sz((*it)->data_size());
|
||||
const uint8_t *ptr = (*it)->data_pointer();
|
||||
if(Utils::be_to_host((*it)->info.type) == MX) {
|
||||
if(Endian::be_to_host((*it)->info.type) == MX) {
|
||||
ptr += 2;
|
||||
sz -= 2;
|
||||
index += 2;
|
||||
@@ -423,7 +423,7 @@ void DNS::compose_name(const uint8_t *ptr, uint32_t sz, std::string &out) {
|
||||
if(i && ptr[i])
|
||||
out.push_back('.');
|
||||
if((ptr[i] & 0xc0)) {
|
||||
uint16_t index = Utils::be_to_host(*((uint16_t*)(ptr + i)));
|
||||
uint16_t index = Endian::be_to_host(*((uint16_t*)(ptr + i)));
|
||||
index &= 0x3fff;
|
||||
SuffixMap::iterator it(suffixes.find(index));
|
||||
SuffixIndices::iterator suff_it(suffix_indices.find(index));
|
||||
@@ -477,15 +477,15 @@ void DNS::convert_resources(const ResourcesType &lst, std::list<Resource> &res)
|
||||
if(sz == 4)
|
||||
addr = IPv4Address(*(uint32_t*)ptr).to_string();
|
||||
else {
|
||||
if(Utils::be_to_host((*it)->info.type) == MX) {
|
||||
if(Endian::be_to_host((*it)->info.type) == MX) {
|
||||
ptr += 2;
|
||||
sz -= 2;
|
||||
}
|
||||
compose_name(ptr, sz, addr);
|
||||
}
|
||||
res.push_back(
|
||||
Resource(dname, addr, Utils::be_to_host((*it)->info.type),
|
||||
Utils::host_to_be((*it)->info.qclass), Utils::be_to_host((*it)->info.ttl)
|
||||
Resource(dname, addr, Endian::be_to_host((*it)->info.type),
|
||||
Endian::host_to_be((*it)->info.qclass), Endian::be_to_host((*it)->info.ttl)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -496,7 +496,7 @@ DNS::queries_type DNS::dns_queries() const {
|
||||
for(std::list<Query>::const_iterator it(queries.begin()); it != queries.end(); ++it) {
|
||||
string dn;
|
||||
unparse_domain_name(it->name, dn);
|
||||
output.push_back(Query(dn, Utils::be_to_host(it->type), Utils::be_to_host(it->qclass)));
|
||||
output.push_back(Query(dn, Endian::be_to_host(it->type), Endian::be_to_host(it->qclass)));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@@ -529,7 +529,7 @@ uint32_t DNS::ResourceRecord::write(uint8_t *buffer) const {
|
||||
buffer += sz;
|
||||
std::memcpy(buffer, &info, sizeof(info));
|
||||
buffer += sizeof(info);
|
||||
*((uint16_t*)buffer) = Utils::host_to_be(data.size());
|
||||
*((uint16_t*)buffer) = Endian::host_to_be(data.size());
|
||||
buffer += sizeof(uint16_t);
|
||||
std::copy(data.begin(), data.end(), buffer);
|
||||
return sz + sizeof(info) + sizeof(uint16_t) + data.size();
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "rawpdu.h"
|
||||
#include "radiotap.h"
|
||||
#include "sniffer.h"
|
||||
#include "utils.h"
|
||||
#include "rsn_information.h"
|
||||
#include "snap.h"
|
||||
|
||||
@@ -146,7 +145,7 @@ void Dot11::order(small_uint<1> new_value) {
|
||||
}
|
||||
|
||||
void Dot11::duration_id(uint16_t new_duration_id) {
|
||||
this->_header.duration_id = Utils::host_to_le(new_duration_id);
|
||||
this->_header.duration_id = Endian::host_to_le(new_duration_id);
|
||||
}
|
||||
|
||||
void Dot11::addr1(const address_type &new_addr1) {
|
||||
@@ -167,8 +166,8 @@ bool Dot11::send(PacketSender* sender) {
|
||||
|
||||
memset(&addr, 0, sizeof(struct sockaddr_ll));
|
||||
|
||||
addr.sll_family = Utils::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Utils::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_halen = 6;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _header.addr1, 6);
|
||||
@@ -316,7 +315,7 @@ void Dot11ManagementFrame::frag_num(uint8_t new_frag_num) {
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::seq_num(uint16_t new_seq_num) {
|
||||
this->_ext_header.seq_control.seq_number = Utils::host_to_le(new_seq_num);
|
||||
this->_ext_header.seq_control.seq_number = Endian::host_to_le(new_seq_num);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::addr4(const address_type &new_addr4) {
|
||||
@@ -402,10 +401,10 @@ void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, ui
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
uint32_t* ptr = (uint32_t*)(buffer + 2);
|
||||
*(ptr++) = Utils::host_to_le(ac_be);
|
||||
*(ptr++) = Utils::host_to_le(ac_bk);
|
||||
*(ptr++) = Utils::host_to_le(ac_vi);
|
||||
*(ptr++) = Utils::host_to_le(ac_vo);
|
||||
*(ptr++) = Endian::host_to_le(ac_be);
|
||||
*(ptr++) = Endian::host_to_le(ac_bk);
|
||||
*(ptr++) = Endian::host_to_le(ac_vi);
|
||||
*(ptr++) = Endian::host_to_le(ac_vo);
|
||||
add_tagged_option(EDCA, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
@@ -418,7 +417,7 @@ void Dot11ManagementFrame::request_information(const request_info_type elements)
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::fh_parameter_set(fh_params_set fh_params) {
|
||||
fh_params.dwell_time = Utils::host_to_le(fh_params.dwell_time);
|
||||
fh_params.dwell_time = Endian::host_to_le(fh_params.dwell_time);
|
||||
fh_params.hop_set = fh_params.hop_set;
|
||||
fh_params.hop_pattern = fh_params.hop_pattern;
|
||||
fh_params.hop_index = fh_params.hop_index;
|
||||
@@ -433,13 +432,13 @@ void Dot11ManagementFrame::ds_parameter_set(uint8_t current_channel) {
|
||||
void Dot11ManagementFrame::cf_parameter_set(cf_params_set params) {
|
||||
params.cfp_count = params.cfp_count;
|
||||
params.cfp_period = params.cfp_period;
|
||||
params.cfp_max_duration = Utils::host_to_le(params.cfp_max_duration);
|
||||
params.cfp_dur_remaining = Utils::host_to_le(params.cfp_dur_remaining);
|
||||
params.cfp_max_duration = Endian::host_to_le(params.cfp_max_duration);
|
||||
params.cfp_dur_remaining = Endian::host_to_le(params.cfp_dur_remaining);
|
||||
add_tagged_option(CF_SET, sizeof(params), (uint8_t*)¶ms);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) {
|
||||
atim_window = Utils::host_to_le(atim_window);
|
||||
atim_window = Endian::host_to_le(atim_window);
|
||||
add_tagged_option(IBSS_SET, 2, (uint8_t*)&atim_window);
|
||||
}
|
||||
|
||||
@@ -519,8 +518,8 @@ void Dot11ManagementFrame::quiet(const quiet_type &data) {
|
||||
|
||||
buffer[0] = data.quiet_count;
|
||||
buffer[1] = data.quiet_period;
|
||||
ptr_buffer[0] = Utils::host_to_le(data.quiet_duration);
|
||||
ptr_buffer[1] = Utils::host_to_le(data.quiet_offset);
|
||||
ptr_buffer[0] = Endian::host_to_le(data.quiet_duration);
|
||||
ptr_buffer[1] = Endian::host_to_le(data.quiet_offset);
|
||||
add_tagged_option(QUIET, sizeof(buffer), buffer);
|
||||
|
||||
}
|
||||
@@ -540,9 +539,9 @@ void Dot11ManagementFrame::erp_information(uint8_t value) {
|
||||
void Dot11ManagementFrame::bss_load(const bss_load_type &data) {
|
||||
uint8_t buffer[5];
|
||||
|
||||
*(uint16_t*)buffer = Utils::host_to_le(data.station_count);
|
||||
*(uint16_t*)buffer = Endian::host_to_le(data.station_count);
|
||||
buffer[2] = data.channel_utilization;
|
||||
*(uint16_t*)(buffer + 3) = Utils::host_to_le(data.available_capacity);
|
||||
*(uint16_t*)(buffer + 3) = Endian::host_to_le(data.available_capacity);
|
||||
add_tagged_option(BSS_LOAD, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
@@ -640,7 +639,7 @@ Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_parameter_set() con
|
||||
if(!option || option->data_size() != sizeof(fh_params_set))
|
||||
throw std::runtime_error("FH parameters set not set");
|
||||
fh_params_set output = *reinterpret_cast<const fh_params_set*>(option->data_ptr());
|
||||
output.dwell_time = Utils::le_to_host(output.dwell_time);
|
||||
output.dwell_time = Endian::le_to_host(output.dwell_time);
|
||||
output.hop_set = output.hop_set;
|
||||
output.hop_pattern = output.hop_pattern;
|
||||
output.hop_index = output.hop_index;
|
||||
@@ -658,7 +657,7 @@ uint16_t Dot11ManagementFrame::ibss_parameter_set() const {
|
||||
const Dot11::Dot11Option *option = search_option(IBSS_SET);
|
||||
if(!option || option->data_size() != sizeof(uint16_t))
|
||||
throw std::runtime_error("IBSS parameters set not set");
|
||||
return Utils::le_to_host(*reinterpret_cast<const uint16_t*>(option->data_ptr()));
|
||||
return Endian::le_to_host(*reinterpret_cast<const uint16_t*>(option->data_ptr()));
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs() const {
|
||||
@@ -751,8 +750,8 @@ Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
|
||||
output.quiet_count = *(ptr++);
|
||||
output.quiet_period = *(ptr++);
|
||||
const uint16_t *ptr_16 = (const uint16_t*)ptr;
|
||||
output.quiet_duration = Utils::le_to_host(*(ptr_16++));
|
||||
output.quiet_offset = Utils::le_to_host(*ptr_16);
|
||||
output.quiet_duration = Endian::le_to_host(*(ptr_16++));
|
||||
output.quiet_offset = Endian::le_to_host(*ptr_16);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -779,9 +778,9 @@ Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load() const {
|
||||
bss_load_type output;
|
||||
|
||||
const uint8_t *ptr = option->data_ptr();
|
||||
output.station_count = Utils::le_to_host(*(uint16_t*)ptr);
|
||||
output.station_count = Endian::le_to_host(*(uint16_t*)ptr);
|
||||
output.channel_utilization = ptr[2];
|
||||
output.available_capacity = Utils::le_to_host(*(uint16_t*)(ptr + 3));
|
||||
output.available_capacity = Endian::le_to_host(*(uint16_t*)(ptr + 3));
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -832,11 +831,11 @@ Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void Dot11Beacon::timestamp(uint64_t new_timestamp) {
|
||||
this->_body.timestamp = Utils::host_to_le(new_timestamp);
|
||||
this->_body.timestamp = Endian::host_to_le(new_timestamp);
|
||||
}
|
||||
|
||||
void Dot11Beacon::interval(uint16_t new_interval) {
|
||||
this->_body.interval = Utils::host_to_le(new_interval);
|
||||
this->_body.interval = Endian::host_to_le(new_interval);
|
||||
}
|
||||
|
||||
uint32_t Dot11Beacon::header_size() const {
|
||||
@@ -873,7 +872,7 @@ Dot11Disassoc::Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void Dot11Disassoc::reason_code(uint16_t new_reason_code) {
|
||||
this->_body.reason_code = Utils::host_to_le(new_reason_code);
|
||||
this->_body.reason_code = Endian::host_to_le(new_reason_code);
|
||||
}
|
||||
|
||||
uint32_t Dot11Disassoc::header_size() const {
|
||||
@@ -910,7 +909,7 @@ Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz) :
|
||||
}
|
||||
|
||||
void Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) {
|
||||
this->_body.listen_interval = Utils::host_to_le(new_listen_interval);
|
||||
this->_body.listen_interval = Endian::host_to_le(new_listen_interval);
|
||||
}
|
||||
|
||||
uint32_t Dot11AssocRequest::header_size() const {
|
||||
@@ -949,11 +948,11 @@ Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void Dot11AssocResponse::status_code(uint16_t new_status_code) {
|
||||
this->_body.status_code = Utils::host_to_le(new_status_code);
|
||||
this->_body.status_code = Endian::host_to_le(new_status_code);
|
||||
}
|
||||
|
||||
void Dot11AssocResponse::aid(uint16_t new_aid) {
|
||||
this->_body.aid = Utils::host_to_le(new_aid);
|
||||
this->_body.aid = Endian::host_to_le(new_aid);
|
||||
}
|
||||
|
||||
uint32_t Dot11AssocResponse::header_size() const {
|
||||
@@ -992,7 +991,7 @@ Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_s
|
||||
}
|
||||
|
||||
void Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) {
|
||||
this->_body.listen_interval = Utils::host_to_le(new_listen_interval);
|
||||
this->_body.listen_interval = Endian::host_to_le(new_listen_interval);
|
||||
}
|
||||
|
||||
void Dot11ReAssocRequest::current_ap(const address_type &new_current_ap) {
|
||||
@@ -1034,11 +1033,11 @@ Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total
|
||||
}
|
||||
|
||||
void Dot11ReAssocResponse::status_code(uint16_t new_status_code) {
|
||||
this->_body.status_code = Utils::host_to_le(new_status_code);
|
||||
this->_body.status_code = Endian::host_to_le(new_status_code);
|
||||
}
|
||||
|
||||
void Dot11ReAssocResponse::aid(uint16_t new_aid) {
|
||||
this->_body.aid = Utils::host_to_le(new_aid);
|
||||
this->_body.aid = Endian::host_to_le(new_aid);
|
||||
}
|
||||
|
||||
uint32_t Dot11ReAssocResponse::header_size() const {
|
||||
@@ -1078,15 +1077,15 @@ Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_s
|
||||
}
|
||||
|
||||
void Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) {
|
||||
this->_body.auth_algorithm = Utils::host_to_le(new_auth_algorithm);
|
||||
this->_body.auth_algorithm = Endian::host_to_le(new_auth_algorithm);
|
||||
}
|
||||
|
||||
void Dot11Authentication::auth_seq_number(uint16_t new_auth_seq_number) {
|
||||
this->_body.auth_seq_number = Utils::host_to_le(new_auth_seq_number);
|
||||
this->_body.auth_seq_number = Endian::host_to_le(new_auth_seq_number);
|
||||
}
|
||||
|
||||
void Dot11Authentication::status_code(uint16_t new_status_code) {
|
||||
this->_body.status_code = Utils::host_to_le(new_status_code);
|
||||
this->_body.status_code = Endian::host_to_le(new_status_code);
|
||||
}
|
||||
|
||||
uint32_t Dot11Authentication::header_size() const {
|
||||
@@ -1124,7 +1123,7 @@ Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32_t tot
|
||||
}
|
||||
|
||||
void Dot11Deauthentication::reason_code(uint16_t new_reason_code) {
|
||||
this->_body.reason_code = Utils::host_to_le(new_reason_code);
|
||||
this->_body.reason_code = Endian::host_to_le(new_reason_code);
|
||||
}
|
||||
|
||||
uint32_t Dot11Deauthentication::header_size() const {
|
||||
@@ -1181,11 +1180,11 @@ Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void Dot11ProbeResponse::timestamp(uint64_t new_timestamp) {
|
||||
this->_body.timestamp = Utils::host_to_le(new_timestamp);
|
||||
this->_body.timestamp = Endian::host_to_le(new_timestamp);
|
||||
}
|
||||
|
||||
void Dot11ProbeResponse::interval(uint16_t new_interval) {
|
||||
this->_body.interval = Utils::host_to_le(new_interval);
|
||||
this->_body.interval = Endian::host_to_le(new_interval);
|
||||
}
|
||||
|
||||
uint32_t Dot11ProbeResponse::header_size() const {
|
||||
@@ -1253,7 +1252,7 @@ void Dot11Data::frag_num(uint8_t new_frag_num) {
|
||||
}
|
||||
|
||||
void Dot11Data::seq_num(uint16_t new_seq_num) {
|
||||
_ext_header.seq_control.seq_number = Utils::host_to_le(new_seq_num);
|
||||
_ext_header.seq_control.seq_number = Endian::host_to_le(new_seq_num);
|
||||
}
|
||||
|
||||
void Dot11Data::addr4(const address_type &new_addr4) {
|
||||
@@ -1300,7 +1299,7 @@ Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void Dot11QoSData::qos_control(uint16_t new_qos_control) {
|
||||
this->_qos_control = Utils::host_to_le(new_qos_control);
|
||||
this->_qos_control = Endian::host_to_le(new_qos_control);
|
||||
}
|
||||
|
||||
uint32_t Dot11QoSData::header_size() const {
|
||||
@@ -1467,12 +1466,12 @@ uint32_t Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t total_
|
||||
|
||||
void Dot11BlockAckRequest::bar_control(uint16_t bar) {
|
||||
//std::memcpy(&_bar_control, &bar, sizeof(bar));
|
||||
_bar_control.tid = Utils::host_to_le(bar);
|
||||
_bar_control.tid = Endian::host_to_le(bar);
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::start_sequence(uint16_t seq) {
|
||||
//std::memcpy(&_start_sequence, &seq, sizeof(seq));
|
||||
_start_sequence.seq = Utils::host_to_le(seq);
|
||||
_start_sequence.seq = Endian::host_to_le(seq);
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::fragment_number(uint8_t frag) {
|
||||
|
||||
@@ -114,11 +114,11 @@ RC4EAPOL::RC4EAPOL(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void RC4EAPOL::key_length(uint16_t new_key_length) {
|
||||
_header.key_length = Utils::host_to_be(new_key_length);
|
||||
_header.key_length = Endian::host_to_be(new_key_length);
|
||||
}
|
||||
|
||||
void RC4EAPOL::replay_counter(uint16_t new_replay_counter) {
|
||||
_header.replay_counter = Utils::host_to_be(new_replay_counter);
|
||||
_header.replay_counter = Endian::host_to_be(new_replay_counter);
|
||||
}
|
||||
|
||||
void RC4EAPOL::key_iv(const uint8_t *new_key_iv) {
|
||||
@@ -149,7 +149,7 @@ void RC4EAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
|
||||
uint32_t sz = sizeof(_header) + _key.size();
|
||||
assert(total_sz >= sz);
|
||||
if(_key.size())
|
||||
_header.key_length = Utils::host_to_be(_key.size());
|
||||
_header.key_length = Endian::host_to_be(_key.size());
|
||||
std::memcpy(buffer, &_header, sizeof(_header));
|
||||
buffer += sizeof(_header);
|
||||
std::copy(_key.begin(), _key.end(), buffer);
|
||||
@@ -183,11 +183,11 @@ void RSNEAPOL::RSNEAPOL::nonce(const uint8_t *new_nonce) {
|
||||
}
|
||||
|
||||
void RSNEAPOL::rsc(uint64_t new_rsc) {
|
||||
_header.rsc = Utils::host_to_be(new_rsc);
|
||||
_header.rsc = Endian::host_to_be(new_rsc);
|
||||
}
|
||||
|
||||
void RSNEAPOL::id(uint64_t new_id) {
|
||||
_header.id = Utils::host_to_be(new_id);
|
||||
_header.id = Endian::host_to_be(new_id);
|
||||
}
|
||||
|
||||
void RSNEAPOL::mic(const uint8_t *new_mic) {
|
||||
@@ -195,7 +195,7 @@ void RSNEAPOL::mic(const uint8_t *new_mic) {
|
||||
}
|
||||
|
||||
void RSNEAPOL::wpa_length(uint16_t new_wpa_length) {
|
||||
_header.wpa_length = Utils::host_to_be(new_wpa_length);
|
||||
_header.wpa_length = Endian::host_to_be(new_wpa_length);
|
||||
}
|
||||
|
||||
void RSNEAPOL::key(const key_type &new_key) {
|
||||
@@ -220,7 +220,7 @@ void RSNEAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
|
||||
assert(total_sz >= sz);
|
||||
if(_key.size()) {
|
||||
if(!_header.key_t) {
|
||||
_header.key_length = Utils::host_to_be<uint16_t>(32);
|
||||
_header.key_length = Endian::host_to_be<uint16_t>(32);
|
||||
wpa_length(_key.size());
|
||||
}
|
||||
else if(_key.size()) {
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "rawpdu.h"
|
||||
#include "ip.h"
|
||||
#include "arp.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace Tins {
|
||||
const EthernetII::address_type EthernetII::BROADCAST("ff:ff:ff:ff:ff:ff");
|
||||
@@ -88,7 +87,7 @@ void EthernetII::iface(const NetworkInterface& new_iface) {
|
||||
}
|
||||
|
||||
void EthernetII::payload_type(uint16_t new_payload_type) {
|
||||
this->_eth.payload_type = Utils::host_to_be(new_payload_type);
|
||||
this->_eth.payload_type = Endian::host_to_be(new_payload_type);
|
||||
}
|
||||
|
||||
uint32_t EthernetII::header_size() const {
|
||||
@@ -102,8 +101,8 @@ bool EthernetII::send(PacketSender* sender) {
|
||||
|
||||
memset(&addr, 0, sizeof(struct sockaddr_ll));
|
||||
|
||||
addr.sll_family = Utils::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Utils::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_halen = ADDR_SIZE;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
|
||||
@@ -139,7 +138,7 @@ void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
|
||||
default:
|
||||
type = 0;
|
||||
}
|
||||
_eth.payload_type = Utils::host_to_be(type);
|
||||
_eth.payload_type = Endian::host_to_be(type);
|
||||
}
|
||||
memcpy(buffer, &_eth, sizeof(ethhdr));
|
||||
}
|
||||
@@ -148,8 +147,8 @@ PDU *EthernetII::recv_response(PacketSender *sender) {
|
||||
struct sockaddr_ll addr;
|
||||
memset(&addr, 0, sizeof(struct sockaddr_ll));
|
||||
|
||||
addr.sll_family = Utils::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Utils::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_halen = ADDR_SIZE;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
|
||||
|
||||
12
src/icmp.cpp
12
src/icmp.cpp
@@ -66,23 +66,23 @@ void Tins::ICMP::type(Flags new_type) {
|
||||
}
|
||||
|
||||
void Tins::ICMP::check(uint16_t new_check) {
|
||||
_icmp.check = Utils::host_to_be(new_check);
|
||||
_icmp.check = Endian::host_to_be(new_check);
|
||||
}
|
||||
|
||||
void Tins::ICMP::id(uint16_t new_id) {
|
||||
_icmp.un.echo.id = Utils::host_to_be(new_id);
|
||||
_icmp.un.echo.id = Endian::host_to_be(new_id);
|
||||
}
|
||||
|
||||
void Tins::ICMP::sequence(uint16_t new_seq) {
|
||||
_icmp.un.echo.sequence = Utils::host_to_be(new_seq);
|
||||
_icmp.un.echo.sequence = Endian::host_to_be(new_seq);
|
||||
}
|
||||
|
||||
void Tins::ICMP::gateway(uint32_t new_gw) {
|
||||
_icmp.un.gateway = Utils::host_to_be(new_gw);
|
||||
_icmp.un.gateway = Endian::host_to_be(new_gw);
|
||||
}
|
||||
|
||||
void Tins::ICMP::mtu(uint16_t new_mtu) {
|
||||
_icmp.un.frag.mtu = Utils::host_to_be(new_mtu);
|
||||
_icmp.un.frag.mtu = Endian::host_to_be(new_mtu);
|
||||
}
|
||||
|
||||
void Tins::ICMP::pointer(uint8_t new_pointer) {
|
||||
@@ -171,7 +171,7 @@ void Tins::ICMP::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
|
||||
Utils::do_checksum((uint8_t*)&_icmp, ((uint8_t*)&_icmp) + sizeof(icmphdr));
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum & 0xffff) + (checksum >> 16);
|
||||
_icmp.check = Utils::host_to_be<uint16_t>(~checksum);
|
||||
_icmp.check = Endian::host_to_be<uint16_t>(~checksum);
|
||||
}
|
||||
memcpy(buffer, &_icmp, sizeof(icmphdr));
|
||||
_icmp.check = 0;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#endif
|
||||
#include "ieee802_3.h"
|
||||
#include "llc.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace Tins {
|
||||
const IEEE802_3::address_type IEEE802_3::BROADCAST("ff:ff:ff:ff:ff:ff");
|
||||
@@ -73,7 +72,7 @@ void IEEE802_3::iface(const NetworkInterface &new_iface) {
|
||||
}
|
||||
|
||||
void IEEE802_3::length(uint16_t new_length) {
|
||||
this->_eth.length = Utils::host_to_be(new_length);
|
||||
this->_eth.length = Endian::host_to_be(new_length);
|
||||
}
|
||||
|
||||
uint32_t IEEE802_3::header_size() const {
|
||||
@@ -85,8 +84,8 @@ bool IEEE802_3::send(PacketSender* sender) {
|
||||
|
||||
memset(&addr, 0, sizeof(struct sockaddr_ll));
|
||||
|
||||
addr.sll_family = Utils::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Utils::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_halen = address_type::address_size;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, sizeof(_eth.dst_mac));
|
||||
@@ -110,7 +109,7 @@ void IEEE802_3::write_serialization(uint8_t *buffer, uint32_t total_sz, const PD
|
||||
assert(total_sz >= my_sz);
|
||||
|
||||
if (set_length)
|
||||
_eth.length = Utils::host_to_be(size() - sizeof(_eth));
|
||||
_eth.length = Endian::host_to_be(size() - sizeof(_eth));
|
||||
|
||||
memcpy(buffer, &_eth, sizeof(ethhdr));
|
||||
|
||||
@@ -122,8 +121,8 @@ PDU *IEEE802_3::recv_response(PacketSender *sender) {
|
||||
struct sockaddr_ll addr;
|
||||
memset(&addr, 0, sizeof(struct sockaddr_ll));
|
||||
|
||||
addr.sll_family = Utils::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Utils::host_to_be<uint16_t>(ETH_P_802_3);
|
||||
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_802_3);
|
||||
addr.sll_halen = address_type::address_size;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, sizeof(_eth.dst_mac));
|
||||
|
||||
12
src/ip.cpp
12
src/ip.cpp
@@ -146,15 +146,15 @@ void IP::tos(uint8_t new_tos) {
|
||||
}
|
||||
|
||||
void IP::tot_len(uint16_t new_tot_len) {
|
||||
_ip.tot_len = Utils::host_to_be(new_tot_len);
|
||||
_ip.tot_len = Endian::host_to_be(new_tot_len);
|
||||
}
|
||||
|
||||
void IP::id(uint16_t new_id) {
|
||||
_ip.id = Utils::host_to_be(new_id);
|
||||
_ip.id = Endian::host_to_be(new_id);
|
||||
}
|
||||
|
||||
void IP::frag_off(uint16_t new_frag_off) {
|
||||
_ip.frag_off = Utils::host_to_be(new_frag_off);
|
||||
_ip.frag_off = Endian::host_to_be(new_frag_off);
|
||||
}
|
||||
|
||||
void IP::ttl(uint8_t new_ttl) {
|
||||
@@ -166,7 +166,7 @@ void IP::protocol(uint8_t new_protocol) {
|
||||
}
|
||||
|
||||
void IP::check(uint16_t new_check) {
|
||||
_ip.check = Utils::host_to_be(new_check);
|
||||
_ip.check = Endian::host_to_be(new_check);
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ void IP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU* pare
|
||||
uint32_t checksum = Utils::do_checksum(buffer, buffer + sizeof(_ip) + _padded_options_size);
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum & 0xffff) + (checksum >> 16);
|
||||
((iphdr*)buffer)->check = Utils::host_to_be<uint16_t>(~checksum);
|
||||
((iphdr*)buffer)->check = Endian::host_to_be<uint16_t>(~checksum);
|
||||
this->check(0);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ PDU *IP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
|
||||
if((child = PDU::clone_inner_pdu(ptr + sizeof(_ip), total_sz - sizeof(_ip))) == 0)
|
||||
return 0;
|
||||
}
|
||||
cloned = new IP(ptr, std::min(total_sz, (uint32_t)(Utils::be_to_host(ip_ptr->tot_len) * sizeof(uint32_t))));
|
||||
cloned = new IP(ptr, std::min(total_sz, (uint32_t)(Endian::be_to_host(ip_ptr->tot_len) * sizeof(uint32_t))));
|
||||
cloned->inner_pdu(child);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
@@ -20,14 +20,15 @@
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include "ipaddress.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Tins{
|
||||
IPv4Address::IPv4Address(uint32_t ip)
|
||||
: ip_addr(Utils::be_to_host(ip)) {
|
||||
: ip_addr(Endian::be_to_host(ip)) {
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ IPv4Address::IPv4Address(const std::string &ip)
|
||||
}
|
||||
|
||||
IPv4Address::operator uint32_t() const {
|
||||
return Utils::host_to_be(ip_addr);
|
||||
return Endian::host_to_be(ip_addr);
|
||||
}
|
||||
|
||||
std::string IPv4Address::to_string() const {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "pdu.h"
|
||||
#include "llc.h"
|
||||
#include "utils.h"
|
||||
#include "rawpdu.h"
|
||||
|
||||
using std::list;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#endif
|
||||
#include "network_interface.h"
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
|
||||
/** \cond */
|
||||
struct InterfaceInfoCollector {
|
||||
@@ -41,7 +42,7 @@ struct InterfaceInfoCollector {
|
||||
: info(res), iface_id(id), iface_name(if_name), found(false) { }
|
||||
|
||||
bool operator() (struct ifaddrs *addr) {
|
||||
using Tins::Utils::host_to_be;
|
||||
using Tins::Endian::host_to_be;
|
||||
using Tins::IPv4Address;
|
||||
const struct sockaddr_ll* addr_ptr = ((struct sockaddr_ll*)addr->ifa_addr);
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ Tins::RadioTap::RadioTap(const NetworkInterface &iface, PDU *child)
|
||||
init();
|
||||
}
|
||||
|
||||
Tins::RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz) : PDU(0xff) {
|
||||
Tins::RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
: PDU(0xff)
|
||||
{
|
||||
static const std::string msg("Not enough size for an RadioTap header in the buffer.");
|
||||
if(total_sz < sizeof(_radio))
|
||||
throw std::runtime_error(msg);
|
||||
@@ -130,7 +132,7 @@ void Tins::RadioTap::length(uint8_t new_length) {
|
||||
}
|
||||
|
||||
void Tins::RadioTap::tsft(uint64_t new_tsft) {
|
||||
_tsft = new_tsft;
|
||||
_tsft = Endian::host_to_le(new_tsft);
|
||||
if(!_radio.tsft)
|
||||
_options_size += sizeof(_tsft);
|
||||
_radio.tsft = 1;
|
||||
@@ -151,8 +153,8 @@ void Tins::RadioTap::rate(uint8_t new_rate) {
|
||||
}
|
||||
|
||||
void Tins::RadioTap::channel(uint16_t new_freq, uint16_t new_type) {
|
||||
_channel_freq = new_freq;
|
||||
_channel_type = new_type;
|
||||
_channel_freq = Endian::host_to_le(new_freq);
|
||||
_channel_type = Endian::host_to_le(new_type);
|
||||
if(!_radio.channel)
|
||||
_options_size += sizeof(_channel_freq) + sizeof(_channel_type);
|
||||
_radio.channel = 1;
|
||||
@@ -172,7 +174,7 @@ void Tins::RadioTap::antenna(uint8_t new_antenna) {
|
||||
}
|
||||
|
||||
void Tins::RadioTap::rx_flag(uint16_t new_rx_flag) {
|
||||
_rx_flags = new_rx_flag;
|
||||
_rx_flags = Endian::host_to_le(new_rx_flag);
|
||||
if(!_radio.rx_flags)
|
||||
_options_size += sizeof(_rx_flags);
|
||||
_radio.rx_flags = 1;
|
||||
@@ -197,8 +199,8 @@ bool Tins::RadioTap::send(PacketSender* sender) {
|
||||
|
||||
memset(&addr, 0, sizeof(struct sockaddr_ll));
|
||||
|
||||
addr.sll_family = Utils::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Utils::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_halen = 6;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
|
||||
@@ -206,7 +208,6 @@ bool Tins::RadioTap::send(PacketSender* sender) {
|
||||
if(wlan) {
|
||||
Dot11::address_type dot11_addr(wlan->addr1());
|
||||
std::copy(dot11_addr.begin(), dot11_addr.end(), addr.sll_addr);
|
||||
//memcpy(&(addr.sll_addr), wlan->addr1(), 6);
|
||||
}
|
||||
|
||||
return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include <stdexcept>
|
||||
#include "rsn_information.h"
|
||||
|
||||
namespace Tins {
|
||||
@@ -29,7 +29,7 @@ RSNInformation::RSNInformation() : _version(1), _capabilities(0) {
|
||||
|
||||
RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
|
||||
const char *err_msg = "Malformed RSN information structure";
|
||||
version(Utils::le_to_host(*(uint16_t*)buffer));
|
||||
version(Endian::le_to_host(*(uint16_t*)buffer));
|
||||
buffer += sizeof(uint16_t);
|
||||
group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer);
|
||||
buffer += sizeof(uint32_t);
|
||||
@@ -60,7 +60,7 @@ RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
|
||||
}
|
||||
if(total_sz < sizeof(uint16_t))
|
||||
throw std::runtime_error(err_msg);
|
||||
capabilities(Utils::le_to_host(*(uint16_t*)buffer));
|
||||
capabilities(Endian::le_to_host(*(uint16_t*)buffer));
|
||||
}
|
||||
|
||||
void RSNInformation::add_pairwise_cypher(CypherSuites cypher) {
|
||||
@@ -76,11 +76,11 @@ void RSNInformation::group_suite(CypherSuites group) {
|
||||
}
|
||||
|
||||
void RSNInformation::version(uint16_t ver) {
|
||||
_version = Utils::host_to_le(ver);
|
||||
_version = Endian::host_to_le(ver);
|
||||
}
|
||||
|
||||
void RSNInformation::capabilities(uint16_t cap) {
|
||||
_capabilities = Utils::host_to_le(cap);
|
||||
_capabilities = Endian::host_to_le(cap);
|
||||
}
|
||||
|
||||
RSNInformation::serialization_type RSNInformation::serialize() const {
|
||||
|
||||
44
src/snap.cpp
44
src/snap.cpp
@@ -35,7 +35,7 @@
|
||||
Tins::SNAP::SNAP(PDU *child) : PDU(0xff, child) {
|
||||
std::memset(&_snap, 0, sizeof(_snap));
|
||||
_snap.dsap = _snap.ssap = 0xaa;
|
||||
_snap.id = 3;
|
||||
_snap.control = 3;
|
||||
}
|
||||
|
||||
Tins::SNAP::SNAP(const uint8_t *buffer, uint32_t total_sz) : PDU(0xff) {
|
||||
@@ -44,6 +44,7 @@ Tins::SNAP::SNAP(const uint8_t *buffer, uint32_t total_sz) : PDU(0xff) {
|
||||
std::memcpy(&_snap, buffer, sizeof(_snap));
|
||||
buffer += sizeof(_snap);
|
||||
total_sz -= sizeof(_snap);
|
||||
if(total_sz) {
|
||||
switch(eth_type()) {
|
||||
case Tins::Constants::Ethernet::IP:
|
||||
inner_pdu(new Tins::IP(buffer, total_sz));
|
||||
@@ -56,31 +57,24 @@ Tins::SNAP::SNAP(const uint8_t *buffer, uint32_t total_sz) : PDU(0xff) {
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
Tins::SNAP::SNAP(const SNAP &other) : PDU(other) {
|
||||
copy_fields(&other);
|
||||
}
|
||||
|
||||
Tins::SNAP &Tins::SNAP::operator=(const SNAP &other) {
|
||||
copy_fields(&other);
|
||||
copy_inner_pdu(other);
|
||||
return *this;
|
||||
void Tins::SNAP::control(uint8_t new_control) {
|
||||
_snap.control = new_control;
|
||||
}
|
||||
|
||||
void Tins::SNAP::id(uint8_t new_id) {
|
||||
_snap.id = new_id;
|
||||
}
|
||||
|
||||
void Tins::SNAP::poll(uint8_t new_poll) {
|
||||
_snap.poll = new_poll;
|
||||
}
|
||||
|
||||
void Tins::SNAP::org_code(uint32_t new_org) {
|
||||
_snap.org_code = new_org;
|
||||
void Tins::SNAP::org_code(small_uint<24> new_org) {
|
||||
// little endian fix, it was the only way to make it work.
|
||||
// check on big endian?
|
||||
#ifdef TINS_IS_LITTLE_ENDIAN
|
||||
_snap.org_code = Endian::host_to_be<uint32_t>(new_org) >> 8;
|
||||
#else
|
||||
_snap.org_code = Endian::host_to_be<uint32_t>(new_org);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Tins::SNAP::eth_type(uint16_t new_eth) {
|
||||
_snap.eth_type = Utils::host_to_be(new_eth);
|
||||
_snap.eth_type = Endian::host_to_be(new_eth);
|
||||
}
|
||||
|
||||
uint32_t Tins::SNAP::header_size() const {
|
||||
@@ -104,17 +98,7 @@ void Tins::SNAP::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
|
||||
default:
|
||||
type = 0;
|
||||
}
|
||||
_snap.eth_type = Utils::host_to_be(type);
|
||||
_snap.eth_type = Endian::host_to_be(type);
|
||||
}
|
||||
std::memcpy(buffer, &_snap, sizeof(_snap));
|
||||
}
|
||||
|
||||
void Tins::SNAP::copy_fields(const SNAP *other) {
|
||||
std::memcpy(&_snap, &other->_snap, sizeof(_snap));
|
||||
}
|
||||
|
||||
Tins::PDU *Tins::SNAP::clone_pdu() const {
|
||||
SNAP *new_pdu = new SNAP();
|
||||
new_pdu->copy_fields(this);
|
||||
return new_pdu;
|
||||
}
|
||||
|
||||
28
src/tcp.cpp
28
src/tcp.cpp
@@ -89,31 +89,31 @@ TCP::TCP(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void TCP::dport(uint16_t new_dport) {
|
||||
_tcp.dport = Utils::host_to_be(new_dport);
|
||||
_tcp.dport = Endian::host_to_be(new_dport);
|
||||
}
|
||||
|
||||
void TCP::sport(uint16_t new_sport) {
|
||||
_tcp.sport = Utils::host_to_be(new_sport);
|
||||
_tcp.sport = Endian::host_to_be(new_sport);
|
||||
}
|
||||
|
||||
void TCP::seq(uint32_t new_seq) {
|
||||
_tcp.seq = Utils::host_to_be(new_seq);
|
||||
_tcp.seq = Endian::host_to_be(new_seq);
|
||||
}
|
||||
|
||||
void TCP::ack_seq(uint32_t new_ack_seq) {
|
||||
_tcp.ack_seq = Utils::host_to_be(new_ack_seq);
|
||||
_tcp.ack_seq = Endian::host_to_be(new_ack_seq);
|
||||
}
|
||||
|
||||
void TCP::window(uint16_t new_window) {
|
||||
_tcp.window = Utils::host_to_be(new_window);
|
||||
_tcp.window = Endian::host_to_be(new_window);
|
||||
}
|
||||
|
||||
void TCP::check(uint16_t new_check) {
|
||||
_tcp.check = Utils::host_to_be(new_check);
|
||||
_tcp.check = Endian::host_to_be(new_check);
|
||||
}
|
||||
|
||||
void TCP::urg_ptr(uint16_t new_urg_ptr) {
|
||||
_tcp.urg_ptr = Utils::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) {
|
||||
@@ -125,14 +125,14 @@ void TCP::data_offset(small_uint<4> new_doff) {
|
||||
}
|
||||
|
||||
void TCP::add_mss_option(uint16_t value) {
|
||||
value = Utils::host_to_be(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 = Utils::host_to_be(*value);
|
||||
*value = Endian::host_to_be(*value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ void TCP::add_sack_option(const std::list<uint32_t> &edges) {
|
||||
value = new uint32_t[edges.size()];
|
||||
uint32_t *ptr = value;
|
||||
for(std::list<uint32_t>::const_iterator it = edges.begin(); it != edges.end(); ++it)
|
||||
*(ptr++) = Utils::host_to_be(*it);
|
||||
*(ptr++) = Endian::host_to_be(*it);
|
||||
}
|
||||
add_option(SACK, (uint8_t)(sizeof(uint32_t) * edges.size()), (const uint8_t*)value);
|
||||
delete[] value;
|
||||
@@ -171,13 +171,13 @@ bool TCP::search_sack_option(std::list<uint32_t> *edges) {
|
||||
const uint32_t *ptr = (const uint32_t*)&option->value[0];
|
||||
const uint32_t *end = ptr + (option->value.size() / sizeof(uint32_t));
|
||||
while(ptr < end)
|
||||
edges->push_back(Utils::host_to_be(*(ptr++)));
|
||||
edges->push_back(Endian::host_to_be(*(ptr++)));
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
buffer = Endian::host_to_be(buffer);
|
||||
add_option(TSOPT, 8, (uint8_t*)&buffer);
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ bool TCP::search_timestamp_option(uint32_t *value, uint32_t *reply) {
|
||||
if(!option || option->value.size() != (sizeof(uint32_t) << 1))
|
||||
return false;
|
||||
uint64_t buffer = *(const uint64_t*)&option->value[0];
|
||||
buffer = Utils::be_to_host(buffer);
|
||||
buffer = Endian::be_to_host(buffer);
|
||||
*value = (buffer >> 32) & 0xffffffff;
|
||||
*reply = buffer & 0xffffffff;
|
||||
return true;
|
||||
@@ -308,7 +308,7 @@ void TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum & 0xffff) + (checksum >> 16);
|
||||
|
||||
((tcphdr*)tcp_start)->check = Utils::host_to_be<uint16_t>(~checksum);
|
||||
((tcphdr*)tcp_start)->check = Endian::host_to_be<uint16_t>(~checksum);
|
||||
}
|
||||
_tcp.check = 0;
|
||||
}
|
||||
|
||||
13
src/udp.cpp
13
src/udp.cpp
@@ -24,6 +24,7 @@
|
||||
#include <cstring>
|
||||
#include "udp.h"
|
||||
#include "constants.h"
|
||||
#include "utils.h"
|
||||
#include "ip.h"
|
||||
#include "rawpdu.h"
|
||||
|
||||
@@ -47,20 +48,16 @@ Tins::UDP::UDP(const uint8_t *buffer, uint32_t total_sz)
|
||||
inner_pdu(new RawPDU(buffer + sizeof(udphdr), total_sz));
|
||||
}
|
||||
|
||||
void Tins::UDP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
|
||||
inner_pdu(new RawPDU(new_payload, new_payload_size));
|
||||
}
|
||||
|
||||
void Tins::UDP::dport(uint16_t new_dport) {
|
||||
_udp.dport = Utils::host_to_be(new_dport);
|
||||
_udp.dport = Endian::host_to_be(new_dport);
|
||||
}
|
||||
|
||||
void Tins::UDP::sport(uint16_t new_sport) {
|
||||
_udp.sport = Utils::host_to_be(new_sport);
|
||||
_udp.sport = Endian::host_to_be(new_sport);
|
||||
}
|
||||
|
||||
void Tins::UDP::length(uint16_t new_len) {
|
||||
_udp.len = Utils::host_to_be(new_len);
|
||||
_udp.len = Endian::host_to_be(new_len);
|
||||
}
|
||||
|
||||
uint32_t Tins::UDP::header_size() const {
|
||||
@@ -78,7 +75,7 @@ void Tins::UDP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PD
|
||||
Utils::do_checksum(buffer, buffer + total_sz);
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum & 0xffff)+(checksum >> 16);
|
||||
((udphdr*)buffer)->check = Utils::host_to_be<uint16_t>(~checksum);
|
||||
((udphdr*)buffer)->check = Endian::host_to_be<uint16_t>(~checksum);
|
||||
}
|
||||
_udp.check = 0;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "ip.h"
|
||||
#include "icmp.h"
|
||||
#include "arp.h"
|
||||
#include "endianness.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
@@ -163,14 +164,14 @@ uint32_t Utils::do_checksum(const uint8_t *start, const uint8_t *end) {
|
||||
padding = *(end - 1) << 8;
|
||||
}
|
||||
while(ptr < last)
|
||||
checksum += Utils::host_to_be(*(ptr++));
|
||||
checksum += Endian::host_to_be(*(ptr++));
|
||||
return checksum + padding;
|
||||
}
|
||||
|
||||
uint32_t Utils::pseudoheader_checksum(IPv4Address source_ip, IPv4Address dest_ip, uint32_t len, uint32_t flag) {
|
||||
uint32_t checksum(0);
|
||||
uint32_t source_ip_int = Utils::host_to_be<uint32_t>(source_ip),
|
||||
dest_ip_int = Utils::host_to_be<uint32_t>(dest_ip);
|
||||
uint32_t source_ip_int = Endian::host_to_be<uint32_t>(source_ip),
|
||||
dest_ip_int = Endian::host_to_be<uint32_t>(dest_ip);
|
||||
uint16_t *ptr = (uint16_t*)&source_ip_int;
|
||||
|
||||
checksum += (uint32_t)(*ptr) + (uint32_t)(*(ptr+1));
|
||||
|
||||
@@ -88,7 +88,6 @@ TEST_F(Dot11AssocResponseTest, ClonePDU) {
|
||||
TEST_F(Dot11AssocResponseTest, FromBytes) {
|
||||
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
|
||||
ASSERT_TRUE(dot11.get());
|
||||
std::cout << (int)dot11->pdu_type() << std::endl;
|
||||
const Dot11AssocResponse *inner = dot11->find_pdu<Dot11AssocResponse>();
|
||||
ASSERT_TRUE(inner);
|
||||
test_equals_expected(*inner);
|
||||
|
||||
@@ -15,7 +15,9 @@ public:
|
||||
void test_equals(const SNAP &snap1, const SNAP &snap2);
|
||||
};
|
||||
|
||||
const uint8_t SNAPTest::expected_packet[] = {'\xaa', '\xaa', '\x03', '\x00', '\x00', '\x00', 'z', '\xb1'};
|
||||
const uint8_t SNAPTest::expected_packet[] = {
|
||||
'\xaa', '\xaa', '\x03', '\x00', '\x00', '\x00', '\x08', '\x00'
|
||||
};
|
||||
|
||||
TEST_F(SNAPTest, DefaultConstructor) {
|
||||
SNAP snap;
|
||||
@@ -23,17 +25,15 @@ TEST_F(SNAPTest, DefaultConstructor) {
|
||||
EXPECT_EQ(snap.dsap(), 0xaa);
|
||||
EXPECT_EQ(snap.ssap(), 0xaa);
|
||||
EXPECT_EQ(snap.eth_type(), 0);
|
||||
EXPECT_EQ(snap.poll(), 0);
|
||||
EXPECT_EQ(snap.org_code(), 0);
|
||||
EXPECT_EQ(snap.id(), 3);
|
||||
EXPECT_EQ(snap.control(), 3);
|
||||
}
|
||||
|
||||
TEST_F(SNAPTest, CopyConstructor) {
|
||||
SNAP snap1;
|
||||
snap1.eth_type(0xfab1);
|
||||
snap1.org_code(0xfab1c3);
|
||||
snap1.poll(0x1);
|
||||
snap1.id(0x1);
|
||||
snap1.control(0x1);
|
||||
SNAP snap2(snap1);
|
||||
test_equals(snap1, snap2);
|
||||
}
|
||||
@@ -42,27 +42,15 @@ TEST_F(SNAPTest, CopyAssignmentOperator) {
|
||||
SNAP snap1;
|
||||
snap1.eth_type(0xfab1);
|
||||
snap1.org_code(0xfab1c3);
|
||||
snap1.poll(0x1);
|
||||
snap1.id(0x1);
|
||||
snap1.control(0x1);
|
||||
SNAP snap2 = snap1;
|
||||
test_equals(snap1, snap2);
|
||||
}
|
||||
|
||||
TEST_F(SNAPTest, Id) {
|
||||
SNAP snap;
|
||||
snap.id(0x1);
|
||||
EXPECT_EQ(snap.id(), 0x1);
|
||||
}
|
||||
|
||||
TEST_F(SNAPTest, Poll) {
|
||||
SNAP snap;
|
||||
snap.poll(0x1);
|
||||
EXPECT_EQ(snap.poll(), 0x1);
|
||||
}
|
||||
|
||||
TEST_F(SNAPTest, OrgCode) {
|
||||
SNAP snap;
|
||||
snap.org_code(0xfab1c3);
|
||||
|
||||
EXPECT_EQ(snap.org_code(), 0xfab1c3);
|
||||
}
|
||||
|
||||
@@ -76,8 +64,7 @@ TEST_F(SNAPTest, Serialize) {
|
||||
SNAP snap1;
|
||||
snap1.eth_type(0xfab1);
|
||||
snap1.org_code(0xfab1c3);
|
||||
snap1.poll(0x1);
|
||||
snap1.id(0x1);
|
||||
snap1.control(0x1);
|
||||
|
||||
PDU::serialization_type buffer = snap1.serialize();
|
||||
|
||||
@@ -90,8 +77,7 @@ TEST_F(SNAPTest, ClonePDU) {
|
||||
SNAP snap1;
|
||||
snap1.eth_type(0xfab1);
|
||||
snap1.org_code(0xfab1c3);
|
||||
snap1.poll(0x1);
|
||||
snap1.id(0x1);
|
||||
snap1.control(0x1);
|
||||
SNAP *snap2 = static_cast<SNAP*>(snap1.clone_pdu());
|
||||
ASSERT_TRUE(snap2);
|
||||
test_equals(snap1, *snap2);
|
||||
@@ -103,10 +89,11 @@ TEST_F(SNAPTest, ConstructorFromBuffer) {
|
||||
SNAP snap1(expected_packet, sizeof(expected_packet));
|
||||
PDU::serialization_type buffer = snap1.serialize();
|
||||
|
||||
EXPECT_EQ(snap1.id(), 3);
|
||||
EXPECT_EQ(snap1.control(), 3);
|
||||
EXPECT_EQ(snap1.dsap(), 0xaa);
|
||||
EXPECT_EQ(snap1.ssap(), 0xaa);
|
||||
EXPECT_EQ(snap1.eth_type(), 0x7ab1);
|
||||
EXPECT_EQ(snap1.eth_type(), 0x0800);
|
||||
EXPECT_EQ(snap1.org_code(), 0);
|
||||
|
||||
SNAP snap2(&buffer[0], buffer.size());
|
||||
test_equals(snap1, snap2);
|
||||
@@ -115,6 +102,6 @@ TEST_F(SNAPTest, ConstructorFromBuffer) {
|
||||
void SNAPTest::test_equals(const SNAP &snap1, const SNAP &snap2) {
|
||||
EXPECT_EQ(snap1.dsap(), snap2.dsap());
|
||||
EXPECT_EQ(snap1.ssap(), snap2.ssap());
|
||||
EXPECT_EQ(snap1.id(), snap2.id());
|
||||
EXPECT_EQ(snap1.control(), snap2.control());
|
||||
EXPECT_EQ(snap1.eth_type(), snap2.eth_type());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <stdexcept>
|
||||
#include <gtest/gtest.h>
|
||||
#include "utils.h"
|
||||
#include "endianness.h"
|
||||
#include "ipaddress.h"
|
||||
|
||||
using namespace Tins;
|
||||
@@ -65,33 +66,6 @@ TEST_F(UtilsTest, ResolveIp) {
|
||||
|
||||
}
|
||||
|
||||
TEST_F(UtilsTest, NetToHostS) {
|
||||
uint16_t a = 0x01FE;
|
||||
uint16_t b = Utils::net_to_host_s(a);
|
||||
|
||||
EXPECT_EQ(b, 0xFE01);
|
||||
EXPECT_EQ(a, Utils::net_to_host_s(b));
|
||||
|
||||
}
|
||||
|
||||
TEST_F(UtilsTest, NetToHostL) {
|
||||
uint32_t a = 0x0102CDFE;
|
||||
uint32_t b = Utils::net_to_host_l(a);
|
||||
|
||||
EXPECT_EQ(b, 0xFECD0201);
|
||||
EXPECT_EQ(a, Utils::net_to_host_l(b));
|
||||
|
||||
}
|
||||
|
||||
TEST_F(UtilsTest, NetToHostLL) {
|
||||
uint64_t a = 0x0102030489ABCDFE;
|
||||
uint64_t b = Utils::net_to_host_ll(a);
|
||||
|
||||
EXPECT_EQ(b, 0xFECDAB8904030201);
|
||||
EXPECT_EQ(a, Utils::net_to_host_ll(b));
|
||||
|
||||
}
|
||||
|
||||
TEST_F(UtilsTest, Crc32) {
|
||||
|
||||
uint32_t crc = Utils::crc32(data, data_len);
|
||||
|
||||
Reference in New Issue
Block a user