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), however due
9 * to the extra costs of supporting Windows Vista, OpenVPN Solutions
10 * LLC reserves the right to change the terms of the TAP-Win32/TAP-Win64
11 * license for versions 9.1 and higher prior to the official release of
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program (see the file COPYING included with this
25 * distribution); if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 //============================================================
30 // MAC address, Ethernet header, and ARP
31 //============================================================
35 #define IP_HEADER_SIZE 20
37 typedef unsigned char MACADDR
[6];
38 typedef unsigned long IPADDR
;
49 ETH_ADDR list
[NIC_MAX_MCAST_LIST
];
58 MACADDR dest
; /* destination eth addr */
59 MACADDR src
; /* source ether addr */
61 # define ETH_P_IP 0x0800 /* IPv4 protocol */
62 # define ETH_P_ARP 0x0806 /* ARP protocol */
63 USHORT proto
; /* packet type ID field */
64 } ETH_HEADER
, *PETH_HEADER
;
72 MACADDR m_MAC_Destination
; // Reverse these two
73 MACADDR m_MAC_Source
; // to answer ARP requests
74 USHORT m_Proto
; // 0x0806
76 # define MAC_ADDR_TYPE 0x0001
77 USHORT m_MAC_AddressType
; // 0x0001
79 USHORT m_PROTO_AddressType
; // 0x0800
80 UCHAR m_MAC_AddressSize
; // 0x06
81 UCHAR m_PROTO_AddressSize
; // 0x04
83 # define ARP_REQUEST 0x0001
84 # define ARP_REPLY 0x0002
85 USHORT m_ARP_Operation
; // 0x0001 for ARP request, 0x0002 for ARP reply
87 MACADDR m_ARP_MAC_Source
;
88 IPADDR m_ARP_IP_Source
;
89 MACADDR m_ARP_MAC_Destination
;
90 IPADDR m_ARP_IP_Destination
;
92 ARP_PACKET
, *PARP_PACKET
;
99 # define IPH_GET_VER(v) (((v) >> 4) & 0x0F)
100 # define IPH_GET_LEN(v) (((v) & 0x0F) << 2)
107 # define IP_OFFMASK 0x1fff
112 # define IPPROTO_UDP 17 /* UDP protocol */
113 # define IPPROTO_TCP 6 /* TCP protocol */
114 # define IPPROTO_ICMP 1 /* ICMP protocol */
115 # define IPPROTO_IGMP 2 /* IGMP protocol */
121 /* The options start here. */
135 //--------------------------
136 // TCP header, per RFC 793.
137 //--------------------------
140 USHORT source
; /* source port */
141 USHORT dest
; /* destination port */
142 ULONG seq
; /* sequence number */
143 ULONG ack_seq
; /* acknowledgement number */
145 # define TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2)
148 # define TCPH_FIN_MASK (1<<0)
149 # define TCPH_SYN_MASK (1<<1)
150 # define TCPH_RST_MASK (1<<2)
151 # define TCPH_PSH_MASK (1<<3)
152 # define TCPH_ACK_MASK (1<<4)
153 # define TCPH_URG_MASK (1<<5)
154 # define TCPH_ECE_MASK (1<<6)
155 # define TCPH_CWR_MASK (1<<7)
165 #define TCPOPT_MAXSEG 2
166 #define TCPOLEN_MAXSEG 4