1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 12:44:25 +01:00

Solved conflicts.

This commit is contained in:
Matias F
2011-08-12 20:24:51 -03:00
7 changed files with 124 additions and 35 deletions

View File

@@ -164,12 +164,11 @@ namespace Tins {
static const uint8_t DEFAULT_TTL;
void init_ip_fields();
void write_serialization(uint8_t *buffer, uint32_t total_sz);
void write_serialization(uint8_t *buffer, uint32_t total_sz, PDU *parent);
iphdr _ip;
std::vector<IpOption> _ip_options;
uint32_t _options_size;
uint32_t _padded_options_size;
uint32_t _options_size, _padded_options_size;
};
};

View File

@@ -30,37 +30,95 @@ namespace Tins {
class PacketSender;
/** \brief PDU is the base class for protocol data units.
*
* Every PDU implementation must inherit this one. PDUs can be serialized,
* therefore allowing a PacketSender to send them through sockets. PDUs
* are created upwards: upper layers will be children of the lower ones.
* Each PDU must provide its flag identifier. This will be most likely added
* to its parent's data, hence it should be a valid identifier. For example,
* IP should provide IPPROTO_IP.
*/
class PDU {
public:
/** \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.
*/
PDU(uint32_t flag, PDU *next_pdu = 0);
virtual ~PDU();
/* This PDU's header size only. */
/** \brief The header's size
*/
virtual uint32_t header_size() const = 0;
/* This PDU's trailer size only. Defaults to 0. */
/** \brief Trailer's size.
*
* Some protocols require a trailer(like Ethernet). This defaults to 0.
*/
virtual uint32_t trailer_size() const { return 0; }
/* The size of the whole chain of PDUs, including this one. */
inline uint32_t size() const;
/** \brief The whole chain of PDU's size, including this one.
*
* Returns the sum of this and all children PDUs' size.
*/
uint32_t size() const;
/** \brief This PDU's type flag identifier.
*
*/
inline uint32_t flag() const { return _flag; }
/** \brief The child PDU.
*/
inline const PDU *inner_pdu() const { return _inner_pdu; }
/** \brief Sets the flag identifier.
*/
void flag(uint32_t new_flag);
/* When setting a new inner_pdu, the instance takes
* ownership of the object, therefore deleting it when
* it's no longer required. */
/** \brief Sets the child PDU.
*
* \param next_pdu The new child PDU.
* When setting a new inner_pdu, the instance takesownership of
* the object, therefore deleting it when it's no longer required.
*/
void inner_pdu(PDU *next_pdu);
/* Serializes the whole chain of PDU's, including this one. */
/** \brief Serializes the whole chain of PDU's, including this one.
*
* \param sz The size of the buffer must be returned through this parameter.
* The buffer returned must be deleted by the user using
* operator delete[].
*/
uint8_t *serialize(uint32_t &sz);
/* */
virtual bool send(PacketSender* sender) {return false;}
/** \brief Send the stack of PDUs through a PacketSender.
*
* This method will be called only for the PDU on the bottom of the stack,
* therefore it should only implement this method if it can be sent.
* PacketSender implements specific methods to send packets which start
* on every valid TCP/IP stack layer; this should only be a proxy for
* those methods.
* \param sender The PacketSender which will send the packet.
*/
virtual bool send(PacketSender* sender) { return false; }
protected:
/* Serialize this PDU storing the result in buffer. */
void serialize(uint8_t *buffer, uint32_t total_sz);
void serialize(uint8_t *buffer, uint32_t total_sz, PDU *parent);
/* Each PDU's own implementation of serialization. */
virtual void write_serialization(uint8_t *buffer, uint32_t total_sz) = 0;
/** \brief Serialices this TCP PDU.
*
* Each PDU must override this method and implement it's own
* serialization.
* \param buffer The buffer in which the PDU will be serialized.
* \param total_sz The size available in the buffer.
* \param parent The PDU that's one level below this one on the stack. Might be 0.
*/
virtual void write_serialization(uint8_t *buffer, uint32_t total_sz, PDU *parent) = 0;
private:
uint32_t _flag;
PDU *_inner_pdu;

View File

@@ -186,12 +186,6 @@ namespace Tins {
* payload and options size.
*/
uint32_t header_size() const;
/** \brief Serialices this TCP PDU.
* \param buffer The buffer in which the PDU will be serialized.
* \param total_sz The size available in the buffer.
*/
void write_serialization(uint8_t *buffer, uint32_t total_sz);
private:
struct tcphdr {
uint16_t sport;
@@ -240,7 +234,15 @@ namespace Tins {
static const uint16_t DEFAULT_WINDOW;
uint16_t do_checksum(uint8_t *start, uint8_t *end) const;
/** \brief Serialices this TCP PDU.
* \param buffer The buffer in which the PDU will be serialized.
* \param total_sz The size available in the buffer.
* \param parent The PDU that's one level below this one on the stack.
*/
void write_serialization(uint8_t *buffer, uint32_t total_sz, PDU *parent);
uint32_t do_checksum(uint8_t *start, uint8_t *end) const;
uint32_t pseudoheader_checksum(uint32_t source_ip, uint32_t dest_ip) const;
tcphdr _tcp;
std::vector<TCPOption> _options;