mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 13:34:27 +01:00
UDP PDU is now working.
This commit is contained in:
@@ -164,7 +164,7 @@ namespace Tins {
|
||||
static const uint8_t DEFAULT_TTL;
|
||||
|
||||
void init_ip_fields();
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, PDU *parent);
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
iphdr _ip;
|
||||
std::vector<IpOption> _ip_options;
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Tins {
|
||||
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, PDU *parent);
|
||||
void serialize(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
/** \brief Serialices this TCP PDU.
|
||||
*
|
||||
@@ -118,7 +118,10 @@ namespace Tins {
|
||||
* \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;
|
||||
virtual void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) = 0;
|
||||
|
||||
static uint32_t do_checksum(uint8_t *start, uint8_t *end);
|
||||
static uint32_t pseudoheader_checksum(uint32_t source_ip, uint32_t dest_ip, uint32_t len, uint32_t flag);
|
||||
private:
|
||||
uint32_t _flag;
|
||||
PDU *_inner_pdu;
|
||||
|
||||
@@ -111,6 +111,10 @@ 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.
|
||||
*/
|
||||
@@ -183,7 +187,7 @@ namespace Tins {
|
||||
/** \brief Returns the header size.
|
||||
*
|
||||
* This metod overrides PDU::header_size. This size includes the
|
||||
* payload and options size.
|
||||
* payload and options size. \sa PDU::header_size
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
private:
|
||||
@@ -239,10 +243,7 @@ namespace Tins {
|
||||
* \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;
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
tcphdr _tcp;
|
||||
std::vector<TCPOption> _options;
|
||||
|
||||
@@ -22,6 +22,31 @@ 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; }
|
||||
|
||||
/** \brief Returns the source port
|
||||
*/
|
||||
inline uint16_t sport() const { return _udp.sport; }
|
||||
|
||||
/** \brief Set the destination port.
|
||||
*
|
||||
* \param new_dport The new destination port.
|
||||
*/
|
||||
void dport(uint16_t new_dport);
|
||||
|
||||
/** \brief Set the source port.
|
||||
*
|
||||
* \param new_sport The new source port.
|
||||
*/
|
||||
void sport(uint16_t new_sport);
|
||||
|
||||
/** \brief Set the payload.
|
||||
*
|
||||
* Payload is NOT copied. Therefore, pointers provided as
|
||||
@@ -30,6 +55,14 @@ namespace Tins {
|
||||
* \param new_payload_size New payload's size
|
||||
*/
|
||||
void payload(uint8_t *new_payload, uint32_t new_payload_size);
|
||||
|
||||
/* Virtual methods */
|
||||
/** \brief Returns the header size.
|
||||
*
|
||||
* This metod overrides PDU::header_size. This size includes the
|
||||
* payload and options size. \sa PDU::header_size
|
||||
*/
|
||||
uint32_t header_size() const;
|
||||
private:
|
||||
struct udphdr {
|
||||
uint16_t sport;
|
||||
@@ -38,8 +71,11 @@ namespace Tins {
|
||||
uint16_t check;
|
||||
} __attribute__((packed));
|
||||
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
udphdr _udp;
|
||||
uint8_t *payload;
|
||||
uint8_t *_payload;
|
||||
uint32_t _payload_size;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user