Welcome to mirror list, hosted at ThFree Co, Russian Federation.

xfilter.h « ddk « include « w32api « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3940b44f2cf54132ebe87e5caffc1a4b6b254571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * xfilter.h
 *
 * Address filtering for NDIS MACs
 *
 * This file is part of the w32api package.
 *
 * Contributors:
 *   Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
 *
 * THIS SOFTWARE IS NOT COPYRIGHTED
 *
 * This source code is offered for use in the public domain. You may
 * use, modify or distribute it freely.
 *
 * This code is distributed in the hope that it will be useful but
 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
 * DISCLAIMED. This includes but is not limited to warranties of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 */

#ifndef __XFILTER_H
#define __XFILTER_H

#if __GNUC__ >=3
#pragma GCC system_header
#endif

#ifdef __cplusplus
extern "C" {
#endif

#include "ntddk.h"


#define ETH_LENGTH_OF_ADDRESS             6

#define ETH_IS_BROADCAST(Address) \
  ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))

#define ETH_IS_MULTICAST(Address) \
  (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))

#define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
{ \
	if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
	{ \
    *(_Result) = 1; \
	} \
	else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
	{ \
    *(_Result) = (UINT)-1; \
	} \
	else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
	{ \
    *(_Result) = 1; \
	} \
	else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
	{ \
	  *(_Result) = (UINT)-1; \
	} \
	else \
	{ \
	  *(_Result) = 0; \
	} \
}

#define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
{ \
	if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
    (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
	{ \
    *(_Result) = 0; \
	} \
	else \
	{ \
    *(_Result) = 1; \
	} \
}

#define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
{ \
	*((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
	*((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
}

#define FDDI_LENGTH_OF_LONG_ADDRESS       6
#define FDDI_LENGTH_OF_SHORT_ADDRESS      2

#define FDDI_IS_BROADCAST(Address, AddressLength, Result)   \
  *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
  (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))

#define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
  *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)

#define FDDI_IS_SMT(FcByte, Result) \
{ \
  *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
}


#define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
{ \
	if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
	{ \
	  *(_Result) = 1; \
	} \
	else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
	{ \
	  *(_Result) = (UINT)-1; \
	} \
	else if (_Length == 2) \
	{ \
	  *(_Result) = 0; \
	} \
	else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
	{ \
	  *(_Result) = 1; \
	} \
	else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
	{ \
	  *(_Result) = (UINT)-1; \
	} \
	else \
	{ \
	  *(_Result) = 0; \
	} \
}

#define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
{                                                                   \
	if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
	  (((_Length) == 2) || \
	    (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
	{ \
	  *(_Result) = 0; \
	} \
	else \
	{ \
	  *(_Result) = 1; \
	} \
}

#define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
{ \
	PCHAR _D = (D); \
	PCHAR _S = (S); \
	UINT _C = (AddressLength); \
	for ( ; _C > 0 ; _D++, _S++, _C--) \
	{ \
	  *_D = *_S; \
	} \
}

#define TR_LENGTH_OF_FUNCTIONAL           4
#define TR_LENGTH_OF_ADDRESS              6

typedef ULONG TR_FUNCTIONAL_ADDRESS;
typedef ULONG TR_GROUP_ADDRESS;

#define TR_IS_NOT_DIRECTED(_Address, _Result) \
{ \
  *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
}

#define TR_IS_FUNCTIONAL(_Address, _Result) \
{ \
	*(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
}

#define TR_IS_GROUP(_Address, _Result) \
{ \
  *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
}

#define TR_IS_SOURCE_ROUTING(_Address, _Result) \
{ \
  *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
}

#define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)

#define TR_IS_BROADCAST(_Address, _Result) \
{ \
	*(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
		(*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
		(*(UNALIGNED ULONG  *)&(_Address)[2] == 0xFFFFFFFF)); \
}

#define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
{ \
	if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
	{ \
	  *(_Result) = 1; \
	} \
	else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
	{ \
	  *(_Result) = (UINT)-1; \
	} \
	else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
	{ \
	  *(_Result) = 1; \
	} \
	else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
	{ \
	  *(_Result) = (UINT)-1; \
	} \
	else \
	{ \
	  *(_Result) = 0; \
	} \
}

#define TR_COPY_NETWORK_ADDRESS(_D, _S) \
{ \
	*((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
	*((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
}

#define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
{ \
	if ((*(ULONG UNALIGNED  *)&(_A)[2] == *(ULONG UNALIGNED  *)&(_B)[2]) && \
	    (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
	{ \
    *(_Result) = 0; \
	} \
	else \
	{ \
    *(_Result) = 1; \
	} \
}

#ifdef __cplusplus
}
#endif

#endif /* __XFILTER_H */