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.
27 * Address filtering for NDIS MACs
29 * This file is part of the w32api package.
32 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
34 * THIS SOFTWARE IS NOT COPYRIGHTED
36 * This source code is offered for use in the public domain. You may
37 * use, modify or distribute it freely.
39 * This code is distributed in the hope that it will be useful but
40 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
41 * DISCLAIMED. This includes but is not limited to warranties of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
48 #pragma GCC system_header
57 #define ETH_LENGTH_OF_ADDRESS 6
59 #define ETH_IS_BROADCAST(Address) \
60 ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
62 #define ETH_IS_MULTICAST(Address) \
63 (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
65 #define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
67 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
71 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
73 *(_Result) = (UINT)-1; \
75 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
79 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
81 *(_Result) = (UINT)-1; \
89 #define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
91 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
92 (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
102 #define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
104 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
105 *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
108 #define FDDI_LENGTH_OF_LONG_ADDRESS 6
109 #define FDDI_LENGTH_OF_SHORT_ADDRESS 2
111 #define FDDI_IS_BROADCAST(Address, AddressLength, Result) \
112 *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
113 (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
115 #define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
116 *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
118 #define FDDI_IS_SMT(FcByte, Result) \
120 *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
124 #define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
126 if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
130 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
132 *(_Result) = (UINT)-1; \
134 else if (_Length == 2) \
138 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
142 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
144 *(_Result) = (UINT)-1; \
152 #define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
154 if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
155 (((_Length) == 2) || \
156 (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
166 #define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
170 UINT _C = (AddressLength); \
171 for ( ; _C > 0 ; _D++, _S++, _C--) \
177 #define TR_LENGTH_OF_FUNCTIONAL 4
178 #define TR_LENGTH_OF_ADDRESS 6
180 typedef ULONG TR_FUNCTIONAL_ADDRESS;
181 typedef ULONG TR_GROUP_ADDRESS;
183 #define TR_IS_NOT_DIRECTED(_Address, _Result) \
185 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
188 #define TR_IS_FUNCTIONAL(_Address, _Result) \
190 *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
193 #define TR_IS_GROUP(_Address, _Result) \
195 *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
198 #define TR_IS_SOURCE_ROUTING(_Address, _Result) \
200 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
203 #define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
205 #define TR_IS_BROADCAST(_Address, _Result) \
207 *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
208 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
209 (*(UNALIGNED ULONG *)&(_Address)[2] == 0xFFFFFFFF)); \
212 #define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
214 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
218 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
220 *(_Result) = (UINT)-1; \
222 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
226 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
228 *(_Result) = (UINT)-1; \
236 #define TR_COPY_NETWORK_ADDRESS(_D, _S) \
238 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
239 *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
242 #define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
244 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
245 (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
259 #endif /* __XFILTER_H */