Skip to content

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

Open
flutter/core-packages
#49

Description

@Marshal-GG

Package

multicast_dns 0.3.3+1

Platform seen on

Android (the root cause is platform-independent)

Summary

On IPv4, MDnsClient.start() never sets IP_MULTICAST_IF on its sending socket. For IPv6 it does — the per-interface loop sets RawSocketOption.IPv6MulticastInterface. The IPv4 path calls joinMulticast but sets no IPv4MulticastInterface, so IPv4 multicast egress follows the OS routing table.

On a phone with both Wi-Fi and mobile data up, the default route is cellular, so mDNS queries leave over the cellular interface and never reach the LAN. Discovery silently finds nothing and reports no error.

Evidence

In lib/multicast_dns.dart, the interface loop sets the multicast interface only inside the if (targetAddress.type == InternetAddressType.IPv6) branch. The IPv4 send socket (_incomingIPv4, bound to anyIPv4) joins multicast but is never given an IPv4MulticastInterface option.

Confirmed on desktop that joinMulticast does not set IP_MULTICAST_IF: reading the socket's IPv4MulticastInterface option stays 0.0.0.0 after joining on every interface, so the socket relies on routing for IPv4 egress.

Steps to reproduce

  1. On an Android device, turn on both Wi-Fi and mobile data.
  2. Announce an mDNS service on the LAN from another machine (e.g. dns-sd -R sample _http._tcp . 8000).
  3. Run a lookup from the device. It returns nothing.
  4. Force the socket's IPv4 multicast interface to the Wi-Fi address and repeat — the same lookup resolves.

Suggested fix

In the IPv4 path, set the multicast interface, mirroring the IPv6 branch:

socket.setRawOption(RawSocketOption(
  RawSocketOption.levelIPv4,
  RawSocketOption.IPv4MulticastInterface,
  interfaceAddress.rawAddress,
));

Workaround

Callers can override rawDatagramSocketFactory and set the option on the returned socket themselves.

Versions

Flutter 3.47.5 · Dart 3.13.4 · multicast_dns 0.3.3+1

Activity

  1. added
    in triagePresently being triaged by the triage team
    packageflutter/packages repository. See also p: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Nov 10, 2026
  2. puneetkukreja98 commented on Nov 10, 2026

    @puneetkukreja98
    Contributor

    @Marshal-GG Thanks for reporting this, routing this to team-ecosystem for further investigation.

  3. added
    fyi-androidFor the attention of Android platform team
    P2Important issues not at the top of the work list
    on Nov 10, 2026
  4. bparrishMines commented on Nov 10, 2026

    @bparrishMines
    Contributor

    cc @vashworth since you are the suggested reviewer.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: multicast_dnsThe mdns packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions