libtins  4.0
exceptions.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef TINS_EXCEPTIONS_H
31 #define TINS_EXCEPTIONS_H
32 
33 #include <string>
34 #include <stdexcept>
35 
36 namespace Tins {
37 
41 class exception_base : public std::runtime_error {
42 public:
44  : std::runtime_error(std::string()) { }
45 
46  exception_base(const std::string& message)
47  : std::runtime_error(message) { }
48 
49  exception_base(const char* message)
50  : std::runtime_error(message) { }
51 };
52 
57 public:
58  option_not_found() : exception_base("Option not found") { }
59 };
60 
65 public:
66  malformed_packet() : exception_base("Malformed packet") { }
67 };
68 
73 public:
74  serialization_error() : exception_base("Serialization error") { }
75 };
76 
80 class pdu_not_found : public exception_base {
81 public:
82  pdu_not_found() : exception_base("PDU not found") { }
83 };
84 
90 public:
91  invalid_interface() : exception_base("Invalid interface") { }
92 };
93 
99 public:
100  invalid_address() : exception_base("Invalid address") { }
101 };
102 
107 public:
108  invalid_option_value() : exception_base("Invalid option value") { }
109 };
110 
115 public:
116  field_not_present() : exception_base("Field not present") { }
117 };
118 
123 public:
124  socket_open_error(const std::string& msg)
125  : exception_base(msg) { }
126 };
127 
132 public:
133  socket_close_error(const std::string& msg)
134  : exception_base(msg) { }
135 };
136 
141 public:
142  socket_write_error(const std::string& msg)
143  : exception_base(msg) { }
144 };
145 
151 public:
152  invalid_socket_type() : exception_base("The provided socket type is invalid") { }
153 };
154 
160 public:
161  unknown_link_type() : exception_base("The sniffed link layer PDU type is unknown") { }
162 };
163 
168 public:
169  malformed_option() : exception_base("Malformed option") { }
170 };
171 
176 public:
177  bad_tins_cast() : exception_base("Bad Tins cast") { }
178 };
179 
185 public:
186  protocol_disabled() : exception_base("Protocol disabled") { }
187 };
188 
194 public:
195  feature_disabled() : exception_base("Feature disabled") { }
196 };
197 
203 public:
204  option_payload_too_large() : exception_base("Option payload too large") { }
205 };
206 
212 public:
213  invalid_ipv6_extension_header() : exception_base("Invalid IPv6 extension header") { }
214 };
215 
219 class pcap_error : public exception_base {
220 public:
221  pcap_error(const char* message) : exception_base(message) {
222 
223  }
224 
225  pcap_error(const std::string& message) : exception_base(message) {
226 
227  }
228 };
229 
234 public:
235  invalid_pcap_filter(const char* message) : exception_base(message) {
236 
237  }
238 };
239 
245 public:
246  pdu_not_serializable() : exception_base("PDU not serializable") { }
247 };
248 
253 public:
254  pcap_open_failed() : exception_base("Failed to create pcap handle") { }
255 };
256 
262 public:
263  unsupported_function() : exception_base("Function is not supported on this OS") { }
264 };
265 
270 public:
271  invalid_domain_name() : exception_base("Invalid domain name") { }
272 };
273 
278 public:
279  stream_not_found() : exception_base("Stream not found") { }
280 };
281 
286 public:
287  callback_not_set() : exception_base("Callback not set") { }
288 };
289 
294 public:
295  invalid_packet() : exception_base("Invalid packet") { }
296 };
297 
298 namespace Crypto {
299 namespace WPA2 {
304  public:
305  invalid_handshake() : exception_base("Invalid WPA2 handshake") { }
306  };
307 } // WPA2
308 } // Crypto
309 
310 } // Tins
311 
312 #endif // TINS_EXCEPTIONS_H
Exception thrown when sniffing a protocol that has been disabled at compile time. ...
Definition: exceptions.h:184
Exception thrown when a PDU is not found when using PDU::rfind_pdu.
Definition: exceptions.h:80
Generic pcap error.
Definition: exceptions.h:219
Exception thrown when a field is not present in frame.
Definition: exceptions.h:114
Exception thrown when serializing a packet fails.
Definition: exceptions.h:72
Exception thrown when serialiation of a non-serializable PDU is attempted.
Definition: exceptions.h:244
Exception thrown when a stream is not found.
Definition: exceptions.h:277
Exception thrown when a malformed packet is parsed.
Definition: exceptions.h:64
Exception thrown when an IPv6 extension header is being created from invalid data.
Definition: exceptions.h:211
Exception thrown when opening a pcap handle fails.
Definition: exceptions.h:252
Exception thrown when an invalid string representation of an address is provided. ...
Definition: exceptions.h:98
Exception thrown when an invalid domain name is parsed.
Definition: exceptions.h:269
Exception thrown when PacketSender fails to open a socket.
Definition: exceptions.h:122
Exception thrown when a feature has been disabled at compile time.
Definition: exceptions.h:193
Exception thrown when a function not supported on the current OS is called.
Definition: exceptions.h:261
Exception thrown when an invalid WPA2 handshake is found.
Definition: exceptions.h:303
Exception thrown when an invalid socket type is provided to PacketSender.
Definition: exceptions.h:150
Base class for all libtins exceptions.
Definition: exceptions.h:41
The Tins namespace.
Definition: address_range.h:38
Exception thrown when a malformed option is found.
Definition: exceptions.h:167
Exception thrown when PacketSender fails to write on a socket.
Definition: exceptions.h:140
Exception thrown when an invalid pcap filter is compiled.
Definition: exceptions.h:233
Exception thrown when a required callback for an object is not set.
Definition: exceptions.h:285
Exception thrown when PacketSender fails to close a socket.
Definition: exceptions.h:131
Exception thrown when an invalid packet is provided to some function.
Definition: exceptions.h:293
Exception thrown when a PDU option is set using an incorrect value.
Definition: exceptions.h:106
Exception thrown when PDU::send requires a valid interface, but an invalid is used.
Definition: exceptions.h:89
Exception thrown when a call to tins_cast fails.
Definition: exceptions.h:175
Exception thrown when an option is not found.
Definition: exceptions.h:56
Exception thrown when a payload is too large to fit into a PDUOption.
Definition: exceptions.h:202