Skip to content

[multicast_dns] Send IPv4 queries on each interface - #49

Open
NemesisDevX wants to merge 4 commits into
flutter:mainfrom
NemesisDevX:oss-038-mdns-ipv4-interfaces
Open

NemesisDevX wants to merge 4 commits into
flutter:mainfrom
NemesisDevX:oss-038-mdns-ipv4-interfaces

Conversation

@NemesisDevX

@NemesisDevX NemesisDevX commented Nov 9, 2026 •

Copy link
Copy Markdown

Fixes flutter/flutter#196244

On IPv4, queries were sent through the wildcard listener socket, leaving multicast egress to the system routing table. When cellular is the default route, this can send mDNS queries away from the Wi-Fi LAN.

This change opens one IPv4 sending socket for each discovered IPv4 interface, sets IP_MULTICAST_IF to that interface's address, sends queries through those sockets, and closes them with the client. The wildcard socket remains responsible for receiving and joining the multicast group; the prior wildcard send path remains the fallback when no interfaces are discovered. Regression coverage verifies the per-interface socket option, one query per interface, socket cleanup, and continuing sends after an interface send failure.

Verification:

  • Initial patch at a6e615f: dart test — 22 passed; dart analyze — no issues; dart format — clean.
  • Current head 01e47d9 includes follow-up send-failure handling and regression coverage. I could not run Dart tests or analysis on this head because the Dart SDK is unavailable in this environment.
  • git diff --check — clean on the current head.
  • Current GitHub checks: 2/6 completed; five workflows await maintainer approval, so no test result is available for the current head yet.

Pre-Review Checklist

  • I read the contributor guide and followed the process for submitting PRs.
  • I read the AI contribution guidelines and reviewed the code and description for accuracy.
  • I read the Tree Hygiene page and followed its requirements.
  • I ran dart format on the current head (the initial patch was formatted; the follow-up edits have not been formatted locally).
  • I signed the CLA. (GitHub currently reports the CLA check as successful.)
  • The title starts with the package name in brackets.
  • This PR links the issue it fixes.
  • I updated the version and CHANGELOG.
  • No public API documentation changes are needed.
  • I added regression coverage.
  • Tests and analysis have passed on the current head; current head checks are awaiting maintainer approval.

AI disclosure: implementation and test work were assisted by ChatGPT; I reviewed the complete patch and reported verification status as of the current head.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the MDnsClient to send IPv4 mDNS queries over each configured network interface by creating and managing a list of interface-specific sockets (_ipv4InterfaceSockets). It also adds corresponding unit tests to verify this behavior. Feedback on the changes suggests wrapping the socket transmission loop in a try-catch block to ensure that a failure or SocketException on one network interface does not prevent queries from being sent on the remaining interfaces.

@Piinks
Piinks requested a review from vashworth November 9, 2026 22:43
NemesisDevX and others added 3 commits November 10, 2026 00:49
If creating an interface socket throws partway through start(), the
sockets already created were leaked and _starting stayed true, leaving
the client permanently unable to start. Close all sockets, reset the
starting flag, and rethrow so the client can be retried.

Also fix the send-failure test so the SocketException is actually armed:
host is the InterfaceAddress wrapper, so compare by address string
rather than object identity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[multicast_dns] IPv4 queries ignore the Wi-Fi interface and leave over cellular when mobile data is up

1 participant