mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 13:04:28 +01:00
Added RawPDU class. Removed payload member from TCP and UDP. They're not represented by RawPDUs.
This commit is contained in:
54
include/rawpdu.h
Normal file
54
include/rawpdu.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* libtins is a net packet wrapper library for crafting and
|
||||
* interpreting sniffed packets.
|
||||
*
|
||||
* Copyright (C) 2011 Nasel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __RAWPDU_H
|
||||
#define __RAWPDU_H
|
||||
|
||||
|
||||
#include "pdu.h"
|
||||
|
||||
|
||||
namespace Tins {
|
||||
|
||||
/** \brief Represents a PDU which holds raw data.
|
||||
*
|
||||
* In order to send payloads over TCP, UDP, or other transport layer or
|
||||
* higher level protocols, RawPDU can be used as a wrapper for raw byte arrays.
|
||||
*/
|
||||
class RawPDU : public PDU {
|
||||
public:
|
||||
RawPDU(uint8_t *payload, uint32_t size);
|
||||
|
||||
/** \brief Returns the header size.
|
||||
*
|
||||
* This metod overrides PDU::header_size. \sa PDU::header_size
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
private:
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
uint8_t *_payload;
|
||||
uint32_t _payload_size;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -111,10 +111,6 @@ namespace Tins {
|
||||
*/
|
||||
inline uint16_t urg_ptr() const { return _tcp.urg_ptr; }
|
||||
|
||||
/** \brief Returns the payload.
|
||||
*/
|
||||
inline const uint8_t *payload() const { return _payload; }
|
||||
|
||||
/** \brief Set the destination port.
|
||||
* \param new_dport New destination port.
|
||||
*/
|
||||
@@ -153,7 +149,10 @@ namespace Tins {
|
||||
/** \brief Set the payload.
|
||||
*
|
||||
* Payload is NOT copied. Therefore, pointers provided as
|
||||
* payloads must be freed manually by the user.
|
||||
* payloads must be freed manually by the user. This actually
|
||||
* creates a RawPDU that holds the payload, and sets it as the
|
||||
* inner_pdu. Therefore, if an inner_pdu was set previously,
|
||||
* a call to TCP::payload will delete it.
|
||||
* \param new_payload New payload.
|
||||
* \param new_payload_size New payload's size
|
||||
*/
|
||||
@@ -247,8 +246,7 @@ namespace Tins {
|
||||
|
||||
tcphdr _tcp;
|
||||
std::vector<TCPOption> _options;
|
||||
uint8_t *_payload;
|
||||
uint32_t _payload_size, _options_size, _total_options_size;
|
||||
uint32_t _options_size, _total_options_size;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
* libtins is a net packet wrapper library for crafting and
|
||||
* interpreting sniffed packets.
|
||||
*
|
||||
* Copyright (C) 2011 Nasel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __UDP_H
|
||||
#define __UDP_H
|
||||
|
||||
@@ -22,11 +43,7 @@ namespace Tins {
|
||||
* */
|
||||
UDP(uint16_t sport = 0, uint16_t dport = 0);
|
||||
|
||||
|
||||
/** \brief Returns the payload.
|
||||
*/
|
||||
inline const uint8_t *payload() const { return _payload; }
|
||||
|
||||
|
||||
/** \brief Returns the destination port
|
||||
*/
|
||||
inline uint16_t dport() const { return _udp.dport; }
|
||||
@@ -50,7 +67,10 @@ namespace Tins {
|
||||
/** \brief Set the payload.
|
||||
*
|
||||
* Payload is NOT copied. Therefore, pointers provided as
|
||||
* payloads must be freed manually by the user.
|
||||
* payloads must be freed manually by the user. This actually
|
||||
* creates a RawPDU that holds the payload, and sets it as the
|
||||
* inner_pdu. Therefore, if an inner_pdu was set previously,
|
||||
* a call to UDP::payload will delete it.
|
||||
* \param new_payload New payload.
|
||||
* \param new_payload_size New payload's size
|
||||
*/
|
||||
@@ -74,8 +94,6 @@ namespace Tins {
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
udphdr _udp;
|
||||
uint8_t *_payload;
|
||||
uint32_t _payload_size;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user