[socket] Fix IPv6 compilation error on host platform#14101
[socket] Fix IPv6 compilation error on host platform#14101swoboda1337 merged 1 commit intoesphome:devfrom
Conversation
The format_sockaddr_to function accessed sin6_addr.un.u32_addr (an LWIP-specific struct layout) under a guard that included the host platform, which uses POSIX struct in6_addr without the LWIP union. Narrow the preprocessor guard to USE_HOST and use the standard IN6_IS_ADDR_V4MAPPED() macro with s6_addr[] for the host code path. ESP32-IDF is unaffected since its LWIP headers provide the union layout even with BSD sockets. Also adds socket component build tests for host and ESP32-IDF, with and without IPv6. Closes esphome#14097 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#14101
components: [socket]
refresh: 1h(Added by the PR bot) |
|
👋 Hi there! This PR modifies 1 file(s) with codeowners. @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a compilation error when using IPv6 on the host platform. The issue stems from the host platform using POSIX struct in6_addr (which only has s6_addr[]) while the existing code attempted to access LWIP-specific un.u32_addr union members. ESP32-IDF is unaffected because it includes LWIP headers that provide the union layout despite using BSD sockets.
Changes:
- Updated IPv4-mapped IPv6 address detection to use standard POSIX macros for host platform
- Added platform-specific preprocessor guards to separate host and ESP32-IDF code paths
- Added build tests for socket component on host and ESP32-IDF platforms with and without IPv6
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| esphome/components/socket/socket.cpp | Added USE_HOST-specific code path using IN6_IS_ADDR_V4MAPPED() and s6_addr[12] for IPv4-mapped address detection |
| tests/components/socket/common.yaml | Shared test configuration with substitution for IPv6 enable flag |
| tests/components/socket/test.host.yaml | Build test for socket component on host platform without IPv6 |
| tests/components/socket/test.esp32-idf.yaml | Build test for socket component on ESP32-IDF platform without IPv6 |
| tests/components/socket/test-ipv6.host.yaml | Build test for socket component on host platform with IPv6 enabled |
| tests/components/socket/test-ipv6.esp32-idf.yaml | Build test for socket component on ESP32-IDF platform with IPv6 enabled |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14101 +/- ##
=======================================
Coverage 74.11% 74.11%
=======================================
Files 55 55
Lines 11590 11590
Branches 1578 1578
=======================================
Hits 8590 8590
Misses 2598 2598
Partials 402 402 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks |
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
What does this implement/fix?
When
network: enable_ipv6: trueis set on thehostplatform, compilation fails becauseformat_sockaddr_toinsocket.cppaccessessin6_addr.un.u32_addr— an LWIP-specific struct layout — under a#ifndef USE_SOCKET_IMPL_LWIP_TCPguard that includes the host platform. The host platform uses POSIXstruct in6_addrwhich only hass6_addr(no LWIP union).ESP32-IDF is unaffected despite also using BSD sockets, because its LWIP headers provide the
un.u32_addrunion layout.The fix narrows the preprocessor guard to
USE_HOSTand uses the standardIN6_IS_ADDR_V4MAPPED()macro withs6_addr[]for the host code path only. The existing LWIP code path for ESP32-IDF and LWIP sockets is unchanged.Also adds socket component build tests for host and ESP32-IDF, with and without IPv6.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: