1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-22 18:25:57 +01:00

Removed the PDU* parameter in several PDU's constructors.

This commit is contained in:
Matias Fontanini
2013-04-23 20:03:08 -03:00
parent 7e85058ef1
commit bf604339f0
24 changed files with 83 additions and 143 deletions

View File

@@ -58,7 +58,7 @@ subdir = .
DIST_COMMON = README $(am__configure_deps) $(libtins_include_HEADERS) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/libtins.pc.in $(top_srcdir)/configure \
$(top_srcdir)/include/config.h.in AUTHORS INSTALL THANKS \
$(top_srcdir)/include/config.h.in AUTHORS THANKS TODO \
config.guess config.sub depcomp install-sh ltmain.sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \

View File

@@ -178,10 +178,8 @@ namespace Tins {
* destination's and source's MAC.
*
* \param dst_hw_addr The destination hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11(const address_type &dst_hw_addr = address_type(),
PDU* child = 0);
Dot11(const address_type &dst_hw_addr = address_type());
/**
* \brief Constructs 802.11 PDU from a buffer and adds all
@@ -2656,11 +2654,9 @@ namespace Tins {
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
* \param child The inner PDU.
*/
Dot11Data(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type(),
PDU* child = 0);
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11Data object from a buffer and adds
@@ -2828,11 +2824,9 @@ namespace Tins {
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11QoSData(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type(),
PDU* child = 0);
const address_type &src_hw_addr = address_type());
/**
* \brief Constructors Dot11QoSData object from a buffer and adds
@@ -2919,10 +2913,8 @@ namespace Tins {
* source hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11Control(const address_type &dst_addr = address_type(),
PDU* child = 0);
Dot11Control(const address_type &dst_addr = address_type());
/**
* \brief Constructs a Dot11Control object from a buffer and
@@ -2981,11 +2973,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11ControlTA(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11ControlTA object from a buffer and
@@ -3037,11 +3027,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11RTS(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11RTS object from a buffer and adds all
@@ -3098,11 +3086,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11PSPoll(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11PSPoll object from a buffer and
@@ -3160,11 +3146,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11CFEnd(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11CFEnd object from a buffer and adds
@@ -3222,11 +3206,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11EndCFAck(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11EndCFAck frame object from a buffer
@@ -3283,10 +3265,8 @@ namespace Tins {
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11Ack(const address_type &dst_addr = address_type(),
PDU* child = 0);
Dot11Ack(const address_type &dst_addr = address_type());
/**
* \brief Constructs a Dot11Ack frame object from a buffer and
@@ -3347,11 +3327,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11BlockAckRequest(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11BlockAckRequest object from a buffer
@@ -3490,11 +3468,9 @@ namespace Tins {
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
* \param child PDU* with the PDU contained by the 802.11 PDU (optional).
*/
Dot11BlockAck(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type(),
PDU* child = 0);
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11BlockAck frame object from a buffer

View File

@@ -69,8 +69,7 @@ namespace Tins {
* \param child The PDU which will be set as the inner PDU.
*/
Dot3(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type(),
PDU* child = 0);
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot3 object from a buffer and adds a

View File

@@ -61,13 +61,11 @@ namespace Tins {
/**
* \brief Constructs an ethernet II PDU.
*
* \param dst_hw_addr address_type containing the destination's MAC(optional).
* \param src_hw_addr address_type containing the source's MAC(optional).
* \param child PDU* with the PDU contained by the ethernet PDU (optional).
* \param dst_hw_addr address_type containing the destination's MAC.
* \param src_hw_addr address_type containing the source's MAC.
*/
EthernetII(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type(),
PDU* child = 0);
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a EthernetII object from a buffer and adds

View File

@@ -229,12 +229,9 @@ namespace Tins {
*
* \param ip_dst The destination ip address(optional).
* \param ip_src The source ip address(optional).
* \param child pointer to a PDU which will be set as the inner_pdu
* for the packet being constructed(optional).
*/
IP(address_type ip_dst = address_type(),
address_type ip_src = address_type(),
PDU *child = 0);
address_type ip_src = address_type());
/**
* \brief Constructs an IP object from a buffer and adds all

View File

@@ -90,18 +90,17 @@ namespace Tins {
};
/**
* \brief Creates an instance of LLC
* \param child The child PDU.(optional)
* \brief Default constructor.
*/
LLC(PDU *child = 0);
LLC();
/**
* \brief Creates an instance of LLC, setting the dsap and ssap.
* The control field is set all to 0.
* @param dsap The dsap value to be set.
* @param ssap The ssap value to be set.
* \brief Constructs an instance of LLC, setting the dsap and ssap.
* The control field is set to 0.
* \param dsap The dsap value to be set.
* \param ssap The ssap value to be set.
*/
LLC(uint8_t dsap, uint8_t ssap, PDU* child = 0);
LLC(uint8_t dsap, uint8_t ssap);
/**
* \brief Constructs a LLC object from a buffer and adds all

View File

@@ -47,16 +47,6 @@ public:
* The family identifier is left as zero.
*/
Loopback();
/**
* \brief Construct a Loopback object.
*
* The NetworkInterface object will only be used in *BSD, where
* Null/Loopback PDUs can actually be sent.
*
* \param inner_pdu The inner pdu to be set.
*/
Loopback(PDU *inner_pdu = 0);
/**
* \brief Construct a Loopback object from a buffer and adds

View File

@@ -121,13 +121,9 @@ namespace Tins {
};
/**
* \brief PDU constructor
*
* Must be called by subclasses in their constructors.
* \param flag The flag identifier for the subclass' PDU.
* \param next_pdu The child PDU. Can be obviated.
* \brief Default constructor.
*/
PDU(PDU *next_pdu = 0);
PDU();
#if TINS_IS_CXX11
/**

View File

@@ -107,10 +107,9 @@ namespace Tins {
};
/**
* \brief Creates an instance of RadioTap.
* \param child The child PDU.
* \brief Default constructor.
*/
RadioTap(PDU *child = 0);
RadioTap();
/**
* \brief Constructs a RadioTap object from a buffer and adds all

View File

@@ -56,9 +56,8 @@ namespace Tins {
* \brief Creates an instance of SNAP
* This constructor sets the dsap and ssap fields to 0xaa, and
* the id field to 3.
* \param child The child PDU.(optional)
*/
SNAP(PDU *child = 0);
SNAP();
/**
* \brief Constructs a SNAP object from a buffer and adds all

View File

@@ -53,11 +53,11 @@ namespace Tins {
*
* Creates an instance of UDP. Destination and source port can
* be provided, otherwise both will be 0.
*
* \param dport Destination port.
* \param sport Source port.
* \param child The child PDU(optional).
* */
UDP(uint16_t dport = 0, uint16_t sport = 0, PDU *child = 0);
UDP(uint16_t dport = 0, uint16_t sport = 0);
/**
* \brief Constructs an UDP object from a buffer.
@@ -145,7 +145,7 @@ namespace Tins {
/**
* \sa PDU::clone
*/
PDU *clone() const {
UDP *clone() const {
return new UDP(*this);
}
private:

View File

@@ -125,24 +125,24 @@ EthernetII ARP::make_arp_request(ipaddress_type target, ipaddress_type sender,
const hwaddress_type &hw_snd)
{
/* Create ARP packet and set its attributes */
ARP* arp = new ARP();
arp->target_ip_addr(target);
arp->sender_ip_addr(sender);
arp->sender_hw_addr(hw_snd);
arp->opcode(REQUEST);
ARP arp;
arp.target_ip_addr(target);
arp.sender_ip_addr(sender);
arp.sender_hw_addr(hw_snd);
arp.opcode(REQUEST);
/* Create the EthernetII PDU with the ARP PDU as its inner PDU */
return EthernetII(EthernetII::BROADCAST, hw_snd, arp);
return EthernetII(EthernetII::BROADCAST, hw_snd) / arp;
}
EthernetII ARP::make_arp_reply(ipaddress_type target, ipaddress_type sender,
const hwaddress_type &hw_tgt, const hwaddress_type &hw_snd)
{
/* Create ARP packet and set its attributes */
ARP* arp = new ARP(target, sender, hw_tgt, hw_snd);
arp->opcode(REPLY);
ARP arp(target, sender, hw_tgt, hw_snd);
arp.opcode(REPLY);
/* Create the EthernetII PDU with the ARP PDU as its inner PDU */
return EthernetII(hw_tgt, hw_snd, arp);
return EthernetII(hw_tgt, hw_snd) / arp;
}
}

View File

@@ -60,8 +60,8 @@ using std::runtime_error;
namespace Tins {
const Dot11::address_type Dot11::BROADCAST = "ff:ff:ff:ff:ff:ff";
Dot11::Dot11(const address_type &dst_hw_addr, PDU* child)
: PDU(child), _options_size(0)
Dot11::Dot11(const address_type &dst_hw_addr)
: _options_size(0)
{
memset(&_header, 0, sizeof(ieee80211_header));
addr1(dst_hw_addr);
@@ -1296,8 +1296,8 @@ uint32_t Dot11Data::init(const uint8_t *buffer, uint32_t total_sz) {
}
Dot11Data::Dot11Data(const address_type &dst_hw_addr,
const address_type &src_hw_addr, PDU* child)
: Dot11(dst_hw_addr, child)
const address_type &src_hw_addr)
: Dot11(dst_hw_addr)
{
type(Dot11::DATA);
memset(&_ext_header, 0, sizeof(_ext_header));
@@ -1354,8 +1354,8 @@ uint32_t Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
/* QoS data. */
Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr,
const address_type &src_hw_addr, PDU* child)
: Dot11Data(dst_hw_addr, src_hw_addr, child)
const address_type &src_hw_addr)
: Dot11Data(dst_hw_addr, src_hw_addr)
{
subtype(Dot11::QOS_DATA_DATA);
_qos_control = 0;
@@ -1395,8 +1395,8 @@ uint32_t Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz
/* Dot11Control */
Dot11Control::Dot11Control(const address_type &dst_addr, PDU* child)
: Dot11(dst_addr, child)
Dot11Control::Dot11Control(const address_type &dst_addr)
: Dot11(dst_addr)
{
type(CONTROL);
}
@@ -1409,8 +1409,8 @@ Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz)
/* Dot11ControlTA */
Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr,
const address_type &target_address, PDU* child)
: Dot11Control(dst_addr, child)
const address_type &target_address)
: Dot11Control(dst_addr)
{
target_addr(target_address);
}
@@ -1444,8 +1444,8 @@ void Dot11ControlTA::target_addr(const address_type &addr) {
/* Dot11RTS */
Dot11RTS::Dot11RTS(const address_type &dst_addr,
const address_type &target_addr, PDU* child)
: Dot11ControlTA(dst_addr, target_addr, child)
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
subtype(RTS);
}
@@ -1458,8 +1458,8 @@ Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz)
/* Dot11PSPoll */
Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr,
const address_type &target_addr, PDU* child)
: Dot11ControlTA(dst_addr, target_addr, child)
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
subtype(PS);
}
@@ -1472,8 +1472,8 @@ Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz)
/* Dot11CFEnd */
Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr,
const address_type &target_addr, PDU* child)
: Dot11ControlTA(dst_addr, target_addr, child)
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
subtype(CF_END);
}
@@ -1486,8 +1486,8 @@ Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz)
/* Dot11EndCFAck */
Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr,
const address_type &target_addr, PDU* child)
: Dot11ControlTA(dst_addr, target_addr, child)
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
subtype(CF_END_ACK);
}
@@ -1499,8 +1499,8 @@ Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz)
/* Dot11Ack */
Dot11Ack::Dot11Ack(const address_type &dst_addr, PDU* child)
: Dot11Control(dst_addr, child)
Dot11Ack::Dot11Ack(const address_type &dst_addr)
: Dot11Control(dst_addr)
{
subtype(ACK);
}
@@ -1514,8 +1514,8 @@ Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz)
/* Dot11BlockAck */
Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type &dst_addr,
const address_type &target_addr, PDU* child)
: Dot11ControlTA(dst_addr, target_addr, child)
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
init_block_ack();
}
@@ -1579,8 +1579,8 @@ uint32_t Dot11BlockAckRequest::header_size() const {
/* Dot11BlockAck */
Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr,
const address_type &target_addr, PDU* child)
: Dot11ControlTA(dst_addr, target_addr, child)
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
subtype(BLOCK_ACK);
std::memset(_bitmap, 0, sizeof(_bitmap));

View File

@@ -51,9 +51,7 @@
namespace Tins {
const Dot3::address_type Dot3::BROADCAST("ff:ff:ff:ff:ff:ff");
Dot3::Dot3(const address_type &dst_hw_addr, const address_type &src_hw_addr,
PDU* child)
: PDU(child)
Dot3::Dot3(const address_type &dst_hw_addr, const address_type &src_hw_addr)
{
memset(&_eth, 0, sizeof(ethhdr));
this->dst_addr(dst_hw_addr);

View File

@@ -57,8 +57,7 @@ namespace Tins {
const EthernetII::address_type EthernetII::BROADCAST("ff:ff:ff:ff:ff:ff");
EthernetII::EthernetII(const address_type &dst_hw_addr,
const address_type &src_hw_addr, PDU* child)
: PDU(child)
const address_type &src_hw_addr)
{
memset(&_eth, 0, sizeof(ethhdr));
dst_addr(dst_hw_addr);

View File

@@ -59,8 +59,7 @@ namespace Tins {
const uint8_t IP::DEFAULT_TTL = 128;
IP::IP(address_type ip_dst, address_type ip_src, PDU *child)
: PDU(child)
IP::IP(address_type ip_dst, address_type ip_src)
{
init_ip_fields();
this->dst_addr(ip_dst);

View File

@@ -43,8 +43,8 @@ namespace Tins {
const uint8_t LLC::GLOBAL_DSAP_ADDR = 0xFF;
const uint8_t LLC::NULL_ADDR = 0x00;
LLC::LLC(PDU *child)
: PDU(child), _type(LLC::INFORMATION)
LLC::LLC()
: _type(LLC::INFORMATION)
{
memset(&_header, 0, sizeof(llchdr));
control_field_length = 2;
@@ -52,8 +52,8 @@ LLC::LLC(PDU *child)
information_field_length = 0;
}
LLC::LLC(uint8_t dsap, uint8_t ssap, PDU *child)
: PDU(child), _type(LLC::INFORMATION)
LLC::LLC(uint8_t dsap, uint8_t ssap)
: _type(LLC::INFORMATION)
{
_header.dsap = dsap;
_header.ssap = ssap;

View File

@@ -57,12 +57,6 @@ Loopback::Loopback()
: _family()
{
}
Loopback::Loopback(PDU *inner_pdu)
: PDU(inner_pdu), _family()
{
}
Loopback::Loopback(const uint8_t *buffer, uint32_t total_sz)

View File

@@ -36,7 +36,9 @@
namespace Tins {
PDU::PDU(PDU *next_pdu) : _inner_pdu(next_pdu) {
PDU::PDU()
: _inner_pdu()
{
}

View File

@@ -61,8 +61,7 @@ void read_field(const uint8_t* &buffer, uint32_t &total_sz, T& field) {
total_sz -= sizeof(field);
}
RadioTap::RadioTap(PDU *child)
: PDU(child)
RadioTap::RadioTap()
{
std::memset(&_radio, 0, sizeof(_radio));
init();

View File

@@ -44,7 +44,7 @@
#include "exceptions.h"
Tins::SNAP::SNAP(PDU *child) : PDU(child)
Tins::SNAP::SNAP()
{
std::memset(&_snap, 0, sizeof(_snap));
_snap.dsap = _snap.ssap = 0xaa;

View File

@@ -40,8 +40,7 @@
#include "exceptions.h"
namespace Tins {
UDP::UDP(uint16_t dport, uint16_t sport, PDU *child)
: PDU(child)
UDP::UDP(uint16_t dport, uint16_t sport)
{
this->dport(dport);
this->sport(sport);

View File

@@ -98,11 +98,10 @@ TEST_F(EthernetIITest, PayloadType) {
}
TEST_F(EthernetIITest, CompleteConstructor) {
EthernetII* eth2 = new EthernetII();
EthernetII eth(dst_addr, src_addr, eth2);
EthernetII eth2;
EthernetII eth = EthernetII(dst_addr, src_addr) / eth2;
EXPECT_EQ(eth.dst_addr(), dst_addr);
EXPECT_EQ(eth.src_addr(), src_addr);
EXPECT_TRUE(eth.inner_pdu() == eth2);
EXPECT_EQ(eth.payload_type(), 0);
}

View File

@@ -69,11 +69,9 @@ TEST_F(UDPTest, CopyAssignmentOperator) {
}
TEST_F(UDPTest, CompleteConstructor) {
UDP *inner = new UDP(0x48fa, 0x716b);
UDP udp(0x1234, 0x4321, inner);
UDP udp(0x1234, 0x4321);
EXPECT_EQ(udp.dport(), 0x1234);
EXPECT_EQ(udp.sport(), 0x4321);
EXPECT_TRUE(udp.inner_pdu() == inner);
}
TEST_F(UDPTest, DPort) {
@@ -109,7 +107,7 @@ TEST_F(UDPTest, ClonePDU) {
udp1.sport(sport);
udp1.length(length);
UDP *udp2 = static_cast<UDP*>(udp1.clone());
UDP *udp2 = udp1.clone();
ASSERT_TRUE(udp2);
EXPECT_EQ(udp2->sport(), sport);
EXPECT_EQ(udp2->dport(), dport);