diff --git a/include/sll.h b/include/sll.h index 4d6d391..6051ed6 100644 --- a/include/sll.h +++ b/include/sll.h @@ -70,40 +70,40 @@ public: // Getters /** - * \brief Getter for the packet_type field. - * \return The stored packet_type field value. + * \brief Getter for the Packet Type field. + * \return The stored Packet Type field value. */ uint16_t packet_type() const { return Endian::be_to_host(_header.packet_type); } /** - * \brief Getter for the lladdr_type field. - * \return The stored lladdr_type field value. + * \brief Getter for the LLADDR Type field. + * \return The stored LLADDR Type field value. */ uint16_t lladdr_type() const { return Endian::be_to_host(_header.lladdr_type); } /** - * \brief Getter for the lladdr_len field. - * \return The stored lladdr_len field value. + * \brief Getter for the LLADDR Length field. + * \return The stored LLADDR Length field value. */ uint16_t lladdr_len() const { return Endian::be_to_host(_header.lladdr_len); } /** - * \brief Getter for the address field. - * \return The stored address field value. + * \brief Getter for the Address field. + * \return The stored Address field value. */ address_type address() const { return _header.address; } /** - * \brief Getter for the protocol field. - * \return The stored protocol field value. + * \brief Getter for the Protocol field. + * \return The stored Protocol field value. */ uint16_t protocol() const { return Endian::be_to_host(_header.protocol); @@ -118,32 +118,32 @@ public: // Setters /** - * \brief Setter for the packet_type field. - * \param new_packet_type The new packet_type field value. + * \brief Setter for the Packet Type field. + * \param new_packet_type The new Packet Type field value. */ void packet_type(uint16_t new_packet_type); /** - * \brief Setter for the lladdr_type field. - * \param new_lladdr_type The new lladdr_type field value. + * \brief Setter for the LLADDR Type field. + * \param new_lladdr_type The new LLADDR Type field value. */ void lladdr_type(uint16_t new_lladdr_type); /** - * \brief Setter for the lladdr_len field. - * \param new_lladdr_len The new lladdr_len field value. + * \brief Setter for the LLADDR Length field. + * \param new_lladdr_len The new LLADDR Length field value. */ void lladdr_len(uint16_t new_lladdr_len); /** - * \brief Setter for the address field. - * \param new_address The new address field value. + * \brief Setter for the Address field. + * \param new_address The new Address field value. */ void address(const address_type &new_address); /** - * \brief Setter for the protocol field. - * \param new_protocol The new protocol field value. + * \brief Setter for the Protocol field. + * \param new_protocol The new Protocol field value. */ void protocol(uint16_t new_protocol); diff --git a/include/snap.h b/include/snap.h index 4f1fae0..b5d3764 100644 --- a/include/snap.h +++ b/include/snap.h @@ -76,40 +76,40 @@ namespace Tins { /* Setters */ /** - * \brief Setter for the control field. - * \param new_id The new control to be set. + * \brief Setter for the Control field. + * \param new_id The new Control to be set. */ void control(uint8_t new_control); /** - * \brief Setter for the org code field. - * \param new_org The new org code to be set. + * \brief Setter for the Organization Code field. + * \param new_org The new Organization Code to be set. */ void org_code(small_uint<24> new_org); /** - * \brief Setter for the eth type field. - * \param new_eth The new eth type to be set. + * \brief Setter for the Ethernet Type field. + * \param new_eth The new Ethernet Type to be set. */ void eth_type(uint16_t new_eth); /* Getters */ /** - * \brief Getter for the dsap field. - * \return The dsap field. + * \brief Getter for the DSAP field. + * \return The DSAP field. */ uint8_t dsap() const { return _snap.dsap; } /** - * \brief Getter for the ssap field. - * \return The ssap field. + * \brief Getter for the SSAP field. + * \return The SSAP field. */ uint8_t ssap() const { return _snap.ssap; } /** - * \brief Getter for the control field. - * \return The control field. + * \brief Getter for the Control field. + * \return The Control field. */ uint8_t control() const { #if TINS_IS_LITTLE_ENDIAN @@ -120,8 +120,8 @@ namespace Tins { } /** - * \brief Getter for the org code field. - * \return The org code field. + * \brief Getter for the Organization Code field. + * \return The Organization Code field. */ small_uint<24> org_code() const { #if TINS_IS_LITTLE_ENDIAN @@ -132,8 +132,8 @@ namespace Tins { } /** - * \brief Getter for the eth type field. - * \return The eth field. + * \brief Getter for the Ethernet Type field. + * \return The Ethernet Type field. */ uint16_t eth_type() const { return Endian::be_to_host(_snap.eth_type); } @@ -149,7 +149,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::SNAP; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Clones this PDU. diff --git a/include/sniffer.h b/include/sniffer.h index 99a70fe..9936a9e 100644 --- a/include/sniffer.h +++ b/include/sniffer.h @@ -76,7 +76,7 @@ namespace Tins { * This constructor is available only in C++11. */ BaseSniffer(BaseSniffer &&rhs) noexcept - : handle(nullptr), mask() + : handle(nullptr), mask(), prog() { *this = std::move(rhs); } @@ -90,6 +90,7 @@ namespace Tins { using std::swap; swap(handle, rhs.handle); swap(mask, rhs.mask); + swap(prog, rhs.prog); return *this; } #endif @@ -241,6 +242,7 @@ namespace Tins { pcap_t *handle; bpf_u_int32 mask; + bpf_program prog; }; /** diff --git a/include/stp.h b/include/stp.h index a313b7a..52bcf2a 100644 --- a/include/stp.h +++ b/include/stp.h @@ -80,94 +80,94 @@ public: // Getters /** - * \brief Getter for the proto_id field. - * \return The stored proto_id field value. + * \brief Getter for the Protocol ID field. + * \return The stored Protocol ID field value. */ uint16_t proto_id() const { return Endian::be_to_host(_header.proto_id); } /** - * \brief Getter for the proto_version field. - * \return The stored proto_version field value. + * \brief Getter for the Protocol Version field. + * \return The stored Protocol Version field value. */ uint8_t proto_version() const { return _header.proto_version; } /** - * \brief Getter for the bpdu_type field. - * \return The stored bpdu_type field value. + * \brief Getter for the BDU Type field. + * \return The stored BDU Type field value. */ uint8_t bpdu_type() const { return _header.bpdu_type; } /** - * \brief Getter for the bpdu_flags field. - * \return The stored bpdu_flags field value. + * \brief Getter for the BDU Flags field. + * \return The stored BDU Flags field value. */ uint8_t bpdu_flags() const { return _header.bpdu_flags; } /** - * \brief Getter for the root_path_cost field. - * \return The stored root_path_cost field value. + * \brief Getter for the Root Path Cost field. + * \return The stored Root Path Cost field value. */ uint32_t root_path_cost() const { return Endian::be_to_host(_header.root_path_cost); } /** - * \brief Getter for the port_id field. - * \return The stored port_id field value. + * \brief Getter for the Port ID field. + * \return The stored Port ID field value. */ uint16_t port_id() const { return Endian::be_to_host(_header.port_id); } /** - * \brief Getter for the msg_age field. - * \return The stored msg_age field value. + * \brief Getter for the Message Age field. + * \return The stored Message Age field value. */ uint16_t msg_age() const { return Endian::be_to_host(_header.msg_age) / 256; } /** - * \brief Getter for the max_age field. - * \return The stored max_age field value. + * \brief Getter for the Maximum Age field. + * \return The stored Maximum Age field value. */ uint16_t max_age() const { return Endian::be_to_host(_header.max_age) / 256; } /** - * \brief Getter for the hello_time field. - * \return The stored hello_time field value. + * \brief Getter for the Hello Time field. + * \return The stored Hello Time field value. */ uint16_t hello_time() const { return Endian::be_to_host(_header.hello_time) / 256; } /** - * \brief Getter for the fwd_delay field. - * \return The stored fwd_delay field value. + * \brief Getter for the Forward Delay field. + * \return The stored Forward Delay field value. */ uint16_t fwd_delay() const { return Endian::be_to_host(_header.fwd_delay) / 256; } /** - * \brief Getter for the root id field. - * \return The stored root id field value. + * \brief Getter for the Root ID field. + * \return The stored Root ID field value. */ bpdu_id_type root_id() const; /** - * \brief Getter for the bridge id field. - * \return The stored bridge id field value. + * \brief Getter for the Bridge ID field. + * \return The stored Bridge ID field value. */ bpdu_id_type bridge_id() const; @@ -194,74 +194,74 @@ public: // Setters /** - * \brief Setter for the proto_id field. - * \param new_proto_id The new proto_id field value. + * \brief Setter for the Protocol ID field. + * \param new_proto_id The new Protocol ID field value. */ void proto_id(uint16_t new_proto_id); /** - * \brief Setter for the proto_version field. - * \param new_proto_version The new proto_version field value. + * \brief Setter for the Protocol Version field. + * \param new_proto_version The new Protocol Version field value. */ void proto_version(uint8_t new_proto_version); /** - * \brief Setter for the bpdu_type field. - * \param new_bpdu_type The new bpdu_type field value. + * \brief Setter for the BPDU Type field. + * \param new_bpdu_type The new BPDU Type field value. */ void bpdu_type(uint8_t new_bpdu_type); /** - * \brief Setter for the bpdu_flags field. - * \param new_bpdu_flags The new bpdu_flags field value. + * \brief Setter for the BPDU Flags field. + * \param new_bpdu_flags The new BPDU Flags field value. */ void bpdu_flags(uint8_t new_bpdu_flags); /** - * \brief Setter for the root_path_cost field. - * \param new_root_path_cost The new root_path_cost field value. + * \brief Setter for the Root Path Cost field. + * \param new_root_path_cost The new Root Path Cost field value. */ void root_path_cost(uint32_t new_root_path_cost); /** - * \brief Setter for the port_id field. - * \param new_port_id The new port_id field value. + * \brief Setter for the Port ID field. + * \param new_port_id The new Port ID field value. */ void port_id(uint16_t new_port_id); /** - * \brief Setter for the msg_age field. - * \param new_msg_age The new msg_age field value. + * \brief Setter for the Message Age field. + * \param new_msg_age The new Message Age field value. */ void msg_age(uint16_t new_msg_age); /** - * \brief Setter for the max_age field. - * \param new_max_age The new max_age field value. + * \brief Setter for the Maximum Age field. + * \param new_max_age The new Maximum Age field value. */ void max_age(uint16_t new_max_age); /** - * \brief Setter for the hello_time field. - * \param new_hello_time The new hello_time field value. + * \brief Setter for the Hello Time field. + * \param new_hello_time The new Hello Time field value. */ void hello_time(uint16_t new_hello_time); /** - * \brief Setter for the fwd_delay field. - * \param new_fwd_delay The new fwd_delay field value. + * \brief Setter for the Forward Delay field. + * \param new_fwd_delay The new Forward Delay field value. */ void fwd_delay(uint16_t new_fwd_delay); /** - * \brief Setter for the root id field. - * \param new_fwd_delay The new root id field value. + * \brief Setter for the Root ID field. + * \param new_fwd_delay The new Root ID field value. */ void root_id(const bpdu_id_type &id); /** - * \brief Setter for the bridge id field. - * \param new_fwd_delay The new bridge id field value. + * \brief Setter for the Bridge ID field. + * \param new_fwd_delay The new Bridge ID field value. */ void bridge_id(const bpdu_id_type &id); private: diff --git a/include/udp.h b/include/udp.h index 27943ca..c059a3f 100644 --- a/include/udp.h +++ b/include/udp.h @@ -51,8 +51,8 @@ namespace Tins { /** * \brief UDP constructor. * - * Creates an instance of UDP. Destination and source port can - * be provided, otherwise both will be 0. + * Constructs an instance of UDP. The destination and source + * port can be provided, otherwise both of them will be 0. * * \param dport Destination port. * \param sport Source port. diff --git a/src/sniffer.cpp b/src/sniffer.cpp index c939f0b..445bf36 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -36,12 +36,14 @@ using std::runtime_error; namespace Tins { BaseSniffer::BaseSniffer() -: handle(0), mask(0) +: handle(0), mask(0), prog() { - + } BaseSniffer::~BaseSniffer() { + if(prog.bf_insns) + pcap_freecode(&prog); if(handle) pcap_close(handle); } @@ -112,11 +114,9 @@ BaseSniffer::iterator BaseSniffer::end() { } bool BaseSniffer::set_filter(const std::string &filter) { - bpf_program prog; if(pcap_compile(handle, &prog, filter.c_str(), 0, mask) == -1) return false; bool result = pcap_setfilter(handle, &prog) != -1; - pcap_freecode(&prog); return result; }