3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 * Address filtering for NDIS MACs
31 #pragma GCC system_header
40 #define ETH_LENGTH_OF_ADDRESS 6
42 #define ETH_IS_BROADCAST(Address) \
43 ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
45 #define ETH_IS_MULTICAST(Address) \
46 (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
48 #define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
50 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
54 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
56 *(_Result) = (UINT)-1; \
58 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
62 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
64 *(_Result) = (UINT)-1; \
72 #define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
74 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
75 (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
85 #define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
87 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
88 *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
91 #define FDDI_LENGTH_OF_LONG_ADDRESS 6
92 #define FDDI_LENGTH_OF_SHORT_ADDRESS 2
94 #define FDDI_IS_BROADCAST(Address, AddressLength, Result) \
95 *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
96 (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
98 #define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
99 *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
101 #define FDDI_IS_SMT(FcByte, Result) \
103 *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
107 #define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
109 if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
113 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
115 *(_Result) = (UINT)-1; \
117 else if (_Length == 2) \
121 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
125 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
127 *(_Result) = (UINT)-1; \
135 #define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
137 if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
138 (((_Length) == 2) || \
139 (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
149 #define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
153 UINT _C = (AddressLength); \
154 for ( ; _C > 0 ; _D++, _S++, _C--) \
160 #define TR_LENGTH_OF_FUNCTIONAL 4
161 #define TR_LENGTH_OF_ADDRESS 6
163 typedef ULONG TR_FUNCTIONAL_ADDRESS;
164 typedef ULONG TR_GROUP_ADDRESS;
166 #define TR_IS_NOT_DIRECTED(_Address, _Result) \
168 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
171 #define TR_IS_FUNCTIONAL(_Address, _Result) \
173 *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
176 #define TR_IS_GROUP(_Address, _Result) \
178 *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
181 #define TR_IS_SOURCE_ROUTING(_Address, _Result) \
183 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
186 #define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
188 #define TR_IS_BROADCAST(_Address, _Result) \
190 *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
191 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
192 (*(UNALIGNED ULONG *)&(_Address)[2] == 0xFFFFFFFF)); \
195 #define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
197 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
201 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
203 *(_Result) = (UINT)-1; \
205 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
209 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
211 *(_Result) = (UINT)-1; \
219 #define TR_COPY_NETWORK_ADDRESS(_D, _S) \
221 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
222 *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
225 #define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
227 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
228 (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
242 #endif /* __XFILTER_H */