mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Fix -Wextra compiler warnings. (#184)
* Fix -Wextra compiler warnings. Fix #183. Signed-off-by: Kyle Fazzari <github@status.e4ward.com> * Comment out unused parameters. This is done everywhere possible instead of using Internals::unused(). Note that this involved moving some implementations into the corresponding .cpp file. Signed-off-by: Kyle Fazzari <github@status.e4ward.com> * Fix warnings in tests as well. Signed-off-by: Kyle Fazzari <github@status.e4ward.com> * Leave IPv4Reassembler alone, it's growing. Signed-off-by: Kyle Fazzari <github@status.e4ward.com>
This commit is contained in:
committed by
Matias Fontanini
parent
94e5ac2109
commit
a71a3d29ff
@@ -18,7 +18,7 @@ IF(MSVC)
|
|||||||
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
|
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
|
||||||
ADD_DEFINITIONS("-DNOGDI=1")
|
ADD_DEFINITIONS("-DNOGDI=1")
|
||||||
ELSE()
|
ELSE()
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
IF(APPLE)
|
IF(APPLE)
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ struct smart_ptr {
|
|||||||
typedef std::auto_ptr<T> type;
|
typedef std::auto_ptr<T> type;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class T> void unused(const T&) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -508,8 +508,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Dot11* from_bytes(const uint8_t* buffer, uint32_t total_sz);
|
static Dot11* from_bytes(const uint8_t* buffer, uint32_t total_sz);
|
||||||
protected:
|
protected:
|
||||||
virtual void write_ext_header(Memory::OutputMemoryStream& stream) { }
|
virtual void write_ext_header(Memory::OutputMemoryStream& stream);
|
||||||
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream) { }
|
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream);
|
||||||
void parse_tagged_parameters(Memory::InputMemoryStream& stream);
|
void parse_tagged_parameters(Memory::InputMemoryStream& stream);
|
||||||
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t* val);
|
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t* val);
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ public:
|
|||||||
*
|
*
|
||||||
* This effectively returns the address_size constant.
|
* This effectively returns the address_size constant.
|
||||||
*/
|
*/
|
||||||
const size_t size() const {
|
size_t size() const {
|
||||||
return address_size;
|
return address_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T* find_pdu(PDUType type = T::pdu_flag) const {
|
const T* find_pdu(PDUType type = T::pdu_flag) const {
|
||||||
return const_cast<PDU*>(this)->find_pdu<T>();
|
return const_cast<PDU*>(this)->find_pdu<T>(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -381,7 +381,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T& rfind_pdu(PDUType type = T::pdu_flag) const {
|
const T& rfind_pdu(PDUType type = T::pdu_flag) const {
|
||||||
return const_cast<PDU*>(this)->rfind_pdu<T>();
|
return const_cast<PDU*>(this)->rfind_pdu<T>(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,9 +433,7 @@ public:
|
|||||||
* \param ptr The pointer to the buffer.
|
* \param ptr The pointer to the buffer.
|
||||||
* \param total_sz The size of the buffer.
|
* \param total_sz The size of the buffer.
|
||||||
*/
|
*/
|
||||||
virtual bool matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
virtual bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Check whether this PDU matches the specified flag.
|
* \brief Check whether this PDU matches the specified flag.
|
||||||
@@ -485,7 +483,7 @@ protected:
|
|||||||
*
|
*
|
||||||
* \param parent The parent PDU.
|
* \param parent The parent PDU.
|
||||||
*/
|
*/
|
||||||
virtual void prepare_for_serialize(const PDU* parent) { }
|
virtual void prepare_for_serialize(const PDU* parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Serializes this PDU and propagates this action to child PDUs.
|
* \brief Serializes this PDU and propagates this action to child PDUs.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata ARP::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata ARP::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(arp_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(arp_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ void BootP::vend(const vend_type& newvend_) {
|
|||||||
vend_ = newvend_;
|
vend_ = newvend_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BootP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void BootP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(bootp_);
|
stream.write(bootp_);
|
||||||
stream.write(vend_.begin(), vend_.end());
|
stream.write(vend_.begin(), vend_.end());
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata DHCP::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata DHCP::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(bootp_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(bootp_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata DHCPv6::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata DHCPv6::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < 2)) {
|
if (TINS_UNLIKELY(total_sz < 2)) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata DNS::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata DNS::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(dns_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(dns_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
@@ -386,7 +386,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
|
|||||||
return end_ptr - start_ptr;
|
return end_ptr - start_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNS::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void DNS::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
stream.write(records_data_.begin(), records_data_.end());
|
stream.write(records_data_.begin(), records_data_.end());
|
||||||
|
|||||||
@@ -67,9 +67,8 @@ Dot11::Dot11(const address_type& dst_hw_addr)
|
|||||||
addr1(dst_hw_addr);
|
addr1(dst_hw_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dot11::Dot11(const dot11_header* header_ptr)
|
Dot11::Dot11(const dot11_header* /*header_ptr*/)
|
||||||
: header_(), options_size_(0) {
|
: header_(), options_size_(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dot11::Dot11(const uint8_t* buffer, uint32_t total_sz)
|
Dot11::Dot11(const uint8_t* buffer, uint32_t total_sz)
|
||||||
@@ -78,6 +77,12 @@ Dot11::Dot11(const uint8_t* buffer, uint32_t total_sz)
|
|||||||
stream.read(header_);
|
stream.read(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dot11::write_ext_header(Memory::OutputMemoryStream& /*stream*/) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dot11::write_fixed_parameters(Memory::OutputMemoryStream& /*stream*/) {
|
||||||
|
}
|
||||||
|
|
||||||
void Dot11::parse_tagged_parameters(InputMemoryStream& stream) {
|
void Dot11::parse_tagged_parameters(InputMemoryStream& stream) {
|
||||||
if (stream) {
|
if (stream) {
|
||||||
while (stream.size() >= 2) {
|
while (stream.size() >= 2) {
|
||||||
@@ -208,7 +213,7 @@ void Dot11::send(PacketSender& sender, const NetworkInterface& iface) {
|
|||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
write_ext_header(stream);
|
write_ext_header(stream);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata Dot1Q::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata Dot1Q::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(dot1q_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(dot1q_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace Tins {
|
|||||||
|
|
||||||
const Dot3::address_type Dot3::BROADCAST("ff:ff:ff:ff:ff:ff");
|
const Dot3::address_type Dot3::BROADCAST("ff:ff:ff:ff:ff:ff");
|
||||||
|
|
||||||
PDU::metadata Dot3::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata Dot3::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(dot3_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(dot3_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ bool Dot3::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dot3::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void Dot3::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
header_.length = Endian::host_to_be<uint16_t>(size() - sizeof(header_));
|
header_.length = Endian::host_to_be<uint16_t>(size() - sizeof(header_));
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ bool EthernetII::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
Constants::Ethernet::e flag;
|
Constants::Ethernet::e flag;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata ICMP::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata ICMP::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(icmp_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(icmp_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -450,6 +450,8 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pare
|
|||||||
total_sz = Endian::host_to_be<uint16_t>(total_sz);
|
total_sz = Endian::host_to_be<uint16_t>(total_sz);
|
||||||
header_.frag_off = Endian::be_to_host(header_.frag_off);
|
header_.frag_off = Endian::be_to_host(header_.frag_off);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Internals::unused(parent);
|
||||||
#endif
|
#endif
|
||||||
tot_len(total_sz);
|
tot_len(total_sz);
|
||||||
head_len(static_cast<uint8_t>(header_size() / sizeof(uint32_t)));
|
head_len(static_cast<uint8_t>(header_size() / sizeof(uint32_t)));
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ PDU::metadata IPv6::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
|||||||
return metadata(header_size, pdu_flag, PDU::UNKNOWN);
|
return metadata(header_size, pdu_flag, PDU::UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPv6::IPv6(address_type ip_dst, address_type ip_src, PDU* child)
|
IPv6::IPv6(address_type ip_dst, address_type ip_src, PDU* /*child*/)
|
||||||
: header_(), headers_size_(0) {
|
: header_(), headers_size_(0) {
|
||||||
version(6);
|
version(6);
|
||||||
dst_addr(ip_dst);
|
dst_addr(ip_dst);
|
||||||
@@ -219,7 +219,7 @@ bool IPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
uint8_t new_flag = Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type());
|
uint8_t new_flag = Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type());
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ void LLC::clear_information_fields() {
|
|||||||
information_fields_.clear();
|
information_fields_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz, const Tins::PDU* parent) {
|
void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz, const Tins::PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) {
|
if (inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) {
|
||||||
dsap(0x42);
|
dsap(0x42);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string.h>
|
||||||
#include "offline_packet_filter.h"
|
#include "offline_packet_filter.h"
|
||||||
#include "pdu.h"
|
#include "pdu.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
@@ -64,7 +65,8 @@ void OfflinePacketFilter::init(const string& pcap_filter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OfflinePacketFilter::matches_filter(const uint8_t* buffer, uint32_t total_sz) const {
|
bool OfflinePacketFilter::matches_filter(const uint8_t* buffer, uint32_t total_sz) const {
|
||||||
pcap_pkthdr header = {};
|
pcap_pkthdr header;
|
||||||
|
memset(&header, 0, sizeof(header));
|
||||||
header.len = total_sz;
|
header.len = total_sz;
|
||||||
header.caplen = total_sz;
|
header.caplen = total_sz;
|
||||||
return pcap_offline_filter(&filter_, &header, buffer) != 0;
|
return pcap_offline_filter(&filter_, &header, buffer) != 0;
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ bool PacketSender::ether_socket_initialized(const NetworkInterface& iface) const
|
|||||||
#if defined(BSD) || defined(__FreeBSD_kernel__)
|
#if defined(BSD) || defined(__FreeBSD_kernel__)
|
||||||
return ether_socket_.count(iface.id());
|
return ether_socket_.count(iface.id());
|
||||||
#else
|
#else
|
||||||
|
Internals::unused(iface);
|
||||||
return ether_socket_ != INVALID_RAW_SOCKET;
|
return ether_socket_ != INVALID_RAW_SOCKET;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -234,6 +235,7 @@ void PacketSender::open_l2_socket(const NetworkInterface& iface) {
|
|||||||
}
|
}
|
||||||
ether_socket_[iface.id()] = sock;
|
ether_socket_[iface.id()] = sock;
|
||||||
#else
|
#else
|
||||||
|
Internals::unused(iface);
|
||||||
if (ether_socket_ == INVALID_RAW_SOCKET) {
|
if (ether_socket_ == INVALID_RAW_SOCKET) {
|
||||||
ether_socket_ = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
ether_socket_ = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
||||||
|
|
||||||
@@ -284,6 +286,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface& iface)
|
|||||||
}
|
}
|
||||||
ether_socket_.erase(it);
|
ether_socket_.erase(it);
|
||||||
#elif !defined(_WIN32)
|
#elif !defined(_WIN32)
|
||||||
|
Internals::unused(iface);
|
||||||
if (ether_socket_ == INVALID_RAW_SOCKET) {
|
if (ether_socket_ == INVALID_RAW_SOCKET) {
|
||||||
throw invalid_socket_type();
|
throw invalid_socket_type();
|
||||||
}
|
}
|
||||||
@@ -294,6 +297,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface& iface)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Internals::unused(iface);
|
||||||
if (type >= SOCKETS_END || sockets_[type] == INVALID_RAW_SOCKET) {
|
if (type >= SOCKETS_END || sockets_[type] == INVALID_RAW_SOCKET) {
|
||||||
throw invalid_socket_type();
|
throw invalid_socket_type();
|
||||||
}
|
}
|
||||||
@@ -354,6 +358,8 @@ void PacketSender::send_l2(PDU& pdu,
|
|||||||
PDU::serialization_type buffer = pdu.serialize();
|
PDU::serialization_type buffer = pdu.serialize();
|
||||||
|
|
||||||
#ifdef TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
#ifdef TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
||||||
|
Internals::unused(len_addr);
|
||||||
|
Internals::unused(link_addr);
|
||||||
open_l2_socket(iface);
|
open_l2_socket(iface);
|
||||||
pcap_t* handle = pcap_handles_[iface];
|
pcap_t* handle = pcap_handles_[iface];
|
||||||
const int buf_size = static_cast<int>(buffer.size());
|
const int buf_size = static_cast<int>(buffer.size());
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string.h>
|
||||||
#include "packet_writer.h"
|
#include "packet_writer.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "pdu.h"
|
#include "pdu.h"
|
||||||
@@ -71,11 +72,11 @@ void PacketWriter::write(Packet& packet) {
|
|||||||
|
|
||||||
void PacketWriter::write(PDU& pdu, const struct timeval& tv) {
|
void PacketWriter::write(PDU& pdu, const struct timeval& tv) {
|
||||||
PDU::serialization_type buffer = pdu.serialize();
|
PDU::serialization_type buffer = pdu.serialize();
|
||||||
struct pcap_pkthdr header = {
|
struct pcap_pkthdr header;
|
||||||
tv,
|
memset(&header, 0, sizeof(header));
|
||||||
static_cast<bpf_u_int32>(buffer.size()),
|
header.ts = tv;
|
||||||
static_cast<bpf_u_int32>(buffer.size())
|
header.caplen = static_cast<bpf_u_int32>(buffer.size());
|
||||||
};
|
header.len = static_cast<bpf_u_int32>(buffer.size());
|
||||||
pcap_dump((u_char*)dumper_, &header, &buffer[0]);
|
pcap_dump((u_char*)dumper_, &header, &buffer[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ void PDU::copy_inner_pdu(const PDU& pdu) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDU::prepare_for_serialize(const PDU* /*parent*/) {
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t PDU::size() const {
|
uint32_t PDU::size() const {
|
||||||
uint32_t sz = header_size() + trailer_size();
|
uint32_t sz = header_size() + trailer_size();
|
||||||
const PDU* ptr(inner_pdu_);
|
const PDU* ptr(inner_pdu_);
|
||||||
@@ -91,6 +94,10 @@ PDU* PDU::recv_response(PacketSender &, const NetworkInterface &) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PDU::matches_response(const uint8_t* /*ptr*/, uint32_t /*total_sz*/) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void PDU::inner_pdu(PDU* next_pdu) {
|
void PDU::inner_pdu(PDU* next_pdu) {
|
||||||
delete inner_pdu_;
|
delete inner_pdu_;
|
||||||
inner_pdu_ = next_pdu;
|
inner_pdu_ = next_pdu;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ uint32_t PKTAP::header_size() const {
|
|||||||
return sizeof(header_);
|
return sizeof(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PKTAP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void PKTAP::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/, const PDU* /*parent*/) {
|
||||||
throw pdu_not_serializable();
|
throw pdu_not_serializable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ uint32_t PPI::header_size() const {
|
|||||||
return static_cast<uint32_t>(sizeof(header_) + data_.size());
|
return static_cast<uint32_t>(sizeof(header_) + data_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPI::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void PPI::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/, const PDU *) {
|
||||||
throw pdu_not_serializable();
|
throw pdu_not_serializable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ bool RadioTap::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
uint8_t* buffer_start = buffer;
|
uint8_t* buffer_start = buffer;
|
||||||
radio_.it_len = Endian::host_to_le<uint16_t>(header_size());
|
radio_.it_len = Endian::host_to_le<uint16_t>(header_size());
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void RawPDU::payload(const payload_type& pload) {
|
|||||||
payload_ = pload;
|
payload_ = pload;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RawPDU::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
bool RawPDU::matches_response(const uint8_t* /*ptr*/, uint32_t /*total_sz*/) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ uint32_t SNAP::header_size() const {
|
|||||||
return sizeof(snap_);
|
return sizeof(snap_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
|
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
|
||||||
|
|||||||
@@ -356,6 +356,8 @@ void Sniffer::set_immediate_mode(bool enabled) {
|
|||||||
if (pcap_set_immediate_mode(get_pcap_handle(), enabled)) {
|
if (pcap_set_immediate_mode(get_pcap_handle(), enabled)) {
|
||||||
throw pcap_error(pcap_geterr(get_pcap_handle()));
|
throw pcap_error(pcap_geterr(get_pcap_handle()));
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Internals::unused(enabled);
|
||||||
#endif // HAVE_PCAP_IMMEDIATE_MODE
|
#endif // HAVE_PCAP_IMMEDIATE_MODE
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,6 +368,8 @@ void Sniffer::set_timestamp_precision(int value) {
|
|||||||
if (result == PCAP_ERROR_TSTAMP_PRECISION_NOTSUP) {
|
if (result == PCAP_ERROR_TSTAMP_PRECISION_NOTSUP) {
|
||||||
throw pcap_error("Timestamp precision not supported");
|
throw pcap_error("Timestamp precision not supported");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Internals::unused(value);
|
||||||
#endif // HAVE_PCAP_TIMESTAMP_PRECISION
|
#endif // HAVE_PCAP_TIMESTAMP_PRECISION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -309,13 +309,13 @@ void Stream::on_server_flow_data(const Flow& /*flow*/) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::on_client_out_of_order(const Flow& flow, uint32_t seq, const payload_type& payload) {
|
void Stream::on_client_out_of_order(const Flow& /*flow*/, uint32_t seq, const payload_type& payload) {
|
||||||
if (on_client_out_of_order_callback_) {
|
if (on_client_out_of_order_callback_) {
|
||||||
on_client_out_of_order_callback_(*this, seq, payload);
|
on_client_out_of_order_callback_(*this, seq, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::on_server_out_of_order(const Flow& flow, uint32_t seq, const payload_type& payload) {
|
void Stream::on_server_out_of_order(const Flow& /*flow*/, uint32_t seq, const payload_type& payload) {
|
||||||
if (on_server_out_of_order_callback_) {
|
if (on_server_out_of_order_callback_) {
|
||||||
on_server_out_of_order_callback_(*this, seq, payload);
|
on_server_out_of_order_callback_(*this, seq, payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void TCPStream::safe_insert(fragments_type& frags, uint32_t seq, RawPDU* raw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TCPStream::generic_process(uint32_t& my_seq,
|
bool TCPStream::generic_process(uint32_t& my_seq,
|
||||||
uint32_t& other_seq,
|
uint32_t& /*other_seq*/,
|
||||||
payload_type& pload,
|
payload_type& pload,
|
||||||
fragments_type& frags,
|
fragments_type& frags,
|
||||||
TCP* tcp) {
|
TCP* tcp) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ using Tins::Memory::OutputMemoryStream;
|
|||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
PDU::metadata UDP::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
PDU::metadata UDP::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) {
|
||||||
if (TINS_UNLIKELY(total_sz < sizeof(udp_header))) {
|
if (TINS_UNLIKELY(total_sz < sizeof(udp_header))) {
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -654,7 +654,7 @@ TEST_F(ICMPv6Test, ExtensionsParsingWithoutALengthField) {
|
|||||||
const uint8_t ext[] = { 0, 8, 1, 1, 24, 150, 1, 1 };
|
const uint8_t ext[] = { 0, 8, 1, 1, 24, 150, 1, 1 };
|
||||||
ICMPv6 icmp(packet_with_extensions, sizeof(packet_with_extensions));
|
ICMPv6 icmp(packet_with_extensions, sizeof(packet_with_extensions));
|
||||||
ICMPExtensionsStructure extensions = icmp.extensions();
|
ICMPExtensionsStructure extensions = icmp.extensions();
|
||||||
ASSERT_EQ(1, extensions.extensions().size());
|
ASSERT_EQ(1U, extensions.extensions().size());
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
ICMPExtension::payload_type(ext, ext + sizeof(ext)),
|
ICMPExtension::payload_type(ext, ext + sizeof(ext)),
|
||||||
extensions.extensions().begin()->serialize()
|
extensions.extensions().begin()->serialize()
|
||||||
@@ -673,7 +673,7 @@ TEST_F(ICMPv6Test, ExtensionsParsingWithALengthField) {
|
|||||||
const uint8_t ext[] = { 0, 8, 1, 1, 24, 150, 1, 1 };
|
const uint8_t ext[] = { 0, 8, 1, 1, 24, 150, 1, 1 };
|
||||||
ICMPv6 icmp(packet_with_extensions_and_length, sizeof(packet_with_extensions_and_length));
|
ICMPv6 icmp(packet_with_extensions_and_length, sizeof(packet_with_extensions_and_length));
|
||||||
ICMPExtensionsStructure extensions = icmp.extensions();
|
ICMPExtensionsStructure extensions = icmp.extensions();
|
||||||
ASSERT_EQ(1, extensions.extensions().size());
|
ASSERT_EQ(1U, extensions.extensions().size());
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
ICMPExtension::payload_type(ext, ext + sizeof(ext)),
|
ICMPExtension::payload_type(ext, ext + sizeof(ext)),
|
||||||
extensions.extensions().begin()->serialize()
|
extensions.extensions().begin()->serialize()
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void FlowTest::cumulative_stream_server_data_handler(Stream& stream) {
|
|||||||
stream_server_payload_chunks.push_back(stream.server_flow().payload());
|
stream_server_payload_chunks.push_back(stream.server_flow().payload());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlowTest::out_of_order_handler(Flow& session, uint32_t seq, Flow::payload_type payload) {
|
void FlowTest::out_of_order_handler(Flow& /*session*/, uint32_t seq, Flow::payload_type payload) {
|
||||||
flow_out_of_order_chunks.push_back(make_pair(seq, move(payload)));
|
flow_out_of_order_chunks.push_back(make_pair(seq, move(payload)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,11 +777,11 @@ TEST_F(AckTrackerTest, AckingTcp_Sack2) {
|
|||||||
|
|
||||||
tracker.process_packet(make_tcp_ack(5));
|
tracker.process_packet(make_tcp_ack(5));
|
||||||
EXPECT_EQ(4U, tracker.acked_intervals().size());
|
EXPECT_EQ(4U, tracker.acked_intervals().size());
|
||||||
EXPECT_EQ(5, tracker.ack_number());
|
EXPECT_EQ(5U, tracker.ack_number());
|
||||||
|
|
||||||
tracker.process_packet(make_tcp_ack(15));
|
tracker.process_packet(make_tcp_ack(15));
|
||||||
EXPECT_EQ(0U, tracker.acked_intervals().size());
|
EXPECT_EQ(0U, tracker.acked_intervals().size());
|
||||||
EXPECT_EQ(15, tracker.ack_number());
|
EXPECT_EQ(15U, tracker.ack_number());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AckTrackerTest, AckingTcp_Sack3) {
|
TEST_F(AckTrackerTest, AckingTcp_Sack3) {
|
||||||
@@ -803,16 +803,16 @@ TEST_F(AckTrackerTest, AckingTcp_SackOutOfOrder1) {
|
|||||||
AckTracker tracker(0, true);
|
AckTracker tracker(0, true);
|
||||||
tracker.process_packet(make_tcp_ack(10));
|
tracker.process_packet(make_tcp_ack(10));
|
||||||
tracker.process_packet(make_tcp_ack(0, make_pair(9, 12)));
|
tracker.process_packet(make_tcp_ack(0, make_pair(9, 12)));
|
||||||
EXPECT_EQ(0, tracker.acked_intervals().size());
|
EXPECT_EQ(0U, tracker.acked_intervals().size());
|
||||||
EXPECT_EQ(11, tracker.ack_number());
|
EXPECT_EQ(11U, tracker.ack_number());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AckTrackerTest, AckingTcp_SackOutOfOrder2) {
|
TEST_F(AckTrackerTest, AckingTcp_SackOutOfOrder2) {
|
||||||
AckTracker tracker(0, true);
|
AckTracker tracker(0, true);
|
||||||
tracker.process_packet(make_tcp_ack(10));
|
tracker.process_packet(make_tcp_ack(10));
|
||||||
tracker.process_packet(make_tcp_ack(0, make_pair(10, 12)));
|
tracker.process_packet(make_tcp_ack(0, make_pair(10, 12)));
|
||||||
EXPECT_EQ(0, tracker.acked_intervals().size());
|
EXPECT_EQ(0U, tracker.acked_intervals().size());
|
||||||
EXPECT_EQ(11, tracker.ack_number());
|
EXPECT_EQ(11U, tracker.ack_number());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FlowTest, AckNumbersAreCorrect) {
|
TEST_F(FlowTest, AckNumbersAreCorrect) {
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ TEST_F(WPA2DecryptTest, HandshakeCapturedCallback) {
|
|||||||
decrypter.decrypt(radio);
|
decrypter.decrypt(radio);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EQ(2, handshakes_.size());
|
ASSERT_EQ(2U, handshakes_.size());
|
||||||
handshake hs = handshakes_[0];
|
handshake hs = handshakes_[0];
|
||||||
EXPECT_EQ(hs.ssid, "Coherer");
|
EXPECT_EQ(hs.ssid, "Coherer");
|
||||||
EXPECT_EQ(address_type("00:0d:93:82:36:3a"), hs.client_hw);
|
EXPECT_EQ(address_type("00:0d:93:82:36:3a"), hs.client_hw);
|
||||||
@@ -367,7 +367,7 @@ TEST_F(WPA2DecryptTest, AccessPointFoundCallback) {
|
|||||||
decrypter.decrypt(radio);
|
decrypter.decrypt(radio);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EQ(2, access_points_.size());
|
ASSERT_EQ(2U, access_points_.size());
|
||||||
ap_data data = access_points_[0];
|
ap_data data = access_points_[0];
|
||||||
EXPECT_EQ("Coherer", data.ssid);
|
EXPECT_EQ("Coherer", data.ssid);
|
||||||
EXPECT_EQ(address_type("00:0c:41:82:b2:55"), data.bssid);
|
EXPECT_EQ(address_type("00:0c:41:82:b2:55"), data.bssid);
|
||||||
|
|||||||
Reference in New Issue
Block a user