-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLinkLayerSanitizer.hpp
46 lines (34 loc) · 1.01 KB
/
LinkLayerSanitizer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef LINKLAYERSANITIZER_HPP
#define LINKLAYERSANITIZER_HPP
#include "Packet.hpp"
namespace capsan {
class LinkLayerSanitizer {
public:
/**
* @param link_type a link-layer type returned by pcap_datalink.
*/
LinkLayerSanitizer(int link_type);
int LinkType() const
{ return link_type; }
/**
* @return true if the link type can be handled.
*/
bool Valid() const
{ return sanitizer != 0; }
/**
* Parse and optionally sanitize a link-layer header.
* @param pkt packet data read by libpcap.
* @return number of bytes in the link-layer header, or a negative
* value if it can't be determined (e.g. caplen too small), or if the
* network-layer payload is not IPv4. Specifically, -1 is returned
* for caplen problems and -2 for non-IPv4 payloads.
*/
int Sanitize(const capsan::Packet& pkt) const
{ return (*sanitizer)(pkt); }
private:
typedef int (*sanitize_func)(const capsan::Packet& pkt);
int link_type;
sanitize_func sanitizer;
};
} // namespace capsan
#endif // LINKLAYERSANITIZER_HPP