4 * Address filtering for NDIS MACs
6 * This file is part of the w32api package.
9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
11 * THIS SOFTWARE IS NOT COPYRIGHTED
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
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.
25 #pragma GCC system_header
34 #define ETH_LENGTH_OF_ADDRESS 6
36 #define ETH_IS_BROADCAST(Address) \
37 ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
39 #define ETH_IS_MULTICAST(Address) \
40 (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
42 #define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
44 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
48 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
50 *(_Result) = (UINT)-1; \
52 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
56 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
58 *(_Result) = (UINT)-1; \
66 #define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
68 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
69 (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
79 #define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
81 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
82 *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
85 #define FDDI_LENGTH_OF_LONG_ADDRESS 6
86 #define FDDI_LENGTH_OF_SHORT_ADDRESS 2
88 #define FDDI_IS_BROADCAST(Address, AddressLength, Result) \
89 *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
90 (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
92 #define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
93 *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
95 #define FDDI_IS_SMT(FcByte, Result) \
97 *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
101 #define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
103 if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
107 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
109 *(_Result) = (UINT)-1; \
111 else if (_Length == 2) \
115 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
119 else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
121 *(_Result) = (UINT)-1; \
129 #define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
131 if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
132 (((_Length) == 2) || \
133 (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
143 #define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
147 UINT _C = (AddressLength); \
148 for ( ; _C > 0 ; _D++, _S++, _C--) \
154 #define TR_LENGTH_OF_FUNCTIONAL 4
155 #define TR_LENGTH_OF_ADDRESS 6
157 typedef ULONG TR_FUNCTIONAL_ADDRESS;
158 typedef ULONG TR_GROUP_ADDRESS;
160 #define TR_IS_NOT_DIRECTED(_Address, _Result) \
162 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
165 #define TR_IS_FUNCTIONAL(_Address, _Result) \
167 *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
170 #define TR_IS_GROUP(_Address, _Result) \
172 *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
175 #define TR_IS_SOURCE_ROUTING(_Address, _Result) \
177 *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
180 #define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
182 #define TR_IS_BROADCAST(_Address, _Result) \
184 *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
185 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
186 (*(UNALIGNED ULONG *)&(_Address)[2] == 0xFFFFFFFF)); \
189 #define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
191 if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
195 else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
197 *(_Result) = (UINT)-1; \
199 else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
203 else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
205 *(_Result) = (UINT)-1; \
213 #define TR_COPY_NETWORK_ADDRESS(_D, _S) \
215 *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
216 *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
219 #define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
221 if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
222 (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
236 #endif /* __XFILTER_H */