source: Daodan/MinGW/include/ddk/xfilter.h@ 1088

Last change on this file since 1088 was 1046, checked in by alloc, 8 years ago

Daodan: Added Windows MinGW and build batch file

File size: 5.6 KB
Line 
1/*
2 * xfilter.h
3 *
4 * Address filtering for NDIS MACs
5 *
6 * This file is part of the w32api package.
7 *
8 * Contributors:
9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
10 *
11 * THIS SOFTWARE IS NOT COPYRIGHTED
12 *
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
15 *
16 * This code is distributed in the hope that it will be useful but
17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 * DISCLAIMED. This includes but is not limited to warranties of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 */
22
23#ifndef __XFILTER_H
24#define __XFILTER_H
25
26#if __GNUC__ >=3
27#pragma GCC system_header
28#endif
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include "ntddk.h"
35
36
37#define ETH_LENGTH_OF_ADDRESS 6
38
39#define ETH_IS_BROADCAST(Address) \
40 ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
41
42#define ETH_IS_MULTICAST(Address) \
43 (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
44
45#define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
46{ \
47 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
48 { \
49 *(_Result) = 1; \
50 } \
51 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
52 { \
53 *(_Result) = (UINT)-1; \
54 } \
55 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
56 { \
57 *(_Result) = 1; \
58 } \
59 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
60 { \
61 *(_Result) = (UINT)-1; \
62 } \
63 else \
64 { \
65 *(_Result) = 0; \
66 } \
67}
68
69#define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
70{ \
71 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
72 (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
73 { \
74 *(_Result) = 0; \
75 } \
76 else \
77 { \
78 *(_Result) = 1; \
79 } \
80}
81
82#define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
83{ \
84 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
85 *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
86}
87
88#define FDDI_LENGTH_OF_LONG_ADDRESS 6
89#define FDDI_LENGTH_OF_SHORT_ADDRESS 2
90
91#define FDDI_IS_BROADCAST(Address, AddressLength, Result) \
92 *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
93 (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
94
95#define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
96 *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
97
98#define FDDI_IS_SMT(FcByte, Result) \
99{ \
100 *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
101}
102
103
104#define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
105{ \
106 if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
107 { \
108 *(_Result) = 1; \
109 } \
110 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
111 { \
112 *(_Result) = (UINT)-1; \
113 } \
114 else if (_Length == 2) \
115 { \
116 *(_Result) = 0; \
117 } \
118 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
119 { \
120 *(_Result) = 1; \
121 } \
122 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
123 { \
124 *(_Result) = (UINT)-1; \
125 } \
126 else \
127 { \
128 *(_Result) = 0; \
129 } \
130}
131
132#define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
133{ \
134 if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
135 (((_Length) == 2) || \
136 (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
137 { \
138 *(_Result) = 0; \
139 } \
140 else \
141 { \
142 *(_Result) = 1; \
143 } \
144}
145
146#define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
147{ \
148 PCHAR _D = (D); \
149 PCHAR _S = (S); \
150 UINT _C = (AddressLength); \
151 for ( ; _C > 0 ; _D++, _S++, _C--) \
152 { \
153 *_D = *_S; \
154 } \
155}
156
157#define TR_LENGTH_OF_FUNCTIONAL 4
158#define TR_LENGTH_OF_ADDRESS 6
159
160typedef ULONG TR_FUNCTIONAL_ADDRESS;
161typedef ULONG TR_GROUP_ADDRESS;
162
163#define TR_IS_NOT_DIRECTED(_Address, _Result) \
164{ \
165 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
166}
167
168#define TR_IS_FUNCTIONAL(_Address, _Result) \
169{ \
170 *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
171}
172
173#define TR_IS_GROUP(_Address, _Result) \
174{ \
175 *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
176}
177
178#define TR_IS_SOURCE_ROUTING(_Address, _Result) \
179{ \
180 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
181}
182
183#define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
184
185#define TR_IS_BROADCAST(_Address, _Result) \
186{ \
187 *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
188 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
189 (*(UNALIGNED ULONG *)&(_Address)[2] == 0xFFFFFFFF)); \
190}
191
192#define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
193{ \
194 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
195 { \
196 *(_Result) = 1; \
197 } \
198 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
199 { \
200 *(_Result) = (UINT)-1; \
201 } \
202 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
203 { \
204 *(_Result) = 1; \
205 } \
206 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
207 { \
208 *(_Result) = (UINT)-1; \
209 } \
210 else \
211 { \
212 *(_Result) = 0; \
213 } \
214}
215
216#define TR_COPY_NETWORK_ADDRESS(_D, _S) \
217{ \
218 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
219 *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
220}
221
222#define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
223{ \
224 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
225 (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
226 { \
227 *(_Result) = 0; \
228 } \
229 else \
230 { \
231 *(_Result) = 1; \
232 } \
233}
234
235#ifdef __cplusplus
236}
237#endif
238
239#endif /* __XFILTER_H */
Note: See TracBrowser for help on using the repository browser.