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 //============================================================
31 #define IP_HEADER_SIZE 20
33 typedef unsigned char MACADDR
[6];
34 typedef unsigned long IPADDR
;
45 ETH_ADDR list
[NIC_MAX_MCAST_LIST
];
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
;
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
;
95 # define IPH_GET_VER(v) (((v) >> 4) & 0x0F)
96 # define IPH_GET_LEN(v) (((v) & 0x0F) << 2)
103 # define IP_OFFMASK 0x1fff
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 */
117 /* The options start here. */
131 //--------------------------
132 // TCP header, per RFC 793.
133 //--------------------------
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)
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)
161 #define TCPOPT_MAXSEG 2
162 #define TCPOLEN_MAXSEG 4