mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Fixed some bugs.
This commit is contained in:
@@ -52,7 +52,7 @@ namespace Tins {
|
||||
/**
|
||||
* \brief Creates an instance of ICMP.
|
||||
*
|
||||
* If no flag is specified, then ECHO_REPLY will be used.
|
||||
* If no flag is specified, then ECHO_REQUEST will be used.
|
||||
* \param flag The type flag which will be set.
|
||||
*/
|
||||
ICMP(Flags flag = ECHO_REQUEST);
|
||||
@@ -112,6 +112,13 @@ namespace Tins {
|
||||
* \param new_mtu uint16_t with the new sequence.
|
||||
*/
|
||||
void mtu(uint16_t new_mtu);
|
||||
|
||||
/**
|
||||
* \brief Setter for the pointer field.
|
||||
*
|
||||
* \param new_pointer uint8_t with the new pointer.
|
||||
*/
|
||||
void pointer(uint8_t new_pointer);
|
||||
|
||||
/**
|
||||
* \brief Sets echo request flag for this PDU.
|
||||
@@ -242,6 +249,13 @@ namespace Tins {
|
||||
uint32_t gateway() const { return Utils::net_to_host_l(this->_icmp.un.gateway); }
|
||||
|
||||
/**
|
||||
* \brief Getter for the pointer field.
|
||||
*
|
||||
* \return Returns the pointer value.
|
||||
*/
|
||||
uint8_t pointer() const { return this->_icmp.un.pointer; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the mtu field.
|
||||
*
|
||||
* \return Returns the mtu value in an uint16_t.
|
||||
@@ -306,6 +320,7 @@ namespace Tins {
|
||||
uint16_t __unused;
|
||||
uint16_t mtu;
|
||||
} frag;
|
||||
uint8_t pointer;
|
||||
} un;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
@@ -25,18 +25,22 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "pdu.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
/**
|
||||
* \brief Class representing a SNAP frame.
|
||||
*
|
||||
* Note that this PDU contains the 802.3 LLC structure + SNAP frame.
|
||||
* So far only unnumbered information structure is supported.
|
||||
*/
|
||||
class SNAP : public PDU {
|
||||
public:
|
||||
/**
|
||||
* \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);
|
||||
@@ -59,6 +63,70 @@ namespace Tins {
|
||||
*/
|
||||
SNAP &operator= (const SNAP &other);
|
||||
|
||||
/* Setters */
|
||||
|
||||
/**
|
||||
* \brief Setter for the id field.
|
||||
* \param new_id The new id to be set.
|
||||
*/
|
||||
void id(uint8_t new_id);
|
||||
|
||||
/**
|
||||
* \brief Setter for the poll field.
|
||||
* \param new_poll The new poll to be set.
|
||||
*/
|
||||
void poll(uint8_t new_poll);
|
||||
|
||||
/**
|
||||
* \brief Setter for the org code field.
|
||||
* \param new_org The new org code to be set.
|
||||
*/
|
||||
void org_code(uint32_t new_org);
|
||||
|
||||
/**
|
||||
* \brief Setter for the eth type field.
|
||||
* \param new_eth The new eth type to be set.
|
||||
*/
|
||||
void eth_type(uint32_t new_eth);
|
||||
|
||||
/* Getters */
|
||||
|
||||
/**
|
||||
* \brief Getter for the dsap field.
|
||||
* \return The dsap field.
|
||||
*/
|
||||
inline uint8_t dsap() const { return _snap.dsap; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the ssap field.
|
||||
* \return The ssap field.
|
||||
*/
|
||||
inline uint8_t ssap() const { return _snap.ssap; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the id field.
|
||||
* \return The id field.
|
||||
*/
|
||||
inline uint8_t id() const { return _snap.id; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the poll field.
|
||||
* \return The poll field.
|
||||
*/
|
||||
inline uint8_t poll() const { return _snap.poll; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the org code field.
|
||||
* \return The org code field.
|
||||
*/
|
||||
inline uint32_t org_code() const { return _snap.org_code; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the eth type field.
|
||||
* \return The eth field.
|
||||
*/
|
||||
inline uint16_t eth_type() const { return Utils::net_to_host_s(_snap.eth_type); }
|
||||
|
||||
/**
|
||||
* \brief Returns the SNAP frame's header length.
|
||||
*
|
||||
|
||||
56
src/icmp.cpp
56
src/icmp.cpp
@@ -66,23 +66,27 @@ void Tins::ICMP::type(Flags new_type) {
|
||||
}
|
||||
|
||||
void Tins::ICMP::check(uint16_t new_check) {
|
||||
this->_icmp.check = Utils::net_to_host_s(new_check);
|
||||
_icmp.check = Utils::net_to_host_s(new_check);
|
||||
}
|
||||
|
||||
void Tins::ICMP::id(uint16_t new_id) {
|
||||
this->_icmp.un.echo.id = Utils::net_to_host_s(new_id);
|
||||
_icmp.un.echo.id = Utils::net_to_host_s(new_id);
|
||||
}
|
||||
|
||||
void Tins::ICMP::sequence(uint16_t new_seq) {
|
||||
this->_icmp.un.echo.id = Utils::net_to_host_s(new_seq);
|
||||
_icmp.un.echo.sequence = Utils::net_to_host_s(new_seq);
|
||||
}
|
||||
|
||||
void Tins::ICMP::gateway(uint32_t new_gw) {
|
||||
this->_icmp.un.gateway = Utils::net_to_host_l(new_gw);
|
||||
_icmp.un.gateway = Utils::net_to_host_l(new_gw);
|
||||
}
|
||||
|
||||
void Tins::ICMP::mtu(uint16_t new_mtu) {
|
||||
this->_icmp.un.frag.mtu = Utils::net_to_host_s(new_mtu);
|
||||
_icmp.un.frag.mtu = Utils::net_to_host_s(new_mtu);
|
||||
}
|
||||
|
||||
void Tins::ICMP::pointer(uint8_t new_pointer) {
|
||||
_icmp.un.pointer = new_pointer;
|
||||
}
|
||||
|
||||
uint32_t Tins::ICMP::header_size() const {
|
||||
@@ -90,9 +94,9 @@ uint32_t Tins::ICMP::header_size() const {
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_echo_request(uint16_t id, uint16_t seq) {
|
||||
this->type(ECHO_REQUEST);
|
||||
type(ECHO_REQUEST);
|
||||
this->id(id);
|
||||
this->sequence(seq);
|
||||
sequence(seq);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_echo_request() {
|
||||
@@ -104,9 +108,9 @@ void Tins::ICMP::set_echo_request() {
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_echo_reply(uint16_t id, uint16_t seq) {
|
||||
this->type(ECHO_REPLY);
|
||||
type(ECHO_REPLY);
|
||||
this->id(id);
|
||||
this->sequence(seq);
|
||||
sequence(seq);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_echo_reply() {
|
||||
@@ -118,46 +122,46 @@ void Tins::ICMP::set_echo_reply() {
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_info_request(uint16_t id, uint16_t seq) {
|
||||
this->type(INFO_REQUEST);
|
||||
this->code(0);
|
||||
type(INFO_REQUEST);
|
||||
code(0);
|
||||
this->id(id);
|
||||
this->sequence(seq);
|
||||
sequence(seq);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_info_reply(uint16_t id, uint16_t seq) {
|
||||
this->type(INFO_REPLY);
|
||||
this->code(0);
|
||||
type(INFO_REPLY);
|
||||
code(0);
|
||||
this->id(id);
|
||||
this->sequence(seq);
|
||||
sequence(seq);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_dest_unreachable() {
|
||||
this->type(DEST_UNREACHABLE);
|
||||
type(DEST_UNREACHABLE);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_time_exceeded(bool ttl_exceeded) {
|
||||
this->type(TIME_EXCEEDED);
|
||||
this->code((ttl_exceeded) ? 0 : 1);
|
||||
type(TIME_EXCEEDED);
|
||||
code((ttl_exceeded) ? 0 : 1);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_param_problem(bool set_pointer, uint8_t bad_octet) {
|
||||
this->type(PARAM_PROBLEM);
|
||||
type(PARAM_PROBLEM);
|
||||
if(set_pointer) {
|
||||
this->code(0);
|
||||
this->id(bad_octet);
|
||||
code(0);
|
||||
pointer(bad_octet);
|
||||
}
|
||||
else
|
||||
this->code(1);
|
||||
code(1);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_source_quench() {
|
||||
this->type(SOURCE_QUENCH);
|
||||
type(SOURCE_QUENCH);
|
||||
}
|
||||
|
||||
void Tins::ICMP::set_redirect(uint8_t icode, uint32_t address) {
|
||||
this->type(REDIRECT);
|
||||
this->code(icode);
|
||||
this->gateway(address);
|
||||
type(REDIRECT);
|
||||
code(icode);
|
||||
gateway(address);
|
||||
}
|
||||
|
||||
void Tins::ICMP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
|
||||
|
||||
17
src/snap.cpp
17
src/snap.cpp
@@ -27,7 +27,6 @@
|
||||
#endif
|
||||
#include "snap.h"
|
||||
#include "constants.h"
|
||||
#include "utils.h"
|
||||
#include "arp.h"
|
||||
#include "ip.h"
|
||||
#include "eapol.h"
|
||||
@@ -68,6 +67,22 @@ Tins::SNAP &Tins::SNAP::operator= (const SNAP &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Tins::SNAP::id(uint8_t new_id) {
|
||||
_snap.id = new_id;
|
||||
}
|
||||
|
||||
void Tins::SNAP::poll(uint8_t new_poll) {
|
||||
_snap.poll = new_poll;
|
||||
}
|
||||
|
||||
void Tins::SNAP::org_code(uint32_t new_org) {
|
||||
_snap.org_code = new_org;
|
||||
}
|
||||
|
||||
void Tins::SNAP::eth_type(uint32_t new_eth) {
|
||||
_snap.eth_type = Utils::net_to_host_s(new_eth);
|
||||
}
|
||||
|
||||
uint32_t Tins::SNAP::header_size() const {
|
||||
return sizeof(_snap);
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ TEST_F(ARPTest, Serialize) {
|
||||
ASSERT_EQ(size, size2);
|
||||
EXPECT_TRUE(memcmp(buffer, buffer2, size) == 0);
|
||||
delete[] buffer;
|
||||
delete[] buffer2;
|
||||
}
|
||||
|
||||
TEST_F(ARPTest, ClonePDU) {
|
||||
@@ -182,4 +183,6 @@ TEST_F(ARPTest, ConstructorFromBuffer) {
|
||||
EXPECT_EQ(arp1.target_ip_addr(), arp2.target_ip_addr());
|
||||
EXPECT_TRUE(memcmp(arp1.sender_hw_addr(), arp2.sender_hw_addr(), arp2.hw_addr_length()) == 0);
|
||||
EXPECT_TRUE(memcmp(arp1.target_hw_addr(), arp2.target_hw_addr(), arp2.hw_addr_length()) == 0);
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ TEST_F(UDPTest, Serialize) {
|
||||
ASSERT_EQ(size, size2);
|
||||
EXPECT_TRUE(memcmp(buffer, buffer2, size) == 0);
|
||||
delete[] buffer;
|
||||
delete[] buffer2;
|
||||
}
|
||||
|
||||
TEST_F(UDPTest, ConstructorFromBuffer) {
|
||||
@@ -127,6 +128,10 @@ TEST_F(UDPTest, ConstructorFromBuffer) {
|
||||
uint8_t *buffer = udp1.serialize(size);
|
||||
|
||||
EXPECT_EQ(size, sizeof(expected_packet));
|
||||
EXPECT_EQ(udp1.dport(), 0x47f1);
|
||||
EXPECT_EQ(udp1.sport(), 0xf51a);
|
||||
EXPECT_EQ(udp1.length(), 0x453);
|
||||
|
||||
UDP udp2(buffer, size);
|
||||
EXPECT_EQ(udp1.dport(), udp2.dport());
|
||||
EXPECT_EQ(udp1.sport(), udp2.sport());
|
||||
|
||||
Reference in New Issue
Block a user