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

Done some minor fixes.

This commit is contained in:
Matias Fontanini
2012-08-09 23:39:32 -03:00
parent 91af0f9cc2
commit 55be59ee15
10 changed files with 398 additions and 401 deletions

View File

@@ -23,10 +23,11 @@
#define TINS_BOOTP_H
#include <stdint.h>
#include <stdint.h>
#include <algorithm>
#include "pdu.h"
#include "utils.h"
#include "ipaddress.h"
#include "hwaddress.h"
namespace Tins {
@@ -35,8 +36,8 @@ namespace Tins {
* \brief Class representing a BootP packet.
*/
class BootP : public PDU {
public:
typedef HWAddress<16> chaddr_type;
/**
* \brief This PDU's flag.
*/
@@ -156,7 +157,8 @@ namespace Tins {
* \brief Getter for the chaddr field.
* \return The chddr field for this BootP PDU.
*/
const uint8_t *chaddr() const { return _bootp.chaddr; }
//const uint8_t *chaddr() const { return _bootp.chaddr; }
chaddr_type chaddr() const { return _bootp.chaddr; }
/**
* \brief Getter for the sname field.
@@ -260,7 +262,17 @@ namespace Tins {
* The new_chaddr pointer must be at least BOOTP::hlen() bytes long.
* \param new_chaddr The chaddr to be set.
*/
void chaddr(const uint8_t *new_chaddr);
template<size_t n>
void chaddr(const HWAddress<n> &new_chaddr) {
// Copy the new addr
uint8_t *end = std::copy(
new_chaddr.begin(),
new_chaddr.begin() + std::min(n, sizeof(_bootp.chaddr)),
_bootp.chaddr
);
// Fill what's left with zeros
std::fill(end, _bootp.chaddr + chaddr_type::address_size, 0);
}
/**
* \brief Setter for the sname field.
@@ -288,11 +300,11 @@ namespace Tins {
PDUType pdu_type() const { return PDU::BOOTP; }
/**
* \brief Clones this PDU.
*
* \sa PDU::clone_pdu
*/
PDU *clone_pdu() const;
PDU *clone_pdu() const {
return do_clone_pdu<BootP>();
}
protected:
void copy_bootp_fields(const BootP *other);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);

View File

@@ -182,23 +182,6 @@ namespace Tins {
*/
DHCP(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Copy constructor.
*/
DHCP(const DHCP &other);
/**
* \brief Copy assignment operator.
*/
DHCP &operator= (const DHCP &other);
/**
* \brief DHCP destructor
*
* Releases the memory allocated for options.
*/
~DHCP();
/**
* \brief Adds a new option to this DHCP PDU.
*
@@ -391,11 +374,11 @@ namespace Tins {
uint32_t header_size() const;
/**
* \brief Clones this PDU.
*
* \sa PDU::clone_pdu
*/
PDU *clone_pdu() const;
PDU *clone_pdu() const {
return do_clone_pdu<DHCP>();
}
private:
static const uint32_t MAX_DHCP_SIZE;

View File

@@ -49,12 +49,7 @@ namespace Tins {
/**
* \brief Broadcast hardware address.
*/
static const uint8_t *BROADCAST;
/**
* \brief Dot11 address size.
*/
static const uint32_t ADDR_SIZE = 6;
static const address_type BROADCAST;
/**
* \brief Enum for the different types of 802.11 frames.
@@ -970,7 +965,7 @@ namespace Tins {
*
* \return The fourth address as a constant uint8_t pointer.
*/
const uint8_t* addr4() const { return this->_addr4; }
const address_type &addr4() const { return this->_addr4; }
/**
* \brief Setter for the second address.
@@ -1005,7 +1000,7 @@ namespace Tins {
*
* \param new_addr4 const uint8_t array of 6 bytes containing the new fourth address.
*/
void addr4(const uint8_t* new_addr4);
void addr4(const address_type &new_addr4);
/**
* \brief Returns the 802.11 frame's header length.
@@ -1271,11 +1266,12 @@ namespace Tins {
void copy_ext_header(const Dot11ManagementFrame *other);
uint32_t management_frame_size() { return sizeof(_ext_header) + (from_ds() && to_ds()) ? sizeof(_addr4) : 0; }
uint32_t management_frame_size() {
return sizeof(_ext_header) + (from_ds() && to_ds()) ? address_type::address_size : 0;
}
private:
ExtendedHeader _ext_header;
uint8_t _addr4[6];
address_type _addr4;
};
/**

View File

@@ -55,6 +55,15 @@ public:
convert(address, buffer);
}
template<size_t i>
HWAddress(const HWAddress<i> &rhs) {
std::copy(
rhs.begin(),
rhs.begin() + std::min(i, n),
begin()
);
}
HWAddress& operator=(const std::string &address) {
convert(address, buffer);
}

View File

@@ -126,13 +126,13 @@ namespace Tins {
* \brief Getter for this PDU's type flag identifier.
* \return The type flag identifier.
*/
inline uint32_t flag() const { return _flag; }
uint32_t flag() const { return _flag; }
/**
* \brief Getter for the inner PDU.
* \return The current inner PDU. Might be 0.
*/
inline PDU *inner_pdu() const { return _inner_pdu; }
PDU *inner_pdu() const { return _inner_pdu; }
/** \brief Sets the flag identifier.
*/