lwip in the windows operating environment to build

table of Contents

I. Introduction

Two, lwip architecture running in windows

Third, build environment

Four, lwip on windows transplant


I. Introduction

Article content learning Laona five old teacher "LwIP Web server design" training courses in the learning environment to build summary chapters, each speaking course content includes video recording and program source code, can be purchased as want to get the original tutorial.

Two, lwip architecture running in windows

LWIP between the underlying operating system layer there is a simulation sys_arch.c, so that the underlying operating system in the values ​​need to modify the operating system level simulation.

Third, build environment

1, install VS2010 crack method: https://wenku.baidu.com/view/0da247c2aa00b52acfc7ca76.html?re=view

VS Project Description: https://blog.csdn.net/luoweifu/article/details/48692267

2, the Winpcap installation, allowing boot from the start

3, install Wireshark

4, extract engineering package

5, configure the environment variables, configuration PCAP_DIR purpose here is to Lwip_Test environment variables can be found Wpcap library project

 

6, open the project directory is win-lwip \ contrib \ ports \ win32 \ msvc \ lwIP_Test.sln

 

7, project code parameter configuration, GUID can be viewed in wireshark, IP address needs in the local IP address with the same IP network segment, rather than the machine.

For the IP address and MAC address settings (see the video) there is a focus, usually we use the second configuration, so that one computer can be completed commissioning.

If you use the Ethernet address LwIP set our host and network card address same, then LwIP can access external hosts, external host can access LwIP, but can not access the local host LwIP, this is a limitation of winpcap.

If the NIC address used LwIP set our host and network card address is different then LwIP can not access external hosts, external host can not access LwIP, but the local host can access LwIP.

所有应用的开关在lwipcfg_msvc.h 文件中,要测试什么应用,直接把对应的宏定为1 就可以了:

 

 

四、lwip在windows上的移植

1、移植关键 --- Winpcap抓包

正常Windows上的TCPIP通讯是左边Application <---> TCPIP <----> 内核。但要在windows上移植使用lwip就不能再使用windows原始的TCPIP协议栈。要借助windows上的抓包原理来实现lwip的移植和使用,那比如在windows上使用wireshark抓包的时候其实依赖的是Winpcap(图圈出来部分),应用程序在从内核接收数据包或应用发送数据包的时候,其实是会拷贝一份调用Winpcap的API进行解析,实现抓包的功能,不会影响左边正常数据包的发送跟接收。

同样借助于Winpcap,将lwip放置在用户态,调用Winpcap的API来实现与windows内核网卡之间数据包的交互,lwip和wpcap.dll动态库作为windows上的一个进程

 

 

2、移植内容:三个头文件,三个网卡函数,一个任务,模拟层移植

  • 头文件移植:cc.h  /  perf.h / lwipopts.h
  •  网卡驱动

1)pbuf结构,POOL类型,RAM类型

2)libpcap函数,lwip数据包发送接收与Wincap的对接,用Wincap的API函数来实现lwip中的三个网卡函数

pcap_t * pcap_open_live(const char * device, int snaplen, int promisc, int to_ms, char * errbuf)
int pcap_dispatch(pcap_t * p, int cnt, pcap_handler callback, u_char * user)
u_char* pcap_next(pcap_t *, struct pcap_pkthdr *);
int  pcap_sendpacket(pcap_t *, const u_char *, int);

void low_level_init(struct netif *netif)
err_t low_level_output(struct netif *netif, struct pbuf *p)
struct pbuf *low_level_input(struct netif *netif)
  • 一个任务

1)内核初始化,tcpip_init内核初始化,创建内核处理线程

2)添加网卡管理结构,netif_add 添加一个网卡到内核,由内核管理

3)数据包处理与内核超时处理,内核线程tcpip_thread,负责处理邮箱中的数据包

发布了35 篇原创文章 · 获赞 22 · 访问量 1112

Guess you like

Origin blog.csdn.net/m0_37845735/article/details/104498178