LwIP 2.1.0學習摘要

參考:lwIP Wiki | FANDOM powered by Wikia

參考:lwIP: Overview

參考:LwIP源代碼文件目錄解析 - jrunw的博客 - CSDN博客

參考:LwIP協(xié)議棧開發(fā)嵌入式網(wǎng)絡的三種方法分析 - wangyw - 博客園

參考:LWIP使用經(jīng)驗---變態(tài)級(好文章) - yangzhao0001的博客 - CSDN博客

參考:《LwIP協(xié)議棧源碼詳解——TCP/IP協(xié)議的實現(xiàn)》TCP堅持與保活定時器 - bian1029的專欄 - CSDN博客

參考:《嵌入式網(wǎng)絡那些事Lwip深度剖析與實戰(zhàn)演練》

項目Git路徑:lwip.git - lwIP - A Lightweight TCPIP stack


一.簡介

LwIP是原本由Swedish Institute of Computer Science (SICS)的Adam Dunkels開發(fā),現(xiàn)在是由以Kieran Mansley為首的來自世界各地的開發(fā)者積極推進的一款獨立的TCP/IP協(xié)議組件。

LwIP遵從BSD license,致力于全面實現(xiàn)TCP協(xié)議的同時減少RAM的使用量。所以LwIP特別適用于在嵌入式系統(tǒng)上運行,一般需要數(shù)十KByte的RAM和40KByte左右的ROM空間。LwIP已移植到多個平臺或操作系統(tǒng)上,它既能夠運行在有操作系統(tǒng)的環(huán)境中,亦可運行于沒有操作系統(tǒng)的裸機環(huán)境。

LwIP支持下述各種協(xié)議:

IP (Internet Protocol) including packet forwarding over multiple network interfaces

ICMP (Internet Control Message Protocol) for network maintenance and debugging

IGMP (Internet Group Management Protocol) for multicast traffic management

UDP (User Datagram Protocol) including experimental UDP-lite extensions

TCP (Transmission Control Protocol) with congestion control, RTT estimation and fast recovery/fast retransmit

Raw/native API for enhanced performance

Optional Berkeley-like socket API

DNS (Domain names resolver)

SNMP (Simple Network Management Protocol)

DHCP (Dynamic Host Configuration Protocol)

AUTOIP (for IPv4, conform withRFC 3927)

PPP (Point-to-Point Protocol)

ARP (Address Resolution Protocol) for Ethernet

LwIP為用戶提供三組API接口,

sequential API(Netconn API)?為普通的、順序的程序提供了使用lwIP棧的方法。依賴操作系統(tǒng),所有操作都需要協(xié)議棧去處理,應用程序與協(xié)議棧通信,通過發(fā)送消息方式進行,因此這種方式會造成頻繁的任務切換,速度相比RAW API慢了許多。在操作系統(tǒng)上推薦使用本API。

BSD Socket API ?建立在sequential API之上的,封裝出的一套BSD Socket API。同樣依賴操作系統(tǒng),效率低,消耗的資源更多。

Raw API(native API / callback) 基于零拷貝發(fā)送和接收的事件驅(qū)動的API,在沒有操作系統(tǒng)的情況下唯一可用的API。操作較復雜但速度最快,效率最高。

※三種API的詳細區(qū)別可參考:lwIP: APIs


二.使用方法

1.無操作系統(tǒng)模式

1)無OS宏定義:#define NO_SYS to 1

2)在主循環(huán)中將接收到的packet傳入netif->input(pbuf, netif),不要在中斷中進行調(diào)用??梢钥紤]在中斷中開辟PBUF空間,然后將其放在隊列中待主循環(huán)處理

3)主循環(huán)中定期調(diào)用sys_check_timeouts() ?

4)實現(xiàn)這幾個模塊的所有函數(shù):Time, Critical sections and Compiler/platform abstraction

5)此模式下只能使用Raw API

6)此模式下使用lwip_init()

※詳見:lwIP: Mainloop mode ("NO_SYS")


2.操作系統(tǒng)模式

1)選擇一款能夠正確處理優(yōu)先級反轉(zhuǎn)(priority inversion)的OS,并#define LWIP_TCPIP_CORE_LOCKING???1

2)實現(xiàn)Porting (system abstraction layer)的所有函數(shù)

3)可以搭配使用Raw APItcpip_callback,或者直接使用sequential API

4)此模式下使用tcpip_init()

※詳見:lwIP: OS mode (TCPIP thread)


三.目錄結構

LwIP

|-- doc 文檔

|-- test 測試case

|-- src 源碼

? ? ? |-- api ? ? ? ? ? ? ? ? ? ? ? ? ? ?? high-level API接口(sequential API、BSD Socket API )如果只是使用Raw API,則不需要該目錄。

?????????????? |-- api_lib.c ? ? ? ? ?? Sequential API External module

?????????????? |-- api_msg.c?????????Sequential API Internal module

?????????????? |-- err.c????????????????? Error Management module

?????????????? |-- if_api.c????????????? Interface Identification APIs from:

????????????????????????????????????????????RFC 3493: Basic Socket Interface Extensions for IPv6

????????????????????????????????????????????Section 4: Interface Identification

?????????????? |-- netbuf.c ? ? ? ? ?? Network buffer management

?????????????? |-- netdb.c ? ? ? ? ? ? API functions for name resolving

?????????????? |-- netifapi.c ? ? ? ?? Network Interface Sequential API module

?????????????? |-- sockets.c?????????Sockets BSD-Like API module

?????????????? |-- tcpip.c ? ? ? ? ? ? Sequential API Main thread module

? ? ? |-- apps ? ? ? ? ? ? ? ? ? ? ? ? 特別采用low-level Raw API編寫的應用例程。

? ? ? |-- core ? ? ? ? ? ? ? ? ? ? ? ?? TPC/IP協(xié)議棧內(nèi)核、協(xié)議實現(xiàn)、內(nèi)存/緩存管理、low-level Raw API。

?????????????? |-- ipv4??????????????????包含了IPv4標準中與IP層數(shù)據(jù)包處理相關的所有代碼

?????????????? |-- ipv6????????????????? 包含了IPv6標準中與IP層數(shù)據(jù)包處理相關的所有代碼

?????????????? |-- altcp_alloc.c?????Application layered TCP connection API (to be used from TCPIP thread)

????????????????????????????????????????????This interface mimics the tcp callback API to the application while preventing

????????????????????????????????????????????direct linking (much like virtual functions).

????????????????????????????????????????????This way, an application can make use of other application layer protocols

????????????????????????????????????????????on top of TCP without knowing the details (e.g. TLS, proxy connection).

????????????????????????????????????????????This file contains allocation implementation that combine several layers.

?????????????? |-- altcp_tcp.c ? ? ?? Application layered TCP connection API (to be used from TCPIP thread)\n

????????????????????????????????????????????This interface mimics the tcp callback API to the application while preventing

????????????????????????????????????????????direct linking (much like virtual functions).

????????????????????????????????????????????This way, an application can make use of other application layer protocols

????????????????????????????????????????????on top of TCP without knowing the details (e.g. TLS, proxy connection).

????????????????????????????????????????????This file contains the base implementation calling into tcp.

? ? ? ? ? ? ?? |-- altcp.c????????????? common functions for altcp(application layered TCP connection API; to be used from TCPIP thread) to work

?????????????? |-- def.c ? ? ? ? ? ? ? ? Common functions used throughout the stack(如lwip_htons、lwip_htonl)

?????????????? |-- dns.c ? ? ? ? ? ? ?? DNS - host name to IP address resolver

?????????????? |-- inet_chksum.c ? Internet checksum functions

?????????????? |-- init.c Modules ?? initialization

?????????????? |-- ip.c????????????????? Common IPv4 and IPv6 code

?????????????? |-- mem.c ? ? ? ? ?? Dynamic memory manager

?????????????? |-- memp.c ? ? ? ?? Dynamic pool memory manager

?????????????? |-- netif.c????????????? lwIP network interface abstraction

?????????????? |-- pbuf.c????????????? Packet buffer management

?????????????? |-- raw.c????????????? Implementation of raw protocol PCBs for low-level handling of

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? different types of protocols besides (or overriding) those

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? already available in lwIP.

?????????????? |-- stats.c ? ? ? ? ? Statistics module. 主要用來統(tǒng)計調(diào)試。

?????????????? |-- sys.c????????????? lwIP Operating System abstraction

?????????????? |-- tcp.c????????????? Transmission Control Protocol for IP

?????????????? |-- tcp_in.c ? ? ? ? Transmission Control Protocol, incoming traffic

????????????????????????????????????????The input processing functions of the TCP layer.

????????????????????????????????????????These functions are generally called in the order (ip_input() ->)

????????????????????????????????????????tcp_input() -> * tcp_process() -> tcp_receive() (-> application).

?????????????? |-- tcp_out.c?????Transmission Control Protocol, outgoing traffic

????????????????????????????????????????The output functions of TCP.

?????????????? |-- timeout.c?????Stack-internal timers implementation.

????????????????????????????????????????This file includes timer callbacks for stack-internal timers as well as

????????????????????????????????????????functions to set up or stop timers and check for expired timers.

?????????????? |-- udp.c ? ? ? ? ? User Datagram Protocol module

????????????????????????????????????????The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).

??????????????|-- include????????? lwIP頭文件.

?????????????????????? |-- compat????????????????? 兼容

????????????????????????????????? |-- posix?????????POSIX標準下的封裝

??????????????????????????????????|-- stdc ? ? ? ? ? posix/stdc的封裝

?????????????????????? |-- netif ? ?? 針對netif目錄中源文件的各種頭文件

?????????????????????? |-- lwip????? LwIP的各種頭文件,其中需要注意的有opt.h 文件,它包含了所有LwIP內(nèi)核參數(shù)的默認配置值;

????????????????????????????????????????還有init.h 文件,它包含了與當前 LwIP 源代碼信息相關的宏定義,如協(xié)議版本號、是否為官方版等

??????????????|-- netif?????????????? 通用的網(wǎng)絡接口設備驅(qū)動(不包含任何硬件和平臺相關代碼)

?????????????????????? |-- ppp????? Point-to-Point Protocol stack

????????????????????????????????????????The lwIP PPP support is based from pppd (http://ppp.samba.org) with

????????????????????????????????????????huge changes to match code size and memory requirements for embedded devices.

?????????????????????? |-- bridgeif.c ? ? ? ? ? ? ? ? ? ? ? ?? implementing an IEEE 802.1D MAC Bridge

?????????????????????? |-- bridgeif_fdb.c ? ? ? ? ? ? ? ? ? implementing an FDB for IEEE 802.1D MAC Bridge

?????????????????????? |-- ethernet.c?????????????????????????Shared code for Ethernet based interfaces.

?????????????????????? |-- lowpan6.c?????????????????????????A 6LoWPAN implementation as a netif.

?????????????????????? |-- lowpan6_common.c?????????A 6LoWPAN over Bluetooth Low Energy (BLE) implementation as netif,? according to RFC-7668.

?????????????????????? |-- slipif.c ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? A generic implementation of the SLIP (Serial Line IP)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? protocol. It requires a sio (serial I/O) module to work.

?????????????????????? |-- zepif.c????????????????????????????? implementing the ZigBee Encapsulation Protocol (ZEP).


四.LwIP啟動過程



LwIP啟動過程


五.源碼分析

1.內(nèi)存管理

LwIP支持內(nèi)存池memp和內(nèi)存堆mem兩種內(nèi)存管理方式。

內(nèi)存池的特點是預先開辟多組固定大小的內(nèi)存塊組織成鏈表,實現(xiàn)簡單,分配和回收速度快,不會產(chǎn)生內(nèi)存碎片,但是大小固定,并且需要預估算準確。

內(nèi)存堆的本質(zhì)是對一個事先定義好的內(nèi)存塊進行合理有效的組織和管理,主要用于任意大小的內(nèi)存分配,實現(xiàn)較復雜,分配需要查找,回收需要合并,容易產(chǎn)生內(nèi)存碎片,需要合理估算內(nèi)存堆的總大小。


Packet buffers(pbufs)

pbuf是LwIP中數(shù)據(jù)包的內(nèi)部存儲方式,類似于BSD的mbuf。同時支持使用動態(tài)內(nèi)存保存包內(nèi)容,以及使用靜態(tài)內(nèi)存保存內(nèi)容。

/**?Main packet buffer */

struct pbuf {

????struct pbuf *next; ? ? ? /** 指向下一個pbuf */

????void *payload; ? ? ? ? ?? /** 指向載荷的起始地址 */

????u16_t tot_len;???????????? /** 本buffer的長度加上屬于同一個packet的buffer長度的總和。

????????????????????????????????????????????For non-queue packet chains this is the invariant: p->tot_len == p->len + (p->next? p->next->tot_len: 0) */

????u16_t len; ? ? ? ? ? ? ? ? ? /** 本buffer的長度 */

????u8_t type_internal;?????/** 用來表示pbuf類型以及資源分配的位域。

????????????????????????????????????????? (see PBUF_TYPE_FLAG_*, PBUF_ALLOC_FLAG_* and PBUF_TYPE_ALLOC_SRC_MASK) ?? */

????u8_t flags; ? ? ? ? ? ? ? ? ?/** misc flags */

????LWIP_PBUF_REF_T ref;????/**? 本pbuf的參考引用計數(shù)。初始為1,大于1時無法刪除。

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? This can be pointers from an application, the stack itself, or pbuf->next pointers from a chain. ? */

????u8_t if_idx;???????????????? /** 對于接收到的packet,用來保存輸入netif的索引號 */

????LWIP_PBUF_CUSTOM_DATA????/** 用來保存用戶自定義數(shù)據(jù),如timestamps,需要宏定義 */

};


共有四種pbuf類型,PBUF_RAM、PBUF_ROM、PBUF_POOL、PBUF_REF。

pbuf類型與特點
PBUF四種類型


PBUF_RAM

保存在RAM中的pbuf,主要用來進行TX發(fā)送。struct pbuf和payload會被分配在一個連續(xù)的內(nèi)存空間。


PBUF_ROM

data數(shù)據(jù)保存在ROM中的pbuf,struct pbuf和payload被分配在不同的存儲空間。因為payload指向ROM,數(shù)據(jù)傳遞時payload無需被拷貝。


PBUF_POOL

payload指向RAM,來自一個內(nèi)存池并且主要用來進行RX接收??梢韵騊BUF_RAM一樣鏈成鏈表,

struct pbuf和payload被分配在一個連續(xù)的存儲空間。不可用來進行TX。適合用于中斷處理函數(shù)。


PBUF_REF

pbuf來自PBUF_POOL。有點像PBUF_ROM,但由于payload有可能發(fā)生變化,所以需要根據(jù)誰在引用它在隊列傳輸時進行拷貝。


內(nèi)存管理

使用一個專用區(qū)域,確保網(wǎng)絡系統(tǒng)不會用光所有內(nèi)存。它掌管連續(xù)內(nèi)存的開辟和釋放,并且能夠壓縮之前分配出去的內(nèi)存大小。

內(nèi)存分配時,會把檢索到第一塊足夠大的空間分配出去。通過記錄每塊空間的used flag,內(nèi)存釋放時可將前后同為未使用的內(nèi)存進行合并。


內(nèi)存管理結構


2.網(wǎng)絡接口

netif用來抽象網(wǎng)卡設備,支持多網(wǎng)卡設備。如ethernet、loopback等。

/** Generic data structure used for all lwIP network interfaces */

struct netif {

? struct netif *next; /** 指向下一個netif */

? ip_addr_t ip_addr; /** IPv4地址 */

? ip_addr_t netmask; /** IPv4掩碼地址 */

? ip_addr_t gw; /** IPv4網(wǎng)關地址 */

? ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; /** IPv6地址數(shù)組 */

? u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; /** IPv6地址狀態(tài)數(shù)組 */

? u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES];

? u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES];

? netif_input_fn input; /** 被網(wǎng)絡設備驅(qū)動調(diào)用的、用來向TCP/IP協(xié)議棧傳遞packet */

? netif_output_fn output; /** 被IP模塊調(diào)用的、用來向網(wǎng)卡發(fā)送packet。對于ethernet物理層,通常是etharp_output() */

? netif_linkoutput_fn linkoutput; /** 想要在該網(wǎng)卡上發(fā)送packet時,該函數(shù)會被etharp_output()調(diào)用。會像在鏈接上傳輸pbuf一樣 */

? netif_output_ip6_fn output_ip6; /** 想要在該網(wǎng)卡上發(fā)送packet時,該函數(shù)會被IPv6模塊調(diào)用。對于ethernet物理層,通常是ethip6_output() */

? netif_status_callback_fn status_callback; /** 當netif狀態(tài)被設置為up或down時函數(shù)會被調(diào)用 */

? netif_status_callback_fn link_callback; /** 當netif鏈接被設置為up或down時函數(shù)會被調(diào)用 */

? netif_status_callback_fn remove_callback; /** 當netif被移除時函數(shù)會被調(diào)用 */

? void *state; /** 被設備驅(qū)動設定并指向設備的狀態(tài)信息 */

? void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];

? const char*? hostname; /** 該netif的主機名 */

? u16_t chksum_flags; /** checksum標志 */

? u16_t mtu; /** maximum transfer unit (in bytes) */

? u16_t mtu6; /** maximum transfer unit (in bytes) for IPv6 */

? u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; /** link level hardware address of this interface */

? u8_t hwaddr_len; /** number of bytes used in hwaddr */

? u8_t flags; /** netif標志(netif是否設置為有效等) */

? char name[2]; /** 描述縮略語,如WLAN->wl */

? u8_t num; /** number of this interface. as well as for IPv6 zones */

? u8_t ip6_autoconfig_enabled; /** 本netif對于IPv6自動配置是否有效 */

? u8_t rs_count; /** Number of Router Solicitation messages that remain to be sent. */

? //用于stats start

? u8_t link_type; /** link type (from "snmp_ifType" enum from snmp_mib2.h) */

? u32_t link_speed; /** (estimate) link speed */

? u32_t ts; /** timestamp at last change made (up/down) */

? struct stats_mib2_netif_ctrs mib2_counters; /** counters */

? //用于stats end

? netif_igmp_mac_filter_fn igmp_mac_filter; /** could be called to add or delete an entry in the multicast filter table of the ethernet MAC.*/

? netif_mld_mac_filter_fn mld_mac_filter; /** could be called to add or delete an entry in the IPv6 multicast filter table of the ethernet MAC. */

? struct acd *acd_list; /** ACD state information */

? struct pbuf *loop_first; /* List of packets to be queued for ourselves. loop interface (127.0.0.1)*/

? struct pbuf *loop_last;

? u16_t loop_cnt_current;

};

全局變量 struct netif *netif_list 和 struct netif *netif_default 分別用來指向netif鏈表表頭和默認netif。

netif追加


netif_add()



3.IP處理

ip.c定義了一些共通的IP代碼。IPv4、IPv6的具體實現(xiàn)依賴相關文件夾下的代碼。

基本數(shù)據(jù)結構ip_pcb

/* Common members of all PCB types */

struct ip_pcb {

? ip_addr_t local_ip;? ? ? ? ? ? ? ? ? ? ?

? ip_addr_t remote_ip;? ? ? ? ? ? ? ? ? ?

? u8_t netif_idx;?????????? /* Bound netif index */

? u8_t so_options;?????? /* Socket options(bits域:本地地址可重用、keepalive、廣播) */

? u8_t tos;???????????????????? /* Type Of Service */

? u8_t ttl;???????????????????? /* Time To Live */

};


ip_input與ip_output

以IPv4為例,

err_t ip4_input(struct pbuf *p, struct netif *inp); ?? /* 當網(wǎng)卡驅(qū)動收到IP包時會調(diào)用該函數(shù),該函數(shù)進行一些基本檢查,如果該包的目的地不是這里將轉(zhuǎn)發(fā)給其他網(wǎng)卡,最后該包會被傳遞給上層input函數(shù) */

err_t ip_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto); ?? /* 將IP包發(fā)送至網(wǎng)卡。該函數(shù)組成IP報頭并計算checksum */

4.UDP處理


基本數(shù)據(jù)結構udp_pcb

/** the UDP protocol control block */

struct udp_pcb {

? IP_PCB;????????????????/** Common members of all PCB types */

? struct udp_pcb *next;????????/* Protocol specific PCB members */

? u8_t flags;

? u16_t local_port, remote_port;???? /** ports are in host byte order */

? ip4_addr_t mcast_ip4;????????/** outgoing network interface for multicast packets, by IPv4 address (if not 'any') */

? u8_t mcast_ifindex;????????/** outgoing network interface for multicast packets, by interface index (if nonzero) */

? u8_t mcast_ttl;????????????/** TTL for outgoing multicast packets */

? u16_t chksum_len_rx, chksum_len_tx;????????/** used for UDP_LITE only */

? udp_recv_fn recv;????????????/** receive callback function */

? void *recv_arg;????????????/** user-supplied argument for the recv callback */

};


UDP操作API

struct udp_pcb * udp_new (void); ? ? ?? /* 創(chuàng)建一個udp_pcb,綁定一個端口或者連接到遠端之前不被激活(指加入udp_pcbs) */

struct udp_pcb * udp_new_ip_type(u8_t type);????/* 創(chuàng)建一個IPv4/6的udp_pcb */

void? ? ? ? ? ? udp_remove? ? (struct udp_pcb *pcb);????/* 刪除并釋放pcb */

err_t? ? ? ? ? ? udp_bind? ? ? (struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port);???????/* 綁定pcb */

void? ? ? ? ? ? udp_bind_netif (struct udp_pcb *pcb, const struct netif* netif);????/* 綁定pcb到一個netif,之后所有該pcb輸出輸入都會通過該netif */

err_t? ? ? ? ? ? udp_connect? ? (struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port);????/* 設置遠端IP和端口,無連接保障 */

void? ? ? ? ? ? udp_disconnect (struct udp_pcb *pcb);????/* 清楚遠端IP和端口,無連接保障 */

void? ? ? ? ? ? udp_recv? ? ? (struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg);???/* 設置接受用回調(diào)函數(shù),該函數(shù)在收到該pcb的報文時會被調(diào)用 */

err_t? ? ? ? ? ? udp_sendto_if? (struct udp_pcb *pcb, struct pbuf *p,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? const ip_addr_t *dst_ip, u16_t dst_port,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct netif *netif); ?? /* 使用指定netif發(fā)送pbuf到指定地址 */

err_t? ? ? ? ? ? udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? const ip_addr_t *dst_ip, u16_t dst_port,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct netif *netif, const ip_addr_t *src_ip);????/* 類udp_sendto_if() */

err_t? ? ? ? ? ? udp_sendto? ? (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port); ?? /* 使用udp_pcb發(fā)送pbuf到指定地址 */

err_t? ? ? ? ? ? udp_send? ? ? (struct udp_pcb *pcb, struct pbuf *p);???? /* 使用udp_pcb發(fā)送pbuf到當前遠端地址(pcb->remote_ip) */

void ? ? ? ? ?? udp_input (struct pbuf *p, struct netif *inp); ? ? /* 處理一個接收到的UDP數(shù)據(jù)包。該函數(shù)找到相應udp_pcb處理該包,并調(diào)用recv函數(shù) */

void? ? ? ? ? ? udp_init? ? ? (void);???? /* 初始化(初始UDP端口) */

5.TCP處理

詳見:LwIP 2.1.0 TCP學習摘要 - 簡書


六.移植

未完待續(xù)。

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容