ReactOS 0.4.16-dev-112-g52265ae
xfilter.h
Go to the documentation of this file.
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 _X_FILTER_DEFS_
24#define _X_FILTER_DEFS_
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define ETH_LENGTH_OF_ADDRESS 6
31
32#define ETH_IS_BROADCAST(Address) \
33 ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)) && \
34 (((PUCHAR)(Address))[2] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[3] == ((UCHAR)0xff)) && \
35 (((PUCHAR)(Address))[4] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[5] == ((UCHAR)0xff)))
36
37#define ETH_IS_MULTICAST(Address) \
38 (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
39
40#define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
41{ \
42 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
43 { \
44 *(_Result) = 1; \
45 } \
46 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
47 { \
48 *(_Result) = (UINT)-1; \
49 } \
50 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
51 { \
52 *(_Result) = 1; \
53 } \
54 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
55 { \
56 *(_Result) = (UINT)-1; \
57 } \
58 else \
59 { \
60 *(_Result) = 0; \
61 } \
62}
63
64#define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
65{ \
66 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
67 (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
68 { \
69 *(_Result) = 0; \
70 } \
71 else \
72 { \
73 *(_Result) = 1; \
74 } \
75}
76
77#define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
78{ \
79 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
80 *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
81}
82
83#define FDDI_LENGTH_OF_LONG_ADDRESS 6
84#define FDDI_LENGTH_OF_SHORT_ADDRESS 2
85
86#define FDDI_IS_BROADCAST(Address, AddressLength, Result) \
87 *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
88 (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
89
90#define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
91 *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
92
93#define FDDI_IS_SMT(FcByte, Result) \
94{ \
95 *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
96}
97
98
99#define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
100{ \
101 if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
102 { \
103 *(_Result) = 1; \
104 } \
105 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
106 { \
107 *(_Result) = (UINT)-1; \
108 } \
109 else if (_Length == 2) \
110 { \
111 *(_Result) = 0; \
112 } \
113 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
114 { \
115 *(_Result) = 1; \
116 } \
117 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
118 { \
119 *(_Result) = (UINT)-1; \
120 } \
121 else \
122 { \
123 *(_Result) = 0; \
124 } \
125}
126
127#define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
128{ \
129 if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
130 (((_Length) == 2) || \
131 (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
132 { \
133 *(_Result) = 0; \
134 } \
135 else \
136 { \
137 *(_Result) = 1; \
138 } \
139}
140
141#define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
142{ \
143 PCHAR _D = (D); \
144 PCHAR _S = (S); \
145 UINT _C = (AddressLength); \
146 for ( ; _C > 0 ; _D++, _S++, _C--) \
147 { \
148 *_D = *_S; \
149 } \
150}
151
152#define TR_LENGTH_OF_FUNCTIONAL 4
153#define TR_LENGTH_OF_ADDRESS 6
154
157
158#define TR_IS_NOT_DIRECTED(_Address, _Result) \
159{ \
160 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
161}
162
163#define TR_IS_FUNCTIONAL(_Address, _Result) \
164{ \
165 *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
166}
167
168#define TR_IS_GROUP(_Address, _Result) \
169{ \
170 *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
171}
172
173#define TR_IS_SOURCE_ROUTING(_Address, _Result) \
174{ \
175 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
176}
177
178#define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
179
180#define TR_IS_BROADCAST(_Address, _Result) \
181{ \
182 *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
183 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
184 (*(UNALIGNED ULONG *)&(_Address)[2] == 0xFFFFFFFF)); \
185}
186
187#define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
188{ \
189 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
190 { \
191 *(_Result) = 1; \
192 } \
193 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
194 { \
195 *(_Result) = (UINT)-1; \
196 } \
197 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
198 { \
199 *(_Result) = 1; \
200 } \
201 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
202 { \
203 *(_Result) = (UINT)-1; \
204 } \
205 else \
206 { \
207 *(_Result) = 0; \
208 } \
209}
210
211#define TR_COPY_NETWORK_ADDRESS(_D, _S) \
212{ \
213 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
214 *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
215}
216
217#define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
218{ \
219 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
220 (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
221 { \
222 *(_Result) = 0; \
223 } \
224 else \
225 { \
226 *(_Result) = 1; \
227 } \
228}
229
230#ifdef __cplusplus
231}
232#endif
233
234#endif /* _X_FILTER_DEFS_ */
uint32_t ULONG
Definition: typedefs.h:59
ULONG TR_FUNCTIONAL_ADDRESS
Definition: xfilter.h:155
ULONG TR_GROUP_ADDRESS
Definition: xfilter.h:156