资源简介
如何调用虚拟网卡程序,提供了tap的简单的调用方法,以及如何使用。
代码片段和文件信息
/*
* TAP-Win32 -- A kernel driver to provide virtual tap device functionality
* on Windows. Originally derived from the CIPE-Win32
* project by Damion K. Wilson with extensive modifications by
* James Yonan.
*
* All source code which derives from the CIPE-Win32 project is
* Copyright (C) Damion K. Wilson 2003 and is released under the
* GPL version 2 (see below).
*
* All other source code is Copyright (C) 2002-2005 OpenVPN Solutions LLC
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING included with this
* distribution); if not write to the Free Software Foundation Inc.
* 59 Temple Place Suite 330 Boston MA 02111-1307 USA
*/
//=========================
// Code to set DHCP options
//=========================
VOID
SetDHCPOpt (DHCPMsg *m void *data unsigned int len)
{
if (!m->overflow)
{
if (m->optlen + len <= DHCP_OPTIONS_BUFFER_SIZE)
{
if (len)
{
NdisMoveMemory (m->msg.options + m->optlen data len);
m->optlen += len;
}
}
else
{
m->overflow = TRUE;
}
}
}
VOID
SetDHCPOpt0 (DHCPMsg *msg int type)
{
DHCPOPT0 opt;
opt.type = (UCHAR) type;
SetDHCPOpt (msg &opt sizeof (opt));
}
VOID
SetDHCPOpt8 (DHCPMsg *msg int type ULONG data)
{
DHCPOPT8 opt;
opt.type = (UCHAR) type;
opt.len = sizeof (opt.data);
opt.data = (UCHAR) data;
SetDHCPOpt (msg &opt sizeof (opt));
}
VOID
SetDHCPOpt32 (DHCPMsg *msg int type ULONG data)
{
DHCPOPT32 opt;
opt.type = (UCHAR) type;
opt.len = sizeof (opt.data);
opt.data = data;
SetDHCPOpt (msg &opt sizeof (opt));
}
//==============
// Checksum code
//==============
USHORT
ip_checksum (const UCHAR *buf const int len_ip_header)
{
USHORT word16;
ULONG sum = 0;
int i;
// make 16 bit words out of every two adjacent 8 bit words in the packet
// and add them up
for (i = 0; i < len_ip_header - 1; i += 2) {
word16 = ((buf[i] << 8) & 0xFF00) + (buf[i+1] & 0xFF);
sum += (ULONG) word16;
}
// take only 16 bits out of the 32 bit sum and add up the carries
while (sum >> 16)
sum = (sum & 0xFFFF) + (sum >> 16);
// one‘s complement the result
return ((USHORT) ~sum);
}
USHORT
udp_checksum (const UCHAR *buf
const int len_udp
const UCHAR *src_addr
const UCHAR *dest_addr)
{
USHORT word16;
ULONG sum = 0;
int i;
// make 16 bit words out of ev
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6857 2006-10-01 19:59 tap-win32\amd64\OemWin2k.inf
文件 474 2006-10-01 19:59 tap-win32\amd64\tap.cat
文件 6022 2010-11-12 11:56 tap-win32\buildchk_wxp_x86.log
文件 642 2010-11-12 11:56 tap-win32\buildchk_wxp_x86.wrn
文件 3341 2006-10-01 19:59 tap-win32\common.h
文件 2371 2006-10-01 19:59 tap-win32\constants.h
文件 14990 2006-10-01 19:59 tap-win32\dhcp.c
文件 5033 2006-10-01 19:59 tap-win32\dhcp.h
文件 1595 2006-10-01 19:59 tap-win32\endian.h
文件 8741 2006-10-01 19:59 tap-win32\error.c
文件 2556 2006-10-01 19:59 tap-win32\error.h
文件 2306 2006-10-01 19:59 tap-win32\hexdump.c
文件 2309 2006-10-01 19:59 tap-win32\hexdump.h
文件 6840 2006-10-01 19:59 tap-win32\i386\OemWin2k.inf
文件 474 2006-10-01 19:59 tap-win32\i386\tap.cat
文件 5662 2006-10-01 19:59 tap-win32\instance.c
文件 3517 2006-10-01 19:59 tap-win32\lock.h
文件 4027 2006-10-01 19:59 tap-win32\macinfo.c
文件 1938 2006-10-01 19:59 tap-win32\macinfo.h
文件 241 2006-10-01 19:59 tap-win32\MAKEFILE
文件 3903 2006-10-01 19:59 tap-win32\mem.c
文件 3366 2010-11-12 11:56 tap-win32\objchk_wxp_x86\i386\RCa02812
文件 280 2010-11-12 11:56 tap-win32\objchk_wxp_x86\i386\_ob
文件 4518 2006-10-01 19:59 tap-win32\proto.h
文件 4569 2006-10-01 19:59 tap-win32\prototypes.h
文件 1550 2006-10-01 19:59 tap-win32\resource.rc
文件 2230 2010-11-12 12:53 tap-win32\SOURCES
文件 82237 2006-10-01 19:59 tap-win32\tapdrvr.c
文件 4541 2006-10-01 19:59 tap-win32\types.h
目录 0 2011-01-21 09:26 tap-win32\objchk_wxp_x86\i386
............此处省略7个文件信息
评论
共有 条评论