1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 04:54:28 +01:00

Added concat operator to Packet and an overload that takes a PDU*.

This commit is contained in:
Matias Fontanini
2012-12-05 17:04:39 -03:00
parent 765285c6ee
commit 75b32c75bc
6 changed files with 95 additions and 11 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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.
*/