1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-26 03:51:35 +01:00

Documented all functions in header files.

This commit is contained in:
Matias Fontanini
2011-08-16 23:10:22 -03:00
parent 3feb2fdeae
commit 0d2b6a507b
7 changed files with 182 additions and 8 deletions

View File

@@ -36,8 +36,7 @@ namespace Tins {
public:
/**
*
/** \brief Represents the ethernetII broadcast address.
*/
static const uint8_t* BROADCAST;

View File

@@ -63,9 +63,9 @@ namespace Tins {
/** \brief Sets the type field.
*
* \param new_code The type which will be stored in the ICMP struct.
* \param type The type which will be stored in the ICMP struct.
*/
void type(uint8_t type);
void type(Flags type);
/** \brief Sets echo request flag for this PDU.
*
@@ -142,11 +142,15 @@ namespace Tins {
*/
void set_redirect(uint8_t icode, uint32_t address);
/** \brief Returns the ICMP type flag.
/** \brief Getter for the ICMP type flag.
*
* \return The type flag for this ICMP PDU.
*/
Flags type() const { return (Flags)_icmp.type; }
/** \brief Returns the ICMP code flag.
/** \brief Getter for the ICMP code flag.
*
* \return The code flag for this ICMP PDU.
*/
uint8_t code() const { return _icmp.code; }
@@ -167,6 +171,12 @@ namespace Tins {
*/
uint32_t header_size() const;
/** \brief Check wether ptr points to a valid response for this PDU.
*
* \sa PDU::matches_response
* \param ptr The pointer to the buffer.
* \param total_sz The size of the buffer.
*/
bool matches_response(uint8_t *ptr, uint32_t total_sz);
/**
@@ -175,6 +185,14 @@ namespace Tins {
*/
PDUType pdu_type() const { return PDU::ICMP; }
/** \brief Clones this pdu, filling the corresponding header with data
* extracted from a buffer.
*
* \param ptr The pointer to the from from which the data will be extracted.
* \param total_sz The size of the buffer.
* \return The cloned PDU.
* \sa PDU::clone_packet
*/
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
private:
static uint16_t global_id, global_seq;

View File

@@ -76,7 +76,7 @@ namespace Tins {
};
/**
* \brief Constructor for building the IP PDU taking strings.
* \brief Constructor for building the IP PDU taking strings as ip addresses.
*
* Constructor that builds an IP using strings as addresses. They
* can be hostnames or IPs.
@@ -86,42 +86,174 @@ namespace Tins {
* \param child pointer to a PDU which will be set as the inner_pdu for the packet being constructed(optional).
*/
IP(const std::string &ip_dst = "", const std::string &ip_src = "", PDU *child = 0);
/**
* \brief Constructor for building the IP PDU taking integer as ip addresses.
*
* Constructor that builds an IP using strings as addresses. They
* can be hostnames or IPs.
*
* \param ip_dst The destination ip address(optional).
* \param ip_src The source ip address(optional).
* \param child pointer to a PDU which will be set as the inner_pdu for the packet being constructed(optional).
*/
IP(uint32_t ip_dst = 0, uint32_t ip_src = 0, PDU *child = 0);
/* Getters */
/** \brief Getter for the type of service field.
*
* \return The this IP PDU's type of service.
*/
inline uint8_t tos() const { return _ip.tos; }
/** \brief Getter for the total length field.
* \return The total length of this IP PDU.
*/
inline uint16_t tot_len() const { return _ip.tot_len; }
/** \brief Getter for the id field.
* \return The id for this IP PDU.
*/
inline uint16_t id() const { return _ip.id; }
/** \brief Getter for the fragment offset field.
* \return The fragment offset for this IP PDU.
*/
inline uint16_t frag_off() const { return _ip.frag_off; }
/** \brief Getter for the time to live field.
* \return The time to live for this IP PDU.
*/
inline uint8_t ttl() const { return _ip.ttl; }
/** \brief Getter for the protocol field.
* \return The protocol for this IP PDU.
*/
inline uint8_t protocol() const { return _ip.protocol; }
/** \brief Getter for the checksum field.
* \return The checksum for this IP PDU.
*/
inline uint16_t check() const { return _ip.check; }
/** \brief Getter for the source address field.
* \return The source address for this IP PDU.
*/
inline uint32_t source_address() const { return _ip.saddr; }
/** \brief Getter for the destination address field.
* \return The destination address for this IP PDU.
*/
inline uint32_t dest_address() const { return _ip.daddr; }
/* Setters */
/** \brief Setter for the type of service field.
* \param new_tos The new type of service.
*/
void tos(uint8_t new_tos);
/** \brief Setter for the total length field.
* \param new_tot_len The new total length.
*/
void tot_len(uint16_t new_tot_len);
/** \brief Setter for the id field.
* \param new_id The new id.
*/
void id(uint16_t new_id);
/** \brief Setter for the fragment offset field.
* \param new_frag_off The new fragment offset.
*/
void frag_off(uint16_t new_frag_off);
/** \brief Setter for the time to live field.
* \param new_ttl The new time to live.
*/
void ttl(uint8_t new_ttl);
/** \brief Setter for the protocol field.
* \param new_protocol The new protocol.
*/
void protocol(uint8_t new_protocol);
/** \brief Setter for the checksum field.
* \param new_check The new checksum.
*/
void check(uint16_t new_check);
/** \brief Setter for the source address field.
* \param ip The ip address in dotted string notation.
*/
void source_address(const std::string &ip);
/** \brief Setter for the source address field.
* \param ip The ip address in integer notation.
*/
void source_address(uint32_t ip);
/** \brief Setter for the destination address field.
* \param ip The ip address in dotted string notation.
*/
void dest_address(const std::string &ip);
/** \brief Setter for the destination address field.
* \param ip The ip address in integer notation.
*/
void dest_address(uint32_t ip);
/** \brief Sets an IP option.
* \param copied The copied flag for this option.
* \param op_class The option class to be set.
* \param number The options number to be set.
* \param data The data of this options.
* \param data_size The data size.
*/
void set_option(uint8_t copied, OptionClass op_class, OptionNumber number, uint8_t* data = 0, uint32_t data_size = 0);
/** \brief Sets the End of List option.
*/
void set_option_eol();
/** \brief Sets the NOP option.
*/
void set_option_noop();
/** \brief Sets the security option.
* \param data The data for this option
* \param data_len The length of the data.
*/
void set_option_sec(uint8_t* data, uint32_t data_len);
/* Add more option setters */
/* Virtual methods */
/** \brief Returns the header size.
*
* This metod overrides PDU::header_size. \sa PDU::header_size
*/
uint32_t header_size() const;
/**
* \sa PDU::send()
*/
bool send(PacketSender* sender);
/** \brief Check wether ptr points to a valid response for this PDU.
*
* \sa PDU::matches_response
* \param ptr The pointer to the buffer.
* \param total_sz The size of the buffer.
*/
bool matches_response(uint8_t *ptr, uint32_t total_sz);
/** \brief Receives a matching response for this packet.
*
* \sa PDU::recv_response
* \param sender The packet sender which will receive the packet.
*/
PDU *recv_response(PacketSender *sender);
/**
@@ -130,6 +262,14 @@ namespace Tins {
*/
PDUType pdu_type() const { return PDU::IP; }
/** \brief Clones this pdu, filling the corresponding header with data
* extracted from a buffer.
*
* \param ptr The pointer to the from from which the data will be extracted.
* \param total_sz The size of the buffer.
* \return The cloned PDU.
* \sa PDU::clone_packet
*/
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
private:
static const uint8_t DEFAULT_TTL;

View File

@@ -44,6 +44,8 @@ namespace Tins {
*/
class PacketSender {
public:
/** \brief The default timeout for receive actions.
*/
static const uint32_t DEFAULT_TIMEOUT;
/** \brief Flags to indicate the socket type.
@@ -63,6 +65,10 @@ namespace Tins {
*/
PacketSender(uint32_t recv_timeout = DEFAULT_TIMEOUT);
/** \brief PacketSender destructor.
*
* This gracefully closes all open sockets.
*/
~PacketSender();
/** \brief Opens a layer y socket.

View File

@@ -26,6 +26,8 @@
#include <stdint.h>
#include "packetsender.h"
/** \brief The Tins namespace.
*/
namespace Tins {
class PacketSender;
@@ -64,6 +66,12 @@ namespace Tins {
* \param next_pdu The child PDU. Can be obviated.
*/
PDU(uint32_t flag, PDU *next_pdu = 0);
/** \brief PDU destructor.
*
* Deletes the inner pdu, as a consequence every child pdu is
* deleted.
*/
virtual ~PDU();
/** \brief The header's size

View File

@@ -56,7 +56,7 @@ void Tins::ICMP::code(uint8_t new_code) {
_icmp.code = new_code;
}
void Tins::ICMP::type(uint8_t new_type) {
void Tins::ICMP::type(Flags new_type) {
_icmp.type = new_type;
}

View File

@@ -37,6 +37,7 @@
using namespace std;
/** \cond */
struct InterfaceCollector {
set<string> ifaces;
@@ -75,6 +76,8 @@ struct HWAddressCollector {
}
};
/** \endcond */
uint32_t Tins::Utils::ip_to_int(const string &ip) {
uint32_t result(0), i(0), end, bytes_found(0);
while(i < ip.size() && bytes_found < 4) {