-
Notifications
You must be signed in to change notification settings - Fork 241
/
ip.h
131 lines (124 loc) · 3.25 KB
/
ip.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) eBPF for Windows contributors
// SPDX-License-Identifier: MIT
#pragma once
#define IPPROTO_IPV4 4
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_IPV6 41
#define AF_INET 2
#define AF_INET6 23
#ifndef DEFAULT_COMPARTMENT_ID
#define DEFAULT_COMPARTMENT_ID 1
#endif
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#endif
typedef struct _IPV4_HEADER
{
union
{
uint8_t VersionAndHeaderLength; // Version and header length.
struct
{
uint8_t HeaderLength : 4;
uint8_t Version : 4;
};
struct // Linux field names.
{
uint8_t ihl : 4;
uint8_t version : 4;
};
};
union
{
uint8_t tos; // Linux field name.
uint8_t TypeOfServiceAndEcnField; // Type of service & ECN (RFC 3168).
struct
{
uint8_t EcnField : 2;
uint8_t TypeOfService : 6;
};
};
union
{
uint16_t tot_len; // Linux field name.
uint16_t TotalLength; // Total length of datagram.
};
union
{
uint16_t id; // Linux field name.
uint16_t Identification;
};
union
{
uint16_t frag_off; // Linux field name.
uint16_t FlagsAndOffset; // Flags and fragment offset.
struct
{
// Order of fields here depends on MSVC compiler-specific behavior
// See https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields?view=msvc-170
uint16_t DontUse1 : 5; // High bits of fragment offset.
uint16_t MoreFragments : 1;
uint16_t DontFragment : 1;
uint16_t Reserved : 1;
uint16_t DontUse2 : 8; // Low bits of fragment offset.
};
};
union
{
uint8_t ttl; // Linux field name.
uint8_t TimeToLive;
};
union
{
uint8_t protocol; // Linux field name.
uint8_t Protocol;
};
union
{
uint16_t check; // Linux field name.
uint16_t HeaderChecksum;
};
union
{
uint32_t saddr; // Linux field name.
uint32_t SourceAddress;
};
union
{
uint32_t daddr; // Linux field name.
uint32_t DestinationAddress;
};
} IPV4_HEADER, *PIPV4_HEADER;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
typedef uint8_t ipv6_address_t[16];
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#endif
typedef struct _IPV6_HEADER
{
union
{
uint32_t VersionClassFlow; // 4 bits Version, 8 Traffic Class, 20 Flow Label.
struct
{ // Convenience structure to access Version field only.
uint32_t : 4;
uint32_t Version : 4;
uint32_t : 24;
};
};
uint16_t PayloadLength; // Zero indicates Jumbo Payload hop-by-hop option.
uint8_t NextHeader; // Values are superset of IPv4's Protocol field.
uint8_t HopLimit;
ipv6_address_t SourceAddress;
ipv6_address_t DestinationAddress;
} IPV6_HEADER, *PIPV6_HEADER;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
// Linux mappings.
#define iphdr _IPV4_HEADER