Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/multicast_dns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.2.0
* Allow configuration of the port and address the mdns query is performed on.

## 0.1.1

* Fixes [flutter/issue/31854](https://github.com/flutter/flutter/issues/31854) where `decodeMDnsResponse` advanced to incorrect code points and ignored some records.
Expand Down
21 changes: 17 additions & 4 deletions packages/multicast_dns/lib/multicast_dns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class MDnsClient {
final List<RawDatagramSocket> _sockets = <RawDatagramSocket>[];
final LookupResolver _resolver = LookupResolver();
final ResourceRecordCache _cache = ResourceRecordCache();

InternetAddress _mDnsAddress;
int _mDnsPort;
Comment thread
dnfield marked this conversation as resolved.

/// Find all network interfaces with an the [InternetAddressType] specified.
static NetworkInterfacesFactory allInterfacesFactory =
Expand All @@ -58,12 +60,23 @@ class MDnsClient {
/// [InternetAddress.anyIPv6], and will default to anyIPv4.
///
/// The [interfaceFactory] defaults to [allInterfacesFactory].
///
/// The [mDnsPort] allows configuring what port is used for the mDNS
/// query. If not provided, defaults to `5353`.
///
/// The [mDnsAddress] allows configuring what internet address is used
/// for the mDNS query. If not provided, defaults to either `224.0.0.251` or
/// or `FF02::FB`.
Future<void> start({
InternetAddress listenAddress,
NetworkInterfacesFactory interfacesFactory,
int mDnsPort = mDnsPort,
InternetAddress mDnsAddress,
}) async {
listenAddress ??= InternetAddress.anyIPv4;
interfacesFactory ??= allInterfacesFactory;
_mDnsPort = mDnsPort;
_mDnsAddress = mDnsAddress;

assert(listenAddress.address == InternetAddress.anyIPv4.address ||
listenAddress.address == InternetAddress.anyIPv6.address);
Expand All @@ -76,7 +89,7 @@ class MDnsClient {
// Listen on all addresses.
_incoming = await RawDatagramSocket.bind(
listenAddress.address,
mDnsPort,
_mDnsPort,
reuseAddress: true,
reusePort: true,
ttl: 255,
Expand All @@ -87,7 +100,7 @@ class MDnsClient {
_sockets.add(_incoming);
}

_mDnsAddress = _incoming.address.type == InternetAddressType.IPv4
_mDnsAddress ??= _incoming.address.type == InternetAddressType.IPv4
? mDnsAddressIPv4
: mDnsAddressIPv6;

Expand All @@ -99,7 +112,7 @@ class MDnsClient {
final InternetAddress targetAddress = interface.addresses[0];
final RawDatagramSocket socket = await RawDatagramSocket.bind(
targetAddress,
mDnsPort,
_mDnsPort,
reuseAddress: true,
reusePort: true,
ttl: 255,
Expand Down Expand Up @@ -180,7 +193,7 @@ class MDnsClient {
// Send the request on all interfaces.
final List<int> packet = query.encode();
for (RawDatagramSocket socket in _sockets) {
socket.send(packet, _mDnsAddress, mDnsPort);
socket.send(packet, _mDnsAddress, _mDnsPort);
}
return results;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/multicast_dns/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: multicast_dns
description: Dart package for mDNS queries (e.g. Bonjour, Avahi).
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/packages/tree/master/packages/multicast_dns
version: 0.1.1
version: 0.2.0

dependencies:
meta: ^1.1.6
Expand Down