mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 04:54:28 +01:00
Added DHCP and BootP constructors from uint8_t buffer. Normalized IP destination and source address getters/setters.
This commit is contained in:
@@ -45,13 +45,24 @@ namespace Tins {
|
||||
BOOTREPLY = 2
|
||||
};
|
||||
|
||||
/** \brief Creates an instance of BootP.
|
||||
/**
|
||||
* \brief Creates an instance of BootP.
|
||||
*
|
||||
* This sets the size of the vend field to 64, as the BootP RFC
|
||||
* states.
|
||||
*/
|
||||
BootP();
|
||||
|
||||
/**
|
||||
* \brief Constructor which creates a BootP object from a buffer and adds all identifiable
|
||||
* PDUs found in the buffer as children of this one.
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
* \param vend_field_size The vend field size to allocate.
|
||||
* Subclasses might use 0 to provide their own interpretation of this field.
|
||||
*/
|
||||
BootP(const uint8_t *buffer, uint32_t total_sz, uint32_t vend_field_size = 64);
|
||||
|
||||
/** \brief BootP destructor.
|
||||
*
|
||||
* This frees the memory allocated to hold the vend field.
|
||||
|
||||
@@ -164,6 +164,15 @@ namespace Tins {
|
||||
*/
|
||||
DHCP();
|
||||
|
||||
/**
|
||||
* \brief Constructor which creates a DHCP object from a buffer and adds all identifiable
|
||||
* PDUs found in the buffer as children of this one.
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
* Subclasses might use 0 to provide their own interpretation of this field.
|
||||
*/
|
||||
DHCP(const uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
/**
|
||||
* \brief DHCP destructor
|
||||
*
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace Tins {
|
||||
* \return The cloned PDU.
|
||||
* \sa PDU::clone_packet
|
||||
*/
|
||||
PDU *clone_packet(uint8_t *ptr, uint32_t total_sz);
|
||||
PDU *clone_packet(const uint8_t *ptr, uint32_t total_sz);
|
||||
private:
|
||||
/**
|
||||
* Struct that represents the Ethernet II header
|
||||
@@ -190,7 +190,7 @@ namespace Tins {
|
||||
*
|
||||
* \param eth_ptr The pointer to the ethhdr.
|
||||
*/
|
||||
EthernetII(ethhdr *eth_ptr);
|
||||
EthernetII(const ethhdr *eth_ptr);
|
||||
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
|
||||
12
include/ip.h
12
include/ip.h
@@ -179,12 +179,12 @@ namespace Tins {
|
||||
*
|
||||
* \return The source address for this IP PDU.
|
||||
*/
|
||||
inline uint32_t source_address() const { return _ip.saddr; }
|
||||
inline uint32_t src_addr() 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; }
|
||||
inline uint32_t dst_addr() const { return _ip.daddr; }
|
||||
|
||||
/* Setters */
|
||||
|
||||
@@ -249,28 +249,28 @@ namespace Tins {
|
||||
*
|
||||
* \param ip The ip address in dotted string notation.
|
||||
*/
|
||||
void source_address(const std::string &ip);
|
||||
void src_addr(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);
|
||||
void src_addr(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);
|
||||
void dst_addr(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);
|
||||
void dst_addr(uint32_t ip);
|
||||
|
||||
/**
|
||||
* \brief Sets an IP option.
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Tins {
|
||||
* \return The captured packet, matching the given filter, 0 if an
|
||||
* error occured(probably compiling the filter).
|
||||
*/
|
||||
PDU *next_pdu(const std::string &filter);
|
||||
PDU *next_pdu(const std::string &filter = "");
|
||||
|
||||
/**
|
||||
* \brief Starts a sniffing loop, using a callback object for every
|
||||
@@ -88,11 +88,11 @@ namespace Tins {
|
||||
* Handlers could be user-provided classes which inherit AbstractSnifferHandler,
|
||||
* or it could be a specific SnifferHandler specialization. This method deletes
|
||||
* packets after they are handled, therefore the handlers MUST NOT delete them.
|
||||
* \param filter The filter to use when sniffing.
|
||||
* \param cback_handler The callback handler object which should process packets.
|
||||
* \param filter The filter to use when sniffing.
|
||||
* \param max_packets The maximum amount of packets to sniff. 0 == infinite.
|
||||
*/
|
||||
void sniff_loop(const std::string &filter, AbstractSnifferHandler *cback_handler, uint32_t max_packets = 0);
|
||||
void sniff_loop(AbstractSnifferHandler *cback_handler, const std::string &filter, uint32_t max_packets = 0);
|
||||
|
||||
/**
|
||||
* \brief Stops sniffing loops.
|
||||
@@ -105,6 +105,7 @@ namespace Tins {
|
||||
|
||||
pcap_t *handle;
|
||||
bpf_u_int32 ip, mask;
|
||||
bpf_program actual_filter;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,16 +53,26 @@ namespace Tins {
|
||||
*/
|
||||
UDP(const uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
/** \brief Returns the destination port
|
||||
*/
|
||||
/**
|
||||
* \brief Getter for the destination port.
|
||||
* \return The datagram's destination port.
|
||||
*/
|
||||
inline uint16_t dport() const { return _udp.dport; }
|
||||
|
||||
/** \brief Returns the source port
|
||||
*/
|
||||
/**
|
||||
* \brief Getter for the source port.
|
||||
* \return The datagram's source port.
|
||||
*/
|
||||
inline uint16_t sport() const { return _udp.sport; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the length of the datagram.
|
||||
* \return The length of the datagram.
|
||||
*/
|
||||
inline uint16_t length() const { return _udp.len; }
|
||||
|
||||
/** \brief Set the destination port.
|
||||
*
|
||||
/**
|
||||
* \brief Set the destination port.
|
||||
* \param new_dport The new destination port.
|
||||
*/
|
||||
void dport(uint16_t new_dport);
|
||||
|
||||
Reference in New Issue
Block a user