Add mDNS dep and handle IPv4-only mDNS addr#2
Conversation
Add `mdns` to the component private requirements so mDNS symbols are available at build time. In connection_handler.c add a conditional to read the IPv4 address from the mdns result when IPv6 is disabled, falling back to ip_addr_copy for dual-stack builds. This avoids accessing IPv6 fields when LWIP IPv6 support is turned off.
There was a problem hiding this comment.
Pull request overview
This PR updates the snapclient component to ensure mDNS-related code builds correctly across LWIP IPv4/IPv6 configurations, particularly avoiding IPv6 field access in IPv4-only builds.
Changes:
- Adds the
mdnscomponent tosnapclientprivate requirements. - Adjusts mDNS result IP extraction in
connection_handler.cto handle IPv4-only LWIP builds without touching IPv6 fields.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| components/snapclient/connection_handler.c | Adds an IPv4-only compile-time branch for extracting the remote IP from an mDNS result. |
| components/snapclient/CMakeLists.txt | Adds mdns to PRIV_REQUIRES so the component links mDNS symbols. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if CONFIG_LWIP_IPV4 && !CONFIG_LWIP_IPV6 | ||
| remote_ip.addr = re->addr->addr.u_addr.ip4.addr; | ||
| #else |
There was a problem hiding this comment.
In the IPv4-only build branch, remote_ip is populated from re->addr->addr.u_addr.ip4 unconditionally. If CONFIG_SNAPCLIENT_CONNECT_IPV6 is enabled (Kconfig currently doesn’t prevent it when CONFIG_LWIP_IPV6 is off), the selection loop can break on a V6 address and this assignment will read the IPv4 field from a V6 address, producing an invalid remote IP. Consider forcing IPv4 selection when !CONFIG_LWIP_IPV6 (ignore CONFIG_SNAPCLIENT_CONNECT_IPV6 in that case) and/or assert/check the selected address type is V4 before assigning remote_ip in this branch.
| INCLUDE_DIRS "include" | ||
|
|
||
| PRIV_REQUIRES esp_timer opus flac lightsnapcast | ||
| PRIV_REQUIRES esp_timer mdns opus flac lightsnapcast |
There was a problem hiding this comment.
mdns is now listed in PRIV_REQUIRES unconditionally, but this component already adds it conditionally via idf_component_optional_requires(PRIVATE mdns) under if(CONFIG_SNAPSERVER_USE_MDNS). Keeping the dependency unconditional (and duplicated) will build/link the mdns component even when mDNS is disabled. Consider removing mdns from PRIV_REQUIRES and relying on the existing conditional idf_component_optional_requires, or otherwise make the dependency consistently conditional in one place.
| PRIV_REQUIRES esp_timer mdns opus flac lightsnapcast | |
| PRIV_REQUIRES esp_timer opus flac lightsnapcast |
There was a problem hiding this comment.
No idea why it is not working without this.
|
These edits may not be necessary if the build flags are set properly in the ESPHome snapclient component. I can investigate further. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Thanks |
Add
mdnsto the component private requirements so mDNS symbols are available at build time. Inconnection_handler.cadd a conditional to read the IPv4 address from the mdns result when IPv6 is disabled, falling back toip_addr_copyfor dual-stack builds. This avoids accessing IPv6 fields when LWIP IPv6 support is turned off.