-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
packet.h
58 lines (38 loc) · 1.82 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
// (C) 2020 by folkert van heusden <[email protected]>, released under Apache License v2.0
#pragma once
#include <cstring>
#include <stdint.h>
#include <utility>
#include <sys/time.h>
#include "any_addr.h"
class packet
{
private:
const struct timespec ts { 0, 0 };
const any_addr src_mac_addr;
const any_addr src_addr;
const any_addr dst_addr;
uint8_t *data;
int size;
std::string log_prefix;
// this is required for ICMP: it needs certain fields from the source (IP-)header
uint8_t *header;
int header_size;
const bool is_forwarded;
public:
packet(const timespec & ts, 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 = false);
packet(const timespec & ts, 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 = false);
virtual ~packet();
uint8_t *get_data() const { return data; }
std::pair<const uint8_t *, int> get_payload() const { return { data, size }; }
bool get_is_forwarded() const { return is_forwarded; }
int get_size() const { return size; }
void add_to_log_prefix(const std::string & what) { log_prefix += what; }
std::string get_log_prefix() const { return log_prefix; }
const any_addr & get_src_mac_addr() const { return src_mac_addr; }
const any_addr & get_src_addr() const { return src_addr; }
const any_addr & get_dst_addr() const { return dst_addr; }
std::pair<const uint8_t *, int> get_header() const { return { header, header_size }; }
struct timespec get_recv_ts() const { return ts; }
packet *duplicate() const;
};