1、lwipwin32编译及运行软件
WinPcap_4_1_3、Visual Studio 2015、VMware(虚拟机网卡)。
lwipwin32使用VMware Network Adapter VMnet8网卡收发报文。不使用VMware网卡的话,在Window 10安装openvpn-install-2.4.8-I602-Win10也可,使用openvpn的虚拟网卡。
2、VMware Network Adapter VMnet8配置
右键点击需要共享的物理网卡,点击弹出菜单中的“Properties”。
在弹出的Properties对话框点击"Sharing" tab页,勾选“Allow ohter network users to connect through this computer's interrent connection”,在"Home networking connection:"下拉列表选择“VMware Virtual Ethernet Adapter for VMnet8”,如下所示:
VMware Virtual Ethernet Adapter for VMnet8网卡ip自动被设置为192.168.137.2,网关为192.168.137.1。
3、lwipwin32网络拓扑结构
lwipwin32网络拓扑结构如下,lwipwin32与VMware虚拟机一样,通过VMware Virtual Ethernet Adapter for VMnet8与主机通信。
4、lwipwin32 ip地址配置
在lwipwin32.c的init函数中修改lwipwin32的ip地址(ip)、子网掩码(mask)、网关(gw),如下所示:
5、运行lwipwin32
运行lwipwin32后,在控制台选择使用的网卡VMware Virtual Ethernet Adapter for VMnet8。(从名字区分不出VMware Virtual Ethernet Adapter for VMnet8,可以尝试选择2、3,然后在主机ping lwipwin32的ip地址)
此步骤相当于用Wireshark/tcpdump指定需要抓包的网卡,lwipwin32使用WinPcap抓取监听的网卡,从监听的网卡读取报文然后发送给lwip协议栈处理。
6、lwipwin32示例
ping示例,ping是tcp/ip协议栈的一部分,不需要编写应用程序代码,打开Windows 10的控制台,执行”ping 192.168.137.121“ (192.168.137.121为前面设置的lwipwin32的ip地址),结果如下:
http服务器示例,在lwipwin32\app中默认有两个简单的http服务器代码示例,本文使用http2.c;http2监听80端口,收到报文请求时,一律当作http的GET处理,返回一个简单的html报文给客户端,执行结果如下: