1 /**
2  * This file is part of the mingw-w64 runtime package.
3  * No warranty is given; refer to the file DISCLAIMER within this package.
4  */
5 #ifndef _WS2IPDEF_
6 #define _WS2IPDEF_
7 
8 #include <_mingw_unicode.h>
9 #include <winapifamily.h>
10 
11 #ifdef __LP64__
12 #pragma push_macro("u_long")
13 #undef u_long
14 #define u_long __ms_u_long
15 #endif
16 
17 #include <in6addr.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* options at IPPROTO_IP level */
24 #define IP_OPTIONS                 1
25 #define IP_HDRINCL                 2
26 #define IP_TOS                     3
27 #define IP_TTL                     4
28 #define IP_MULTICAST_IF            9
29 #define IP_MULTICAST_TTL          10
30 #define IP_MULTICAST_LOOP         11
31 #define IP_ADD_MEMBERSHIP         12
32 #define IP_DROP_MEMBERSHIP        13
33 #define IP_DONTFRAGMENT           14
34 #define IP_ADD_SOURCE_MEMBERSHIP  15
35 #define IP_DROP_SOURCE_MEMBERSHIP 16
36 #define IP_BLOCK_SOURCE           17
37 #define IP_UNBLOCK_SOURCE         18
38 #define IP_PKTINFO                19
39 #define IP_HOPLIMIT               21
40 #define IP_RECVTTL                21
41 #define IP_RECEIVE_BROADCAST      22
42 #define IP_RECVIF                 24
43 #define IP_RECVDSTADDR            25
44 #define IP_IFLIST                 28
45 #define IP_ADD_IFLIST             29
46 #define IP_DEL_IFLIST             30
47 #define IP_UNICAST_IF             31
48 #define IP_RTHDR                  32
49 #define IP_GET_IFLIST             33
50 #define IP_RECVRTHDR              38
51 #define IP_TCLASS                 39
52 #define IP_RECVTCLASS             40
53 #define IP_RECVTOS                40
54 #define IP_ORIGINAL_ARRIVAL_IF    47
55 #define IP_ECN                    50
56 #define IP_PKTINFO_EX             51
57 #define IP_WFP_REDIRECT_RECORDS   60
58 #define IP_WFP_REDIRECT_CONTEXT   70
59 #define IP_MTU_DISCOVER           71
60 #define IP_MTU                    73
61 #define IP_NRT_INTERFACE          74
62 #define IP_RECVERR                75
63 #define IP_USER_MTU               76
64 
65 #define IP_UNSPECIFIED_TYPE_OF_SERVICE -1
66 #define IP_UNSPECIFIED_USER_MTU MAXULONG
67 
68 #define IPV6_ADDRESS_BITS RTL_BITS_OF(IN6_ADDR)
69 
70 /* options at IPPROTO_IPV6 level */
71 #define IPV6_HOPOPTS              1
72 #define IPV6_HDRINCL              2
73 #define IPV6_UNICAST_HOPS         4
74 #define IPV6_MULTICAST_IF         9
75 #define IPV6_MULTICAST_HOPS       10
76 #define IPV6_MULTICAST_LOOP       11
77 #define IPV6_ADD_MEMBERSHIP       12
78 #define IPV6_JOIN_GROUP           IPV6_ADD_MEMBERSHIP
79 #define IPV6_DROP_MEMBERSHIP      13
80 #define IPV6_LEAVE_GROUP          IPV6_DROP_MEMBERSHIP
81 #define IPV6_DONTFRAG             14
82 #define IPV6_PKTINFO              19
83 #define IPV6_HOPLIMIT             21
84 #define IPV6_PROTECTION_LEVEL     23
85 #define IPV6_RECVIF               24
86 #define IPV6_RECVDSTADDR          25
87 #define IPV6_CHECKSUM             26
88 #define IPV6_V6ONLY               27
89 #define IPV6_IFLIST               28
90 #define IPV6_ADD_IFLIST           29
91 #define IPV6_DEL_IFLIST           30
92 #define IPV6_UNICAST_IF           31
93 #define IPV6_RTHDR                32
94 #define IPV6_GET_IFLIST           33
95 #define IPV6_RECVRTHDR            38
96 #define IPV6_TCLASS               39
97 #define IPV6_RECVTCLASS           40
98 #define IPV6_ECN                  50
99 #define IPV6_PKTINFO_EX           51
100 #define IPV6_WFP_REDIRECT_RECORDS 60
101 #define IPV6_WFP_REDIRECT_CONTEXT 70
102 #define IPV6_MTU_DISCOVER         71
103 #define IPV6_MTU                  72
104 #define IPV6_NRT_INTERFACE        74
105 #define IPV6_RECVERR              75
106 #define IPV6_USER_MTU             76
107 
108 #define IP_UNSPECIFIED_HOP_LIMIT -1
109 
110 #define IP_PROTECTION_LEVEL IPV6_PROTECTION_LEVEL
111 
112 #define PROTECTION_LEVEL_UNRESTRICTED   10
113 #define PROTECTION_LEVEL_EDGERESTRICTED 20
114 #define PROTECTION_LEVEL_RESTRICTED     30
115 
116 #if NTDDI_VERSION < NTDDI_VISTA
117 #define PROTECTION_LEVEL_DEFAULT PROTECTION_LEVEL_EDGERESTRICTED
118 #else
119 #define PROTECTION_LEVEL_DEFAULT ((UINT)-1)
120 #endif
121 
122 typedef struct ipv6_mreq {
123   struct in6_addr ipv6mr_multiaddr;
124   unsigned int ipv6mr_interface;
125 } IPV6_MREQ;
126 
127 struct sockaddr_in6_old {
128   short sin6_family;
129   u_short sin6_port;
130   u_long sin6_flowinfo;
131   struct in6_addr sin6_addr;
132 };
133 
134 typedef union sockaddr_gen {
135   struct sockaddr Address;
136   struct sockaddr_in AddressIn;
137   struct sockaddr_in6_old AddressIn6;
138 } sockaddr_gen;
139 
140 struct sockaddr_in6 {
141   short sin6_family;
142   u_short sin6_port;
143   u_long sin6_flowinfo;
144   struct in6_addr sin6_addr;
145   __C89_NAMELESS union {
146     u_long sin6_scope_id;
147     SCOPE_ID sin6_scope_struct;
148   };
149 };
150 
151 typedef struct sockaddr_in6 SOCKADDR_IN6;
152 typedef struct sockaddr_in6 *PSOCKADDR_IN6;
153 typedef struct sockaddr_in6 *LPSOCKADDR_IN6;
154 
155 typedef struct _INTERFACE_INFO {
156   u_long iiFlags;
157   sockaddr_gen iiAddress;
158   sockaddr_gen iiBroadcastAddress;
159   sockaddr_gen iiNetmask;
160 } INTERFACE_INFO,*LPINTERFACE_INFO;
161 
162 typedef struct _INTERFACE_INFO_EX {
163   u_long iiFlags;
164   SOCKET_ADDRESS iiAddress;
165   SOCKET_ADDRESS iiBroadcastAddress;
166   SOCKET_ADDRESS iiNetmask;
167 } INTERFACE_INFO_EX, *LPINTERFACE_INFO_EX;
168 
169 #define IFF_UP 0x00000001
170 #define IFF_BROADCAST 0x00000002
171 #define IFF_LOOPBACK 0x00000004
172 #define IFF_POINTTOPOINT 0x00000008
173 #define IFF_MULTICAST 0x00000010
174 
175 typedef enum _PMTUD_STATE {
176   IP_PMTUDISC_NOT_SET,
177   IP_PMTUDISC_DO,
178   IP_PMTUDISC_DONT,
179   IP_PMTUDISC_PROBE,
180   IP_PMTUDISC_MAX
181 } PMTUD_STATE, *PPMTUD_STATE;
182 
183 #define MCAST_JOIN_GROUP 41
184 #define MCAST_LEAVE_GROUP 42
185 #define MCAST_BLOCK_SOURCE 43
186 #define MCAST_UNBLOCK_SOURCE 44
187 #define MCAST_JOIN_SOURCE_GROUP 45
188 #define MCAST_LEAVE_SOURCE_GROUP 46
189 
190 typedef enum _MULTICAST_MODE_TYPE {
191   MCAST_INCLUDE = 0,
192   MCAST_EXCLUDE
193 } MULTICAST_MODE_TYPE;
194 
195 typedef struct ip_mreq {
196   IN_ADDR imr_multiaddr;
197   IN_ADDR imr_interface;
198 } IP_MREQ, *PIP_MREQ;
199 
200 typedef struct ip_mreq_source {
201   IN_ADDR imr_multiaddr;
202   IN_ADDR imr_sourceaddr;
203   IN_ADDR imr_interface;
204 } IP_MREQ_SOURCE, *PIP_MREQ_SOURCE;
205 
206 typedef struct ip_msfilter {
207   IN_ADDR imsf_multiaddr;
208   IN_ADDR imsf_interface;
209   MULTICAST_MODE_TYPE imsf_fmode;
210   ULONG imsf_numsrc;
211   IN_ADDR imsf_slist[1];
212 } IP_MSFILTER, *PIP_MSFILTER;
213 
214 #define IP_MSFILTER_SIZE(NumSources) (sizeof(IP_MSFILTER) - sizeof(IN_ADDR) + (NumSources) * sizeof(IN_ADDR))
215 
216 typedef struct _sockaddr_in6_pair {
217   PSOCKADDR_IN6 SourceAddress;
218   PSOCKADDR_IN6 DestinationAddress;
219 } SOCKADDR_IN6_PAIR, *PSOCKADDR_IN6_PAIR;
220 
221 typedef union _SOCKADDR_INET {
222   SOCKADDR_IN    Ipv4;
223   SOCKADDR_IN6   Ipv6;
224   ADDRESS_FAMILY si_family;
225 } SOCKADDR_INET, *PSOCKADDR_INET;
226 
227 typedef struct group_filter {
228   ULONG               gf_interface;
229   SOCKADDR_STORAGE    gf_group;
230   MULTICAST_MODE_TYPE gf_fmode;
231   ULONG               gf_numsrc;
232   SOCKADDR_STORAGE    gf_slist[1];
233 } GROUP_FILTER, *PGROUP_FILTER;
234 
235 typedef struct group_req {
236   ULONG            gr_interface;
237   SOCKADDR_STORAGE gr_group;
238 } GROUP_REQ, *PGROUP_REQ;
239 
240 typedef struct group_source_req {
241   ULONG            gsr_interface;
242   SOCKADDR_STORAGE gsr_group;
243   SOCKADDR_STORAGE gsr_source;
244 } GROUP_SOURCE_REQ, *PGROUP_SOURCE_REQ;
245 
246 #define WS2TCPIP_INLINE __CRT_INLINE
247 
248 int IN6_ADDR_EQUAL(const struct in6_addr *,const struct in6_addr *);
IN6_ADDR_EQUAL(const struct in6_addr * a,const struct in6_addr * b)249 WS2TCPIP_INLINE int IN6_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b) {
250     return !memcmp(a, b, sizeof(struct in6_addr));
251 }
252 
253 #define IN6_ARE_ADDR_EQUAL IN6_ADDR_EQUAL
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #ifdef __LP64__
260 #pragma pop_macro("u_long")
261 #endif
262 
263 #endif /*_WS2IPDEF_ */
264