-
Notifications
You must be signed in to change notification settings - Fork 12
/
PacketHeaderV6.h
37 lines (30 loc) · 1.2 KB
/
PacketHeaderV6.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
//
// Quick class to generate hashes of IPv6 packets for use in std::unordered_map
//
#ifndef GWLBTUN_PACKETHEADERV6_H
#define GWLBTUN_PACKETHEADERV6_H
#include <cinttypes>
#include <iostream>
#include <stdexcept>
#include <netinet/ip6.h>
class PacketHeaderV6 {
public:
PacketHeaderV6(unsigned char *pktbuf, ssize_t pktlen); // pktbuf points to the start of the IP header.
bool operator==(const PacketHeaderV6 &) const;
std::string text() const;
std::size_t hash() const;
PacketHeaderV6 reverse() const; // Return a PH for the reverse flow direction (src/dst ips and ports swapped)
private:
struct in6_addr src;
struct in6_addr dst;
uint32_t flow;
uint16_t srcpt;
uint16_t dstpt;
uint8_t prot;
PacketHeaderV6(uint8_t prot, uint32_t flow, struct in6_addr src, struct in6_addr dst, uint16_t srcpt, uint16_t dstpt);
};
std::ostream &operator<<(std::ostream &os, PacketHeaderV6 const &m);
template<> struct std::hash<PacketHeaderV6>:unary_function<PacketHeaderV6, size_t> { std::size_t operator()(const PacketHeaderV6& t) const; };
#endif //GWLBTUN_PACKETHEADERV6_H