ReactOS 0.4.15-dev-7994-gb388cb6
ethernetutils.h
Go to the documentation of this file.
1/*
2 * Contains common Ethernet-related definition, not defined in NDIS
3 *
4 * Copyright (c) 2008-2017 Red Hat, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met :
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and / or other materials provided with the distribution.
14 * 3. Neither the names of the copyright holders nor the names of their contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29#ifndef _ETHERNET_UTILS_H
30#define _ETHERNET_UTILS_H
31
32// assuming <ndis.h> included
33
34
35#define ETH_IS_LOCALLY_ADMINISTERED(Address) \
36 (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x02))
37
38#define ETH_IS_EMPTY(Address) \
39 ((((PUCHAR)(Address))[0] == ((UCHAR)0x00)) && (((PUCHAR)(Address))[1] == ((UCHAR)0x00)) && (((PUCHAR)(Address))[2] == ((UCHAR)0x00)) && (((PUCHAR)(Address))[3] == ((UCHAR)0x00)) && (((PUCHAR)(Address))[4] == ((UCHAR)0x00)) && (((PUCHAR)(Address))[5] == ((UCHAR)0x00)))
40
41#define ETH_HAS_PRIO_HEADER(Address) \
42 (((PUCHAR)(Address))[12] == ((UCHAR)0x81) && ((PUCHAR)(Address))[13] == ((UCHAR)0x00))
43
44#include <pshpack1.h>
45typedef struct _ETH_HEADER
46{
51#include <poppack.h>
52
53#define ETH_HEADER_SIZE (sizeof(ETH_HEADER))
54#define ETH_MIN_PACKET_SIZE 60
55#define ETH_PRIORITY_HEADER_OFFSET 12
56#define ETH_PRIORITY_HEADER_SIZE 4
57
58
60{
61 pDest[0] = 0x81;
62 pDest[2] = (UCHAR)(priority << 5);
63 pDest[2] |= (UCHAR)(VlanID >> 8);
64 pDest[3] |= (UCHAR)VlanID;
65}
66
68{
74
75// IP Header RFC 791
76typedef struct _tagIPv4Header {
77 UCHAR ip_verlen; // length in 32-bit units(low nibble), version (high nibble)
78 UCHAR ip_tos; // Type of service
79 USHORT ip_length; // Total length
80 USHORT ip_id; // Identification
81 USHORT ip_offset; // fragment offset and flags
82 UCHAR ip_ttl; // Time to live
83 UCHAR ip_protocol; // Protocol
84 USHORT ip_xsum; // Header checksum
85 ULONG ip_src; // Source IP address
86 ULONG ip_dest; // Destination IP address
88
89// TCP header RFC 793
90typedef struct _tagTCPHeader {
91 USHORT tcp_src; // Source port
92 USHORT tcp_dest; // Destination port
93 ULONG tcp_seq; // Sequence number
94 ULONG tcp_ack; // Ack number
95 USHORT tcp_flags; // header length and flags
96 USHORT tcp_window; // Window size
97 USHORT tcp_xsum; // Checksum
98 USHORT tcp_urgent; // Urgent
100
101
102// UDP Header RFC 768
103typedef struct _tagUDPHeader {
104 USHORT udp_src; // Source port
105 USHORT udp_dest; // Destination port
106 USHORT udp_length; // length of datagram
107 USHORT udp_xsum; // checksum
109
110
111
112#define TCP_CHECKSUM_OFFSET 16
113#define UDP_CHECKSUM_OFFSET 6
114#define MAX_IPV4_HEADER_SIZE 60
115#define MAX_TCP_HEADER_SIZE 60
116
117static __inline USHORT swap_short(USHORT us)
118{
119 return (us << 8) | (us >> 8);
120}
121
122
123#endif
#define ETH_LENGTH_OF_ADDRESS
Definition: efilter.h:16
struct _tagTCPHeader TCPHeader
struct _ETH_HEADER ETH_HEADER
enum _tag_eInspectedPacketType eInspectedPacketType
struct _tagUDPHeader UDPHeader
_tag_eInspectedPacketType
Definition: ethernetutils.h:68
@ iptUnicast
Definition: ethernetutils.h:69
@ iptMulticast
Definition: ethernetutils.h:71
@ iptBroadcast
Definition: ethernetutils.h:70
@ iptInvalid
Definition: ethernetutils.h:72
struct _tagIPv4Header IPv4Header
static __inline USHORT swap_short(USHORT us)
static void FORCEINLINE SetPriorityData(UCHAR *pDest, ULONG priority, ULONG VlanID)
Definition: ethernetutils.h:59
struct _ETH_HEADER * PETH_HEADER
static const BYTE us[]
Definition: encode.c:689
static int priority
Definition: timer.c:163
unsigned short USHORT
Definition: pedump.c:61
UCHAR SrcAddr[ETH_LENGTH_OF_ADDRESS]
Definition: ethernetutils.h:48
USHORT EthType
Definition: ethernetutils.h:49
UCHAR DstAddr[ETH_LENGTH_OF_ADDRESS]
Definition: ethernetutils.h:47
USHORT tcp_urgent
Definition: ethernetutils.h:98
USHORT tcp_window
Definition: ethernetutils.h:96
USHORT tcp_flags
Definition: ethernetutils.h:95
uint32_t ULONG
Definition: typedefs.h:59
#define FORCEINLINE
Definition: wdftypes.h:67
unsigned char UCHAR
Definition: xmlstorage.h:181