libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
exceptions.h
1 /*
2  * Copyright (c) 2016, 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 
54 public:
55  // try to avoid allocations by doing this.
56  const char* what() const throw() {
57  return "Option not found";
58  }
59 };
60 
65 public:
66  const char* what() const throw() {
67  return "Malformed packet";
68  }
69 };
70 
75 public:
76  const char* what() const throw() {
77  return "Serialization error";
78  }
79 };
80 
84 class pdu_not_found : public exception_base {
85 public:
86  const char* what() const throw() {
87  return "PDU not found";
88  }
89 };
90 
96 public:
97  const char* what() const throw() {
98  return "Invalid interface";
99  }
100 };
101 
107 public:
108  const char* what() const throw() {
109  return "Invalid address";
110  }
111 };
112 
117 public:
118  const char* what() const throw() {
119  return "Field not present";
120  }
121 };
122 
127 public:
128  socket_open_error(const std::string& msg)
129  : exception_base(msg) { }
130 };
131 
136 public:
137  socket_close_error(const std::string& msg)
138  : exception_base(msg) { }
139 };
140 
145 public:
146  socket_write_error(const std::string& msg)
147  : exception_base(msg) { }
148 };
149 
155 public:
156  const char* what() const throw() {
157  return "The provided socket type is invalid";
158  }
159 };
160 
166 public:
167  const char* what() const throw() {
168  return "The sniffed link layer PDU type is unknown";
169  }
170 };
171 
176 public:
177  const char* what() const throw() {
178  return "Malformed option";
179  }
180 };
181 
186 public:
187  const char* what() const throw() {
188  return "Bad Tins cast";
189  }
190 };
191 
197 public:
198  const char* what() const throw() {
199  return "Protocol disabled";
200  }
201 };
202 
208 public:
209  const char* what() const throw() {
210  return "Feature disabled";
211  }
212 };
213 
219 public:
220  const char* what() const throw() {
221  return "Option payload too large";
222  }
223 };
224 
228 class pcap_error : public exception_base {
229 public:
230  pcap_error(const char* message) : exception_base(message) {
231 
232  }
233 };
234 
239 public:
240  invalid_pcap_filter(const char* message) : exception_base(message) {
241 
242  }
243 };
244 
250 public:
251  const char* what() const throw() {
252  return "PDU not serializable";
253  }
254 };
255 
260 public:
261  const char* what() const throw() {
262  return "Failed to create pcap handle";
263  }
264 };
265 
271 public:
272  const char* what() const throw() {
273  return "Function is not supported on this OS";
274  }
275 };
276 
281 public:
282  const char* what() const throw() {
283  return "Invalid domain name";
284  }
285 };
286 
291 public:
292  const char* what() const throw() {
293  return "Stream not found";
294  }
295 };
296 
301 public:
302  const char* what() const throw() {
303  return "Callback not set";
304  }
305 };
306 
311 public:
312  const char* what() const throw() {
313  return "Invalid packet";
314  }
315 };
316 
317 namespace Crypto {
318 namespace WPA2 {
323  public:
324  const char* what() const throw() {
325  return "Invalid WPA2 handshake";
326  }
327  };
328 } // WPA2
329 } // Crypto
330 
331 } // Tins
332 
333 #endif // TINS_EXCEPTIONS_H
Exception thrown when sniffing a protocol that has been disabled at compile time. ...
Definition: exceptions.h:196
Exception thrown when a PDU is not found when using PDU::rfind_pdu.
Definition: exceptions.h:84
Generic pcap error.
Definition: exceptions.h:228
Exception thrown when a field is not present in frame.
Definition: exceptions.h:116
Exception thrown when serializing a packet fails.
Definition: exceptions.h:74
Exception thrown when serialiation of a non-serializable PDU is attempted.
Definition: exceptions.h:249
Exception thrown when a stream is not found.
Definition: exceptions.h:290
Exception thrown when a malformed packet is parsed.
Definition: exceptions.h:64
Exception thrown when opening a pcap handle fails.
Definition: exceptions.h:259
Exception thrown when an invalid string representation of an address is provided. ...
Definition: exceptions.h:106
Exception thrown when an invalid domain name is parsed.
Definition: exceptions.h:280
Exception thrown when PacketSender fails to open a socket.
Definition: exceptions.h:126
Exception thrown when a feature has been disabled at compile time.
Definition: exceptions.h:207
Exception thrown when a function not supported on the current OS is called.
Definition: exceptions.h:270
Exception thrown when an invalid WPA2 handshake is found.
Definition: exceptions.h:322
Exception thrown when an invalid socket type is provided to PacketSender.
Definition: exceptions.h:154
Base class for all libtins exceptions.
Definition: exceptions.h:41
Exception thrown when a malformed option is found.
Definition: exceptions.h:175
Exception thrown when PacketSender fails to write on a socket.
Definition: exceptions.h:144
Exception thrown when an invalid pcap filter is compiled.
Definition: exceptions.h:238
Exception thrown when a required callback for an object is not set.
Definition: exceptions.h:300
Exception thrown when PacketSender fails to close a socket.
Definition: exceptions.h:135
Exception thrown when an invalid packet is provided to some function.
Definition: exceptions.h:310
Exception thrown when PDU::send requires a valid interface, but an invalid is used.
Definition: exceptions.h:95
Exception thrown when a call to tins_cast fails.
Definition: exceptions.h:185
Exception thrown when an option is not found.
Definition: exceptions.h:53
Exception thrown when a payload is too large to fit into a PDUOption.
Definition: exceptions.h:218