-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
packet.cpp
42 lines (34 loc) · 1.43 KB
/
packet.cpp
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
// (C) 2020 by folkert van heusden <[email protected]>, released under Apache License v2.0
#include "packet.h"
#include "utils.h"
packet::packet(const timespec & ts_in, const any_addr & src_mac_addr, const any_addr & src_addr, const any_addr & dst_addr, const uint8_t *const in, const int size, const uint8_t *const header, const int header_size, const std::string & log_prefix, const bool is_forwarded) :
ts(ts_in),
src_mac_addr(src_mac_addr), src_addr(src_addr), dst_addr(dst_addr),
log_prefix(log_prefix),
is_forwarded(is_forwarded)
{
this->size = size;
data = ::duplicate(in, size);
this->header_size = header_size;
this->header = header_size ? ::duplicate(header, header_size) : nullptr;
}
packet::packet(const timespec & ts_in, const any_addr & src_addr, const any_addr & dst_addr, const uint8_t *const in, const int size, const uint8_t *const header, const int header_size, const std::string & log_prefix, const bool is_forwarded) :
ts(ts_in),
src_mac_addr(src_addr), src_addr(src_addr), dst_addr(dst_addr),
log_prefix(log_prefix),
is_forwarded(is_forwarded)
{
this->size = size;
data = ::duplicate(in, size);
this->header_size = header_size;
this->header = header_size ? ::duplicate(header, header_size) : nullptr;
}
packet::~packet()
{
delete [] header;
delete [] data;
}
packet *packet::duplicate() const
{
return new packet(ts, src_mac_addr, src_addr, dst_addr, data, size, header, header_size, log_prefix, is_forwarded);
}