Skip to content

Commit

Permalink
Added malformed_packet exception. Every class except Dot11* use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfontanini committed Apr 18, 2013
1 parent 923f51a commit 3fd1b3d
Show file tree
Hide file tree
Showing 53 changed files with 267 additions and 159 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ libtins_include_HEADERS = include/internals.h \
include/constants.h \
include/utils.h \
include/cxxstd.h \
include/stp.h
include/stp.h \
include/exceptions.h
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ subdir = .
DIST_COMMON = README $(am__configure_deps) $(libtins_include_HEADERS) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/libtins.pc.in $(top_srcdir)/configure AUTHORS THANKS \
config.guess config.sub depcomp install-sh ltmain.sh missing
TODO config.guess config.sub depcomp install-sh ltmain.sh \
missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
Expand Down
10 changes: 8 additions & 2 deletions include/arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ namespace Tins {
const hwaddress_type &sender_hw = hwaddress_type());

/**
* \brief Constructor which creates an ARP object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \brief Constructs an ARP object from a buffer.
*
* If there is not enough size for an ARP header in the buffer,
* a malformed_packet exception is thrown.
*
* If the buffer is bigger than the size of the ARP header,
* then the extra data is stored in a RawPDU.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
7 changes: 5 additions & 2 deletions include/bootp.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ namespace Tins {
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.
* \brief Constructs a BootP object from a buffer .
*
* If there's not enough size for a BootP header, then a
* malformed_packet exception is thrown.
*
* \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.
Expand Down
8 changes: 6 additions & 2 deletions include/dhcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ 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.
* \brief Constructs a DHCP object from a buffer.
*
* If there is not enough size for a BootP header, or any of
* the TLV options contain an invalid size field, then a
* malformed_packet exception is thrown.
*
* \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.
Expand Down
9 changes: 6 additions & 3 deletions include/dhcpv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,12 @@ class DHCPv6 : public PDU {
DHCPv6();

/**
* \brief Constructor which constructs a DHCPv6 object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
* \brief Constructs a DHCPv6 object from a buffer.
*
* If there is not enough size for the DHCPv6 header, or any
* of the TLV options contains an invalid size field, a
* malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
6 changes: 5 additions & 1 deletion include/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ namespace Tins {
DNS();

/**
* \brief Constructor which creates a DNS object from a buffer.
* \brief Constructs a DNS object from a buffer.
*
* If there's not enough size for the DNS header, or any of the
* records are malformed, a malformed_packet is be thrown.
*
* \param buffer The buffer from which this PDU will be
* constructed.
* \param total_sz The total size of the buffer.
Expand Down
4 changes: 4 additions & 0 deletions include/dns_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class DNSResourceRecord {

/**
* \brief Constructs a record.
*
* If the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer A pointer to the start of the data buffer.
* \param len The length of the data.
*/
Expand Down
11 changes: 8 additions & 3 deletions include/dot1q.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ class Dot1Q : public PDU {
Dot1Q(small_uint<12> tag_id = 0, bool append_pad = true);

/**
* \brief Constructor which creates an Dot1Q object from a buffer and
* adds all identifiable PDUs found in the buffer as children of this
* one.
* \brief Constructs a Dot1Q object from a buffer and adds all
* identifiable PDUs found in the buffer as children of this
* one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for a Dot1Q header in the buffer,
* a malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
Expand Down
8 changes: 6 additions & 2 deletions include/dot3.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ namespace Tins {
PDU* child = 0);

/**
* \brief Constructor which creates an Dot3 object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \brief Constructs a Dot3 object from a buffer and adds a
* LLC object with the remaining data as the inner PDU.
*
* If there is not enough size for a Dot3 header, a
* malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
20 changes: 17 additions & 3 deletions include/eapol.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ namespace Tins {
/**
* \brief Static method to instantiate the correct EAPOL subclass
* based on a raw buffer.
*
* If no valid EAPOL type is detected, a null pointer is returned.
*
* \sa RC4EAPOL
* \sa RSNEAPOL
*
* \param buffer The buffer from which the data will be taken.
* \param total_sz The total size of the buffer.
*/
Expand Down Expand Up @@ -197,12 +203,16 @@ namespace Tins {
static const size_t key_sign_size = 16;

/**
* \brief Creates an instance of RC4EAPOL
* \brief Default constructor.
*/
RC4EAPOL();

/**
* \brief Constructor which creates an RC4EAPOL object from a buffer.
* \brief Constructs a RC4EAPOL object from a buffer.
*
* If there is not enough size for a RC4EAPOL header in the
* buffer, a malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down Expand Up @@ -396,7 +406,11 @@ namespace Tins {
RSNEAPOL();

/**
* \brief Constructor which creates an RSNEAPOL object from a buffer.
* \brief Constructs a RSNEAPOL object from a buffer.
*
* If there is not enough size for the RSNEAPOL header, a
* malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
10 changes: 8 additions & 2 deletions include/ethernetII.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ namespace Tins {
PDU* child = 0);

/**
* \brief Constructor which creates an EthernetII object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \brief Constructs a EthernetII object from a buffer and adds
* all identifiable PDUs found in the buffer as children of
* this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for a EthernetII header in the
* buffer, a malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
Expand Down
9 changes: 7 additions & 2 deletions include/icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ namespace Tins {
ICMP(Flags flag = ECHO_REQUEST);

/**
* \brief Constructor which creates an ICMP object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \brief Constructs an ICMP object from a buffer.
*
* If there is not enough size for an ICMP header, a
* malformed_packet exception is thrown.
*
* Any extra data in the buffer will be stored in a RawPDU.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
8 changes: 6 additions & 2 deletions include/icmpv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,12 @@ class ICMPv6 : public PDU {
ICMPv6(Types tp = ECHO_REQUEST);

/**
* \brief Constructor which creates an ICMP object from a buffer and
* adds all identifiable PDUs found in the buffer as children of this one.
* \brief Constructs an ICMPv6 object from a buffer.
*
* If there is not enough size for an ICMPv6 header, a
* malformed_packet exception is thrown.
*
* Any extra data is stored in a RawPDU.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
Expand Down
10 changes: 7 additions & 3 deletions include/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ namespace Tins {
PDU *child = 0);

/**
* \brief Constructor which constructs an IP object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
* \brief Constructs an IP object from a buffer and adds all
* identifiable PDUs found in the buffer as children of this
* one.
*
* If there is not enough size for an IP header, a
* malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
19 changes: 5 additions & 14 deletions include/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ class IPv6 : public PDU {
NO_NEXT_HEADER = 59
};

/**
* Exception thrown when an invalid extension header size is
* encountered.
*/
class header_size_error : public std::exception {
public:
const char *what() const throw() {
return "Not enough size for an extension header";
}
};

/**
* \brief Constructs an IPv6 object.
*
Expand All @@ -108,9 +97,11 @@ class IPv6 : public PDU {
PDU *child = 0);

/**
* \brief Constructor which creates an IPv6 object from a buffer and
* adds all identifiable PDUs found in the buffer as children of this
* one.
* \brief Constructs an IPv6 object from a buffer and adds all
* identifiable PDUs found in the buffer as children of this one.
*
* If there is not enough size for an IPv6 header, a malformed_packet
* exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
Expand Down
8 changes: 6 additions & 2 deletions include/llc.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ namespace Tins {
LLC(uint8_t dsap, uint8_t ssap, PDU* child = 0);

/**
* \brief Constructor which creates a LLC object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \brief Constructs a LLC object from a buffer and adds all
* identifiable PDUs found in the buffer as children of this one.
*
* If there is not enough size for a LLC header, a malformed_packet
* exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
9 changes: 8 additions & 1 deletion include/loopback.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ class Loopback : public PDU {
Loopback(const NetworkInterface &iface, PDU *inner_pdu = 0);

/**
* \brief Construct a Loopback object from a buffer.
* \brief Construct a Loopback object from a buffer and adds
* all identifiable PDUs found in the buffer as children of
* this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for a Loopback header, a
* malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
Expand Down
4 changes: 2 additions & 2 deletions include/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ namespace Tins {
*
* \param rhs The PDU to be moved.
*/
PDU(PDU &&rhs);
PDU(PDU &&rhs) noexcept;

/**
* \brief Move assignment operator.
*
* \param rhs The PDU to be moved.
*/
PDU& operator=(PDU &&rhs);
PDU& operator=(PDU &&rhs) noexcept;
#endif

/**
Expand Down
11 changes: 1 addition & 10 deletions include/pdu_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,9 @@
#include <vector>
#include <iterator>
#include <stdint.h>
#include "exceptions.h"

namespace Tins {
/**
* \brief Exception thrown when an option is not found.
*/
class option_not_found : public std::exception {
public:
const char* what() const throw() {
return "Option not found";
}
};

/**
* \class PDUOption
* \brief Represents a PDU option field.
Expand Down
3 changes: 3 additions & 0 deletions include/pppoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class PPPoE : public PDU {
/**
* \brief Constructor which creates an PPPoE object from a buffer.
*
* If there is not enough size for a PPPoE header, a malformed_packet
* exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
6 changes: 5 additions & 1 deletion include/radiotap.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ namespace Tins {
PDU *child = 0);

/**
* \brief Constructor which creates a RadioTap object from a buffer and adds all
* \brief Constructs a RadioTap object from a buffer and adds all
* identifiable PDUs found in the buffer as children of this one.
*
* If there is not enough size for a RadioTap header, a
* malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Expand Down
5 changes: 4 additions & 1 deletion include/rsn_information.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ namespace Tins{
RSNInformation(const serialization_type &buffer);

/**
* \brief Constructor from buffer.
* \brief Constructs a RSNInformation from a buffer.
*
* If the input is malformed, a malformed_packet exception is
* thrown.
*
* \param buffer The buffer from which this object will be constructed.
* \param total_sz The total size of the buffer.
Expand Down
Loading

0 comments on commit 3fd1b3d

Please sign in to comment.