void
udp_input(struct pbuf *p, struct netif *inp)
{
struct udp_hdr *udphdr;
struct udp_pcb *pcb, *prev;
struct udp_pcb *uncon_pcb;
u16_t src, dest;
u8_t broadcast;
u8_t for_us = 0;
/* Check minimum length (UDP header) 检查最小长度,不能小于UDP首部*/
if (p->len < UDP_HLEN) {
/* drop short packets */
pbuf_free(p);
goto end;
}
//指向UDP报文首部,并且强制转换成udp_hdr类型,方便操作
udphdr = (struct udp_hdr *)p->payload;
/* is broadcast packet ? 判断是不是广播包*/
broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), ip_current_netif());
/* convert src and dest ports to host byte order 得到UDP首部中的源地址和目标主机端口号*/
src = lwip_ntohs(udphdr->src);
dest = lwip_ntohs(udphdr->dest);
pcb = NULL;
prev = NULL;
uncon_pcb = NULL;
/* Iterate through the UDP pcb list for a matching pcb.遍历UDP链表,找到对应的端口号,如果找不到,
* 'Perfect match' pcbs (connected to the remote port & ip address) are就用链表的第一个未使用的UDP控制块
* preferred. If no perfect match is found, the first unconnected pcb that
* matches the local port and ip address gets the datagram. */
for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next
LwIP 接收函数udp_input精简版
最新推荐文章于 2024-07-28 17:01:22 发布
本文深入探讨了LwIP网络库中的udp_input函数,解析了其如何处理UDP数据包的接收流程,包括数据包的解析、端口匹配和回调函数的调用,为理解LwIP UDP通信提供了关键洞察。
摘要由CSDN通过智能技术生成