Upgrade to OpenVPN 2.1.0
[tomato.git] / release / src / router / openvpn / tap-win32 / proto.h
blobe0597725b47136d17987c41a593df12f1ba4231e
1 /*
2 * TAP-Win32/TAP-Win64 -- A kernel driver to provide virtual tap
3 * device functionality on Windows.
5 * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
7 * This source code is Copyright (C) 2002-2009 OpenVPN Technologies, Inc.,
8 * and is released under the GPL version 2 (see below).
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 //============================================================
26 // MAC address, Ethernet header, and ARP
27 //============================================================
29 #pragma pack(1)
31 #define IP_HEADER_SIZE 20
33 typedef unsigned char MACADDR [6];
34 typedef unsigned long IPADDR;
36 //-----------------
37 // Ethernet address
38 //-----------------
40 typedef struct {
41 MACADDR addr;
42 } ETH_ADDR;
44 typedef struct {
45 ETH_ADDR list[NIC_MAX_MCAST_LIST];
46 } MC_LIST;
48 //----------------
49 // Ethernet header
50 //----------------
52 typedef struct
54 MACADDR dest; /* destination eth addr */
55 MACADDR src; /* source ether addr */
57 # define ETH_P_IP 0x0800 /* IPv4 protocol */
58 # define ETH_P_ARP 0x0806 /* ARP protocol */
59 USHORT proto; /* packet type ID field */
60 } ETH_HEADER, *PETH_HEADER;
62 //----------------
63 // ARP packet
64 //----------------
66 typedef struct
68 MACADDR m_MAC_Destination; // Reverse these two
69 MACADDR m_MAC_Source; // to answer ARP requests
70 USHORT m_Proto; // 0x0806
72 # define MAC_ADDR_TYPE 0x0001
73 USHORT m_MAC_AddressType; // 0x0001
75 USHORT m_PROTO_AddressType; // 0x0800
76 UCHAR m_MAC_AddressSize; // 0x06
77 UCHAR m_PROTO_AddressSize; // 0x04
79 # define ARP_REQUEST 0x0001
80 # define ARP_REPLY 0x0002
81 USHORT m_ARP_Operation; // 0x0001 for ARP request, 0x0002 for ARP reply
83 MACADDR m_ARP_MAC_Source;
84 IPADDR m_ARP_IP_Source;
85 MACADDR m_ARP_MAC_Destination;
86 IPADDR m_ARP_IP_Destination;
88 ARP_PACKET, *PARP_PACKET;
90 //----------
91 // IP Header
92 //----------
94 typedef struct {
95 # define IPH_GET_VER(v) (((v) >> 4) & 0x0F)
96 # define IPH_GET_LEN(v) (((v) & 0x0F) << 2)
97 UCHAR version_len;
99 UCHAR tos;
100 USHORT tot_len;
101 USHORT id;
103 # define IP_OFFMASK 0x1fff
104 USHORT frag_off;
106 UCHAR ttl;
108 # define IPPROTO_UDP 17 /* UDP protocol */
109 # define IPPROTO_TCP 6 /* TCP protocol */
110 # define IPPROTO_ICMP 1 /* ICMP protocol */
111 # define IPPROTO_IGMP 2 /* IGMP protocol */
112 UCHAR protocol;
114 USHORT check;
115 ULONG saddr;
116 ULONG daddr;
117 /* The options start here. */
118 } IPHDR;
120 //-----------
121 // UDP header
122 //-----------
124 typedef struct {
125 USHORT source;
126 USHORT dest;
127 USHORT len;
128 USHORT check;
129 } UDPHDR;
131 //--------------------------
132 // TCP header, per RFC 793.
133 //--------------------------
135 typedef struct {
136 USHORT source; /* source port */
137 USHORT dest; /* destination port */
138 ULONG seq; /* sequence number */
139 ULONG ack_seq; /* acknowledgement number */
141 # define TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2)
142 UCHAR doff_res;
144 # define TCPH_FIN_MASK (1<<0)
145 # define TCPH_SYN_MASK (1<<1)
146 # define TCPH_RST_MASK (1<<2)
147 # define TCPH_PSH_MASK (1<<3)
148 # define TCPH_ACK_MASK (1<<4)
149 # define TCPH_URG_MASK (1<<5)
150 # define TCPH_ECE_MASK (1<<6)
151 # define TCPH_CWR_MASK (1<<7)
152 UCHAR flags;
154 USHORT window;
155 USHORT check;
156 USHORT urg_ptr;
157 } TCPHDR;
159 #define TCPOPT_EOL 0
160 #define TCPOPT_NOP 1
161 #define TCPOPT_MAXSEG 2
162 #define TCPOLEN_MAXSEG 4
164 #pragma pack()