-
Notifications
You must be signed in to change notification settings - Fork 1
/
packet.h
74 lines (54 loc) · 2.05 KB
/
packet.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef _packet
#define _packet
#include <deque>
#include "config.h"
#include "buffer.h"
#include "headertrailer.h"
#include "raw_ethernet_packet.h"
struct RawEthernetPacket;
class Packet {
protected:
deque<Header> headers;
Buffer payload;
deque<Trailer> trailers;
public:
Packet();
Packet(const Packet &rhs);
Packet(const Buffer &rhs);
Packet(const char *buf, size_t size);
Packet(const RawEthernetPacket &rhs);
virtual ~Packet();
virtual const Packet & operator= (const Packet &rhs);
virtual void Serialize(const int fd) const;
virtual void Unserialize(const int fd);
virtual size_t GetRawSize() const;
virtual void WriteRaw(const int fd) const;
virtual void DupeRaw(char *buf, size_t size) const;
virtual void PushHeader(const Header &header);
virtual void PushFrontHeader(const Header &header);
virtual void PushBackHeader(const Header &header);
virtual Header & PopHeader();
virtual Header & PopFrontHeader();
virtual Header & PopBackHeader();
virtual void PushTrailer(const Trailer &trailer);
virtual void PushFrontTrailer(const Trailer &trailer);
virtual void PushBackTrailer(const Trailer &trailer);
virtual Trailer & PopTrailer();
virtual Trailer & PopFrontTrailer();
virtual Trailer & PopBackTrailer();
virtual Header & FindHeader(Headers::HeaderType ht) const;
virtual void SetHeader(const Header &h);
virtual Trailer & FindTrailer(Trailers::TrailerType tt) const;
virtual void SetTrailer(const Trailer &h);
virtual Buffer & GetPayload();
virtual void ExtractHeaderFromPayload(Headers::HeaderType type, size_t bytes);
virtual void ExtractTrailerFromPayload(Trailers::TrailerType type, size_t bytes);
template <class HEADER> void ExtractHeaderFromPayload(size_t size) {
headers.push_back(HEADER(payload.ExtractFront(size)));
}
template <class TRAILER> void ExtractTrailerFromPayload(size_t size) {
trailers.push_front(TRAILER(payload.ExtractBack(size)));
}
virtual ostream & Print(ostream &os) const;
};
#endif