lwIP: constrain ping address resolution to IPv4#11528
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-06-29 11:06 CST)
📝 Review Instructions
|
|
| return -RT_ERROR; | ||
| } | ||
| memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); | ||
| h = (struct sockaddr_in *)res->ai_addr; |
There was a problem hiding this comment.
https://github.com/RT-Thread/rt-thread/blob/master/components/net/lwip/port/ethernetif.c#L240
Does this part have the same problem?
There was a problem hiding this comment.
Good catch, this path has the same IPv4 raw ICMP assumption. I updated lwip_netdev_ping() to constrain getaddrinfo() to AF_INET and replaced the pointer SMEMCPY with a direct sockaddr_in * assignment as well.
b612580 to
3bfec0e
Compare
3bfec0e to
1ca8de0
Compare
Summary
struct sockaddr_in *assignment in the same code path#endifcomments next to the touched codeRoot Cause
The custom ping implementation creates an IPv4 raw ICMP socket, but its
lwip_getaddrinfo()hint did not explicitly request IPv4 addresses. On dual-stack configurations, address resolution may return an address family that does not match the later IPv4 ICMP path.Details
The fix sets
hint.ai_family = AF_INETimmediately after initializing theaddrinfohint. This keeps the responsibility at the address resolution layer and does not add duplicate checks later in the ping flow.This intentionally does not change netdev ping behavior, does not add IPv6 ping support, and does not restructure the ping command.
Validation
git diff --check origin/master..HEADrg -n "#endif\\s+/\\s+\\*" components/net/lwiprg -n "memcpy\\(&h,\\s*&res->ai_addr|rt_memcpy\\(&h,\\s*&res->ai_addr" components/net/lwiptools/ci/file_check.pyFormatCheckfor the three touchedping.cfilesLocal BSP build was not run because this Windows environment does not have
scons,gcc,arm-none-eabi-gcc, or MSVCclavailable.