forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetdumpIP.h
More file actions
103 lines (85 loc) · 2.04 KB
/
NetdumpIP.h
File metadata and controls
103 lines (85 loc) · 2.04 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
NetdumpIP.h
Created on: 18 mei 2019
Author: Herman
*/
#ifndef LIBRARIES_ESPGOODIES_HR_SRC_NETDUMP_NETDUMPIP_H_
#define LIBRARIES_ESPGOODIES_HR_SRC_NETDUMP_NETDUMPIP_H_
#include <stdint.h>
#include <lwip/init.h>
#include <StreamString.h>
#include <IPAddress.h>
namespace NetCapture
{
class NetdumpIP
{
public:
NetdumpIP();
NetdumpIP(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
NetdumpIP(const uint8_t *address, bool V4 = true);
NetdumpIP(const IPAddress& ip);
NetdumpIP(const String& ip);
uint8_t& operator[](int index)
{
return rawip[index];
}
bool fromString(const char *address);
String toString();
private:
enum class IPversion {UNSET, IPV4, IPV6};
IPversion ipv = IPversion::UNSET;
uint8_t rawip[16] = {0};
void setV4()
{
ipv = IPversion::IPV4;
};
void setV6()
{
ipv = IPversion::IPV6;
};
void setUnset()
{
ipv = IPversion::UNSET;
};
bool isV4() const
{
return (ipv == IPversion::IPV4);
};
bool isV6() const
{
return (ipv == IPversion::IPV6);
};
bool isUnset() const
{
return (ipv == IPversion::UNSET);
};
bool isSet() const
{
return (ipv != IPversion::UNSET);
};
bool compareRaw(IPversion v, const uint8_t* a, const uint8_t* b) const;
bool compareIP(const IPAddress& ip) const;
bool compareIP(const NetdumpIP& nip) const;
bool fromString4(const char *address);
bool fromString6(const char *address);
size_t printTo(Print& p);
public:
bool operator==(const IPAddress& addr) const
{
return compareIP(addr);
};
bool operator!=(const IPAddress& addr)
{
return compareIP(addr);
};
bool operator==(const NetdumpIP& addr)
{
return compareIP(addr);
};
bool operator!=(const NetdumpIP& addr)
{
return !compareIP(addr);
};
};
} // namespace NetCapture
#endif /* LIBRARIES_ESPGOODIES_HR_SRC_NETDUMP_NETDUMPIP_H_ */