eBPF for Windows
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ip.h
Go to the documentation of this file.
1// Copyright (c) eBPF for Windows contributors
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#define IPPROTO_IPV4 4
6#define IPPROTO_TCP 6
7#define IPPROTO_UDP 17
8#define IPPROTO_IPV6 41
9
10#define AF_INET 2
11#define AF_INET6 23
12
13#ifndef DEFAULT_COMPARTMENT_ID
14#define DEFAULT_COMPARTMENT_ID 1
15#endif
16
17#if defined(_MSC_VER)
18#pragma warning(push)
19#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
20#endif
21typedef struct _IPV4_HEADER
22{
23 union
24 {
25 uint8_t VersionAndHeaderLength; // Version and header length.
26 struct
27 {
28 uint8_t HeaderLength : 4;
29 uint8_t Version : 4;
30 };
31 struct // Linux field names.
32 {
33 uint8_t ihl : 4;
34 uint8_t version : 4;
35 };
36 };
37 union
38 {
39 uint8_t tos; // Linux field name.
40 uint8_t TypeOfServiceAndEcnField; // Type of service & ECN (RFC 3168).
41 struct
42 {
43 uint8_t EcnField : 2;
44 uint8_t TypeOfService : 6;
45 };
46 };
47 union
48 {
49 uint16_t tot_len; // Linux field name.
50 uint16_t TotalLength; // Total length of datagram.
51 };
52 union
53 {
54 uint16_t id; // Linux field name.
56 };
57 union
58 {
59 uint16_t frag_off; // Linux field name.
60 uint16_t FlagsAndOffset; // Flags and fragment offset.
61 struct
62 {
63 // Order of fields here depends on MSVC compiler-specific behavior
64 // See https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields?view=msvc-170
65 uint16_t DontUse1 : 5; // High bits of fragment offset.
66 uint16_t MoreFragments : 1;
67 uint16_t DontFragment : 1;
68 uint16_t Reserved : 1;
69 uint16_t DontUse2 : 8; // Low bits of fragment offset.
70 };
71 };
72 union
73 {
74 uint8_t ttl; // Linux field name.
75 uint8_t TimeToLive;
76 };
77 union
78 {
79 uint8_t protocol; // Linux field name.
80 uint8_t Protocol;
81 };
82 union
83 {
84 uint16_t check; // Linux field name.
86 };
87 union
88 {
89 uint32_t saddr; // Linux field name.
90 uint32_t SourceAddress;
91 };
92 union
93 {
94 uint32_t daddr; // Linux field name.
96 };
98#if defined(_MSC_VER)
99#pragma warning(pop)
100#endif
101
102typedef uint8_t ipv6_address_t[16];
103
104#if defined(_MSC_VER)
105#pragma warning(push)
106#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
107#endif
108typedef struct _IPV6_HEADER
109{
110 union
111 {
112 uint32_t VersionClassFlow; // 4 bits Version, 8 Traffic Class, 20 Flow Label.
113 struct
114 { // Convenience structure to access Version field only.
115 uint32_t : 4;
116 uint32_t Version : 4;
117 uint32_t : 24;
118 };
119 };
120 uint16_t PayloadLength; // Zero indicates Jumbo Payload hop-by-hop option.
121 uint8_t NextHeader; // Values are superset of IPv4's Protocol field.
122 uint8_t HopLimit;
126#if defined(_MSC_VER)
127#pragma warning(pop)
128#endif
129
130// Linux mappings.
131#define iphdr _IPV4_HEADER
struct _IPV6_HEADER * PIPV6_HEADER
struct _IPV6_HEADER IPV6_HEADER
uint8_t ipv6_address_t[16]
Definition ip.h:102
struct _IPV4_HEADER IPV4_HEADER
struct _IPV4_HEADER * PIPV4_HEADER
Definition ip.h:22
uint8_t Protocol
Definition ip.h:80
uint16_t frag_off
Definition ip.h:59
uint16_t Reserved
Definition ip.h:68
uint8_t protocol
Definition ip.h:79
uint32_t SourceAddress
Definition ip.h:90
uint16_t MoreFragments
Definition ip.h:66
uint16_t id
Definition ip.h:54
uint8_t TimeToLive
Definition ip.h:75
uint16_t Identification
Definition ip.h:55
uint8_t TypeOfService
Definition ip.h:44
uint16_t tot_len
Definition ip.h:49
uint16_t check
Definition ip.h:84
uint8_t tos
Definition ip.h:39
uint16_t DontFragment
Definition ip.h:67
uint8_t EcnField
Definition ip.h:43
uint8_t ttl
Definition ip.h:74
uint16_t DontUse1
Definition ip.h:65
uint16_t TotalLength
Definition ip.h:50
uint16_t DontUse2
Definition ip.h:69
uint8_t VersionAndHeaderLength
Definition ip.h:25
uint8_t TypeOfServiceAndEcnField
Definition ip.h:40
uint8_t ihl
Definition ip.h:33
uint32_t daddr
Definition ip.h:94
uint8_t Version
Definition ip.h:29
uint8_t version
Definition ip.h:34
uint8_t HeaderLength
Definition ip.h:28
uint16_t HeaderChecksum
Definition ip.h:85
uint16_t FlagsAndOffset
Definition ip.h:60
uint32_t DestinationAddress
Definition ip.h:95
uint32_t saddr
Definition ip.h:89
Definition ip.h:109
uint32_t Version
Definition ip.h:116
uint16_t PayloadLength
Definition ip.h:120
ipv6_address_t SourceAddress
Definition ip.h:123
ipv6_address_t DestinationAddress
Definition ip.h:124
uint8_t NextHeader
Definition ip.h:121
uint32_t VersionClassFlow
Definition ip.h:112
uint8_t HopLimit
Definition ip.h:122