mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Added concat operator to Packet and an overload that takes a PDU*.
This commit is contained in:
12
depends.d
12
depends.d
@@ -135,11 +135,13 @@ include/cxxstd.h:
|
||||
include/macros.h:
|
||||
|
||||
include/endianness.h:
|
||||
src/dot11.o: src/dot11.cpp include/dot11.h include/macros.h include/pdu.h \
|
||||
include/endianness.h include/hw_address.h include/small_uint.h \
|
||||
include/pdu_option.h include/network_interface.h include/ip_address.h \
|
||||
include/rawpdu.h include/rsn_information.h include/packet_sender.h \
|
||||
include/snap.h
|
||||
src/dot11.o: src/dot11.cpp include/macros.h include/dot11.h \
|
||||
include/macros.h include/pdu.h include/endianness.h include/hw_address.h \
|
||||
include/small_uint.h include/pdu_option.h include/network_interface.h \
|
||||
include/ip_address.h include/rawpdu.h include/rsn_information.h \
|
||||
include/packet_sender.h include/snap.h
|
||||
|
||||
include/macros.h:
|
||||
|
||||
include/dot11.h:
|
||||
|
||||
|
||||
@@ -130,8 +130,19 @@ public:
|
||||
*
|
||||
* The PDU* is cloned using PDU::clone.
|
||||
*/
|
||||
Packet(PDU *apdu, const Timestamp &tstamp)
|
||||
: pdu_(apdu->clone()), ts(tstamp) {}
|
||||
Packet(const PDU *apdu, const Timestamp &tstamp)
|
||||
: pdu_(apdu->clone()), ts(tstamp) { }
|
||||
|
||||
/**
|
||||
* \brief Constructs a Packet from a const PDU&.
|
||||
*
|
||||
* The timestamp will be set to the current time.
|
||||
*
|
||||
* This calls PDU::clone on the PDU parameter.
|
||||
*
|
||||
*/
|
||||
Packet(const PDU &rhs)
|
||||
: pdu_(rhs.clone()), ts(Timestamp::current_time()) { }
|
||||
|
||||
/**
|
||||
* \brief Constructs a Packet from a RefPacket.
|
||||
@@ -248,6 +259,19 @@ public:
|
||||
operator bool() const {
|
||||
return bool(pdu_);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* \brief Concatenation operator.
|
||||
*
|
||||
* Adds the PDU at the end of the PDU stack.
|
||||
*
|
||||
* \param rhs The PDU to be appended.
|
||||
*/
|
||||
Packet &operator/=(const PDU &rhs) {
|
||||
pdu_ /= rhs;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
PDU *pdu_;
|
||||
Timestamp ts;
|
||||
|
||||
@@ -362,6 +362,17 @@ namespace Tins {
|
||||
lop /= rop;
|
||||
return lop;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Concatenation operator on PDU pointers.
|
||||
*
|
||||
* \sa operator/=
|
||||
*/
|
||||
template<typename T>
|
||||
T *operator/= (T* lop, const PDU &rop) {
|
||||
*lop /= rop;
|
||||
return lop;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TINS_PDU_H
|
||||
|
||||
@@ -55,6 +55,20 @@ public:
|
||||
typedef suseconds_t microseconds_type;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Constructs a Timestamp which will hold the current time.
|
||||
*/
|
||||
static Timestamp current_time() {
|
||||
#ifdef WIN32
|
||||
//fixme
|
||||
return Timestamp();
|
||||
#else
|
||||
timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
return tv;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructs the timestamp.
|
||||
*/
|
||||
|
||||
@@ -139,13 +139,15 @@
|
||||
../include/macros.h:
|
||||
|
||||
../include/endianness.h:
|
||||
../src/dot11.o: ../src/dot11.cpp ../include/dot11.h ../include/macros.h \
|
||||
../include/pdu.h ../include/endianness.h ../include/hw_address.h \
|
||||
../include/small_uint.h ../include/pdu_option.h \
|
||||
../src/dot11.o: ../src/dot11.cpp ../include/macros.h ../include/dot11.h \
|
||||
../include/macros.h ../include/pdu.h ../include/endianness.h \
|
||||
../include/hw_address.h ../include/small_uint.h ../include/pdu_option.h \
|
||||
../include/network_interface.h ../include/ip_address.h \
|
||||
../include/rawpdu.h ../include/rsn_information.h \
|
||||
../include/packet_sender.h ../include/snap.h
|
||||
|
||||
../include/macros.h:
|
||||
|
||||
../include/dot11.h:
|
||||
|
||||
../include/macros.h:
|
||||
@@ -1655,7 +1657,8 @@ src/network_interface.o: src/network_interface.cpp \
|
||||
src/pdu.o: src/pdu.cpp ../include/ip.h ../include/pdu.h \
|
||||
../include/small_uint.h ../include/endianness.h ../include/macros.h \
|
||||
../include/ip_address.h ../include/pdu_option.h ../include/tcp.h \
|
||||
../include/rawpdu.h ../include/pdu.h
|
||||
../include/rawpdu.h ../include/pdu.h ../include/packet.h \
|
||||
../include/cxxstd.h ../include/timestamp.h
|
||||
|
||||
../include/ip.h:
|
||||
|
||||
@@ -1676,6 +1679,12 @@ src/pdu.o: src/pdu.cpp ../include/ip.h ../include/pdu.h \
|
||||
../include/rawpdu.h:
|
||||
|
||||
../include/pdu.h:
|
||||
|
||||
../include/packet.h:
|
||||
|
||||
../include/cxxstd.h:
|
||||
|
||||
../include/timestamp.h:
|
||||
src/radiotap.o: src/radiotap.cpp ../include/radiotap.h \
|
||||
../include/macros.h ../include/pdu.h ../include/endianness.h \
|
||||
../include/network_interface.h ../include/hw_address.h \
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "tcp.h"
|
||||
#include "rawpdu.h"
|
||||
#include "pdu.h"
|
||||
#include "packet.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Tins;
|
||||
@@ -30,3 +31,26 @@ TEST_F(PDUTest, OperatorConcat) {
|
||||
EXPECT_TRUE(std::equal(raw_payload.begin(), raw_payload.end(), raw->payload().begin()));
|
||||
}
|
||||
|
||||
TEST_F(PDUTest, OperatorConcatOnPointers) {
|
||||
std::string raw_payload = "Test";
|
||||
IP ip = IP("192.168.0.1") / TCP(22, 52);
|
||||
TCP *tcp = ip.find_pdu<TCP>();
|
||||
ASSERT_TRUE(tcp);
|
||||
tcp /= RawPDU(raw_payload);
|
||||
RawPDU *raw = ip.find_pdu<RawPDU>();
|
||||
ASSERT_TRUE(raw);
|
||||
ASSERT_EQ(raw->payload_size(), raw_payload.size());
|
||||
EXPECT_TRUE(std::equal(raw->payload().begin(), raw->payload().end(), raw_payload.begin()));
|
||||
}
|
||||
|
||||
TEST_F(PDUTest, OperatorConcatOnPacket) {
|
||||
std::string raw_payload = "Test";
|
||||
Packet packet = IP("192.168.0.1") / TCP(22, 52);
|
||||
TCP *tcp = packet.pdu()->find_pdu<TCP>();
|
||||
ASSERT_TRUE(tcp);
|
||||
tcp /= RawPDU(raw_payload);
|
||||
RawPDU *raw = packet.pdu()->find_pdu<RawPDU>();
|
||||
ASSERT_TRUE(raw);
|
||||
ASSERT_EQ(raw->payload_size(), raw_payload.size());
|
||||
EXPECT_TRUE(std::equal(raw->payload().begin(), raw->payload().end(), raw_payload.begin()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user