LWIP network interface 网卡 初始化 以 STM32 为例子 后面会有 用 2G 或者4G 模块 用 PPP拨号的 形式 虚拟出网卡 所以先以 这个为 前提
2017-08-11 19:00
519 查看
LWIP network interface 网卡 初始化 以 STM32 为例子 后面会有 用 2G 或者4G 模块 用 PPP拨号的 形式 虚拟出网卡 所以先以 这个为 前提
LWIP 有 一个 结构体 是 描述 物理 接口 的 即 netif Struct, 大神朱工 对这个 有个 详细的 解释 :http://blog.csdn.net/zhzht19861011/article/details/6690534
LWIP 官网 对 这个 结构体 也有 详细 的 描述 :http://www.nongnu.org/lwip/2_0_x/structnetif.html
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/29/264b9b6e354f255df3684d2309e18783.png)
我 使用 的 代码 是 ST 官方 提供 的 演示例程 , 可以在 这里下载到 STM32F407 + DP83848
工程 打开路径 : C:\Users\admin\Desktop\STM32F4x7_ETH_LwIP_V1.1.0\Project\FreeRTOS\udptcp_echo_server_netconn\MDK-ARM
看看 ST 是怎么 定义 一个 网卡 变量 并 初始化的
首先看 定义 的 地方 :
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/29/b745312d5c6c591f61596a3532106cfe.png)
然后 看看 对 这个变量 怎么 初始化 的 。。
/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
struct ip_addr *netmask, struct ip_addr *gw,
void *state, err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif))
Adds your network interface to the netif_list. Allocate a struct
netif and pass a pointer to this structure as the first argument.
Give pointers to cleared ip_addr structures when using DHCP,
or fill them with sane numbers otherwise. The state pointer may be NULL.
The init function pointer must point to a initialization function for
your ethernet netif interface. The following code illustrates it's use.*/
netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
使用 了 netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); 这个 函数 对 这个 网卡 进行 了 初始化 。
这个 函数 是 LWIP 提供的 函数 ,我们 看一下 官方 的 解释 :http://www.nongnu.org/lwip/2_0_x/group__netif.html#gade5498543e74067f28cc6bef0209e3be
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/29/71c102d200c00cddeb31d119ccc56d94.png)
第一步 : 我 们 需要 先 定义 一个 netif Struct 类型 的变量
LWIP 有 一个 结构体 是 描述 物理 接口 的 即 netif Struct, 大神朱工 对这个 有个 详细的 解释 :http://blog.csdn.net/zhzht19861011/article/details/6690534
LWIP 官网 对 这个 结构体 也有 详细 的 描述 :http://www.nongnu.org/lwip/2_0_x/structnetif.html
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/29/264b9b6e354f255df3684d2309e18783.png)
我 使用 的 代码 是 ST 官方 提供 的 演示例程 , 可以在 这里下载到 STM32F407 + DP83848
工程 打开路径 : C:\Users\admin\Desktop\STM32F4x7_ETH_LwIP_V1.1.0\Project\FreeRTOS\udptcp_echo_server_netconn\MDK-ARM
看看 ST 是怎么 定义 一个 网卡 变量 并 初始化的
首先看 定义 的 地方 :
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/29/b745312d5c6c591f61596a3532106cfe.png)
然后 看看 对 这个变量 怎么 初始化 的 。。
/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
struct ip_addr *netmask, struct ip_addr *gw,
void *state, err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif))
Adds your network interface to the netif_list. Allocate a struct
netif and pass a pointer to this structure as the first argument.
Give pointers to cleared ip_addr structures when using DHCP,
or fill them with sane numbers otherwise. The state pointer may be NULL.
The init function pointer must point to a initialization function for
your ethernet netif interface. The following code illustrates it's use.*/
netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
使用 了 netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); 这个 函数 对 这个 网卡 进行 了 初始化 。
这个 函数 是 LWIP 提供的 函数 ,我们 看一下 官方 的 解释 :http://www.nongnu.org/lwip/2_0_x/group__netif.html#gade5498543e74067f28cc6bef0209e3be
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/29/71c102d200c00cddeb31d119ccc56d94.png)
第一步 : 我 们 需要 先 定义 一个 netif Struct 类型 的变量
相关文章推荐
- 当出现『SIOCADDRT: Network is unreachable』 这个错误时,肯定是由于 gw 后面接的 IP 无法直接与您的网域沟通 (Gateway 并不在你的网域内), 所以,赶紧检
- 3G网卡PPP拨号
- Code maturity level options 代码成熟度选项 [*]Prompt for development and/or incomplete code/drivers 显示尚在开发中或尚未完成的代码与驱动.除非你是测试人员或者开发者,否则请勿选择 我是开发者,所以选[*] Loadable module support 可加载模块支持 [*]Enable loadable module support 内核编译配置选项简介 (2.4.20-8
- LINUX 虚拟网卡tun例子
- linaro rk clm920-cn5_4G ppp拨号
- linux内核的子系统(或者说功能模块的)初始化
- Stm32外围模块编程初始化步骤
- LINUX 虚拟网卡tun例子
- linux下实现虚拟网卡TAP/TUN例子
- arm9+linux fl2440 GPRS SIM卡 模块 ppp拨号上网
- LINUX 虚拟网卡tun例子
- Android 建立PPP虚拟网卡实现上网功能
- LINUX 虚拟网卡tun例子——修改
- 对一个虚拟网卡驱动程序的剖析(三):网卡的初始化函数MiniportInitialize
- debian或者Ubuntu添加虚拟网卡
- GPRS-SIM900模块应用程序——ppp拨号上网
- double由于是双精度,所以比较大小不能直接用>,<或者=,需要使用BigDecimal,具体看例子
- OpenWrt 4G网卡拨号配置
- linux下实现虚拟网卡TAP/TUN例子