Skip to content

Add mDNS dep and handle IPv4-only mDNS addr#2

Merged
luar123 merged 2 commits intoluar123:componentfrom
jb1228:mdns-edits
Mar 4, 2026
Merged

Add mDNS dep and handle IPv4-only mDNS addr#2
luar123 merged 2 commits intoluar123:componentfrom
jb1228:mdns-edits

Conversation

@jb1228
Copy link

@jb1228 jb1228 commented Mar 2, 2026

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.

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.
Copilot AI review requested due to automatic review settings March 2, 2026 03:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mdns component to snapclient private requirements.
  • Adjusts mDNS result IP extraction in connection_handler.c to 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.

Comment on lines +142 to +144
#if CONFIG_LWIP_IPV4 && !CONFIG_LWIP_IPV6
remote_ip.addr = re->addr->addr.u_addr.ip4.addr;
#else
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
INCLUDE_DIRS "include"

PRIV_REQUIRES esp_timer opus flac lightsnapcast
PRIV_REQUIRES esp_timer mdns opus flac lightsnapcast
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
PRIV_REQUIRES esp_timer mdns opus flac lightsnapcast
PRIV_REQUIRES esp_timer opus flac lightsnapcast

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why it is not working without this.

@jb1228
Copy link
Author

jb1228 commented Mar 2, 2026

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>
@luar123 luar123 merged commit 1dfe76a into luar123:component Mar 4, 2026
2 checks passed
@luar123
Copy link
Owner

luar123 commented Mar 4, 2026

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants