Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers xfilter.h Source File

xfilter.h

00001 /*
00002  * xfilter.h
00003  *
00004  * Address filtering for NDIS MACs
00005  *
00006  * This file is part of the w32api package.
00007  *
00008  * Contributors:
00009  *   Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
00010  *
00011  * THIS SOFTWARE IS NOT COPYRIGHTED
00012  *
00013  * This source code is offered for use in the public domain. You may
00014  * use, modify or distribute it freely.
00015  *
00016  * This code is distributed in the hope that it will be useful but
00017  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
00018  * DISCLAIMED. This includes but is not limited to warranties of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00020  *
00021  */
00022 
00023 #ifndef __XFILTER_H
00024 #define __XFILTER_H
00025 
00026 #if __GNUC__ >=3
00027 #pragma GCC system_header
00028 #endif
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 #include "ntddk.h"
00035 
00036 
00037 #define ETH_LENGTH_OF_ADDRESS             6
00038 
00039 #define ETH_IS_BROADCAST(Address) \
00040   ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
00041 
00042 #define ETH_IS_MULTICAST(Address) \
00043   (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
00044 
00045 #define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
00046 { \
00047     if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
00048     { \
00049     *(_Result) = 1; \
00050     } \
00051     else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
00052     { \
00053     *(_Result) = (UINT)-1; \
00054     } \
00055     else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
00056     { \
00057     *(_Result) = 1; \
00058     } \
00059     else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
00060     { \
00061       *(_Result) = (UINT)-1; \
00062     } \
00063     else \
00064     { \
00065       *(_Result) = 0; \
00066     } \
00067 }
00068 
00069 #define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
00070 { \
00071     if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
00072     (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
00073     { \
00074     *(_Result) = 0; \
00075     } \
00076     else \
00077     { \
00078     *(_Result) = 1; \
00079     } \
00080 }
00081 
00082 #define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
00083 { \
00084     *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
00085     *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
00086 }
00087 
00088 #define FDDI_LENGTH_OF_LONG_ADDRESS       6
00089 #define FDDI_LENGTH_OF_SHORT_ADDRESS      2
00090 
00091 #define FDDI_IS_BROADCAST(Address, AddressLength, Result)   \
00092   *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
00093   (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
00094 
00095 #define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
00096   *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
00097 
00098 #define FDDI_IS_SMT(FcByte, Result) \
00099 { \
00100   *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
00101 }
00102 
00103 
00104 #define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
00105 { \
00106     if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
00107     { \
00108       *(_Result) = 1; \
00109     } \
00110     else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
00111     { \
00112       *(_Result) = (UINT)-1; \
00113     } \
00114     else if (_Length == 2) \
00115     { \
00116       *(_Result) = 0; \
00117     } \
00118     else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
00119     { \
00120       *(_Result) = 1; \
00121     } \
00122     else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
00123     { \
00124       *(_Result) = (UINT)-1; \
00125     } \
00126     else \
00127     { \
00128       *(_Result) = 0; \
00129     } \
00130 }
00131 
00132 #define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
00133 {                                                                   \
00134     if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
00135       (((_Length) == 2) || \
00136         (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
00137     { \
00138       *(_Result) = 0; \
00139     } \
00140     else \
00141     { \
00142       *(_Result) = 1; \
00143     } \
00144 }
00145 
00146 #define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
00147 { \
00148     PCHAR _D = (D); \
00149     PCHAR _S = (S); \
00150     UINT _C = (AddressLength); \
00151     for ( ; _C > 0 ; _D++, _S++, _C--) \
00152     { \
00153       *_D = *_S; \
00154     } \
00155 }
00156 
00157 #define TR_LENGTH_OF_FUNCTIONAL           4
00158 #define TR_LENGTH_OF_ADDRESS              6
00159 
00160 typedef ULONG TR_FUNCTIONAL_ADDRESS;
00161 typedef ULONG TR_GROUP_ADDRESS;
00162 
00163 #define TR_IS_NOT_DIRECTED(_Address, _Result) \
00164 { \
00165   *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
00166 }
00167 
00168 #define TR_IS_FUNCTIONAL(_Address, _Result) \
00169 { \
00170     *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
00171 }
00172 
00173 #define TR_IS_GROUP(_Address, _Result) \
00174 { \
00175   *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
00176 }
00177 
00178 #define TR_IS_SOURCE_ROUTING(_Address, _Result) \
00179 { \
00180   *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
00181 }
00182 
00183 #define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
00184 
00185 #define TR_IS_BROADCAST(_Address, _Result) \
00186 { \
00187     *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
00188         (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
00189         (*(UNALIGNED ULONG  *)&(_Address)[2] == 0xFFFFFFFF)); \
00190 }
00191 
00192 #define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
00193 { \
00194     if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
00195     { \
00196       *(_Result) = 1; \
00197     } \
00198     else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
00199     { \
00200       *(_Result) = (UINT)-1; \
00201     } \
00202     else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
00203     { \
00204       *(_Result) = 1; \
00205     } \
00206     else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
00207     { \
00208       *(_Result) = (UINT)-1; \
00209     } \
00210     else \
00211     { \
00212       *(_Result) = 0; \
00213     } \
00214 }
00215 
00216 #define TR_COPY_NETWORK_ADDRESS(_D, _S) \
00217 { \
00218     *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
00219     *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
00220 }
00221 
00222 #define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
00223 { \
00224     if ((*(ULONG UNALIGNED  *)&(_A)[2] == *(ULONG UNALIGNED  *)&(_B)[2]) && \
00225         (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
00226     { \
00227     *(_Result) = 0; \
00228     } \
00229     else \
00230     { \
00231     *(_Result) = 1; \
00232     } \
00233 }
00234 
00235 #ifdef __cplusplus
00236 }
00237 #endif
00238 
00239 #endif /* __XFILTER_H */