Show / Hide Table of Contents

Class MulticastService

Muticast Domain Name Service.

Inheritance
Object
MulticastService
Implements
IResolver
IDisposable
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Makaretu.Dns
Assembly: Makaretu.Dns.Multicast.dll
Syntax
public class MulticastService : IResolver, IDisposable
Remarks

Sends and receives DNS queries and answers via the multicast mechachism defined in https://tools.ietf.org/html/rfc6762.

Use Start() to start listening for multicast messages. One of the events, QueryReceived or AnswerReceived, is raised when a Message is received.

Constructors

| Improve this Doc View Source

MulticastService(Func<IEnumerable<NetworkInterface>, IEnumerable<NetworkInterface>>)

Create a new instance of the MulticastService class.

Declaration
public MulticastService(Func<IEnumerable<NetworkInterface>, IEnumerable<NetworkInterface>> filter = null)
Parameters
Type Name Description
Func<IEnumerable<NetworkInterface>, IEnumerable<NetworkInterface>> filter

Multicast listener will be bound to result of filtering function.

Properties

| Improve this Doc View Source

IgnoreDuplicateMessages

Determines if received messages are checked for duplicates.

Declaration
public bool IgnoreDuplicateMessages { get; set; }
Property Value
Type Description
Boolean

true to ignore duplicate messages. Defaults to true.

Remarks

When set, a message that has been received within the last minute will be ignored.

| Improve this Doc View Source

NetworkInterfaceDiscoveryInterval

The interval for discovering network interfaces.

Declaration
[Obsolete("This property is deprecated and will be removed in nearest future. Using timer removed with obsording of NetworkChange.NetworkAddressChanged event.", false)]
public TimeSpan NetworkInterfaceDiscoveryInterval { get; set; }
Property Value
Type Description
TimeSpan

Default is 2 minutes.

Remarks

When the interval is reached a task is started to discover any new network interfaces.

See Also
NetworkInterfaceDiscovered
| Improve this Doc View Source

UseIpv4

Send and receive on IPv4.

Declaration
public bool UseIpv4 { get; set; }
Property Value
Type Description
Boolean

Defaults to true if the OS supports it.

| Improve this Doc View Source

UseIpv6

Send and receive on IPv6.

Declaration
public bool UseIpv6 { get; set; }
Property Value
Type Description
Boolean

Defaults to true if the OS supports it.

Methods

| Improve this Doc View Source

Dispose()

Declaration
public void Dispose()
| Improve this Doc View Source

Dispose(Boolean)

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing
| Improve this Doc View Source

GetIPAddresses()

Get the IP addresses of the local machine.

Declaration
public static IEnumerable<IPAddress> GetIPAddresses()
Returns
Type Description
IEnumerable<IPAddress>

A sequence of IP addresses of the local machine.

Remarks

The loopback addresses (127.0.0.1 and ::1) are NOT included in the returned sequences.

| Improve this Doc View Source

GetLinkLocalAddresses()

Get the link local IP addresses of the local machine.

Declaration
public static IEnumerable<IPAddress> GetLinkLocalAddresses()
Returns
Type Description
IEnumerable<IPAddress>

A sequence of IP addresses.

Remarks

All IPv4 addresses are considered link local.

See Also
https://en.wikipedia.org/wiki/Link-local_address
| Improve this Doc View Source

GetNetworkInterfaces()

Get the network interfaces that are useable.

Declaration
public static IEnumerable<NetworkInterface> GetNetworkInterfaces()
Returns
Type Description
IEnumerable<NetworkInterface>

A sequence of NetworkInterface.

Remarks

The following filters are applied

  • interface is enabled
  • interface is not a loopback

If no network interface is operational, then the loopback interface(s) are included (127.0.0.1 and/or ::1).

| Improve this Doc View Source

OnDnsMessage(Object, UdpReceiveResult)

Called by the MulticastClient when a DNS message is received.

Declaration
public void OnDnsMessage(object sender, UdpReceiveResult result)
Parameters
Type Name Description
Object sender

The Makaretu.Dns.MulticastClient that got the message.

UdpReceiveResult result

The received message UdpReceiveResult.

Remarks

Decodes the result and then raises
either the QueryReceived or AnswerReceived event.

Multicast DNS messages received with an OPCODE or RCODE other than zero
are silently ignored.


If the message cannot be decoded, then the MalformedMessage event is raised.

| Improve this Doc View Source

ResolveAsync(Message, CancellationToken)

Declaration
public Task<Message> ResolveAsync(Message request, CancellationToken cancel = default(CancellationToken))
Parameters
Type Name Description
Message request
CancellationToken cancel
Returns
Type Description
Task<Message>
| Improve this Doc View Source

SendAnswer(Message, MessageEventArgs, Boolean)

Send an answer to a query.

Declaration
public void SendAnswer(Message answer, MessageEventArgs query, bool checkDuplicate = true)
Parameters
Type Name Description
Message answer

The answer message.

MessageEventArgs query

The query that is being answered.

Boolean checkDuplicate

If true, then if the same answer was recently sent it will not be sent again.

Remarks

If the query is a standard multicast query (sent to port 5353), then SendAnswer(Message, Boolean) is called.

Otherwise a legacy unicast reponse is sent to sender's end point. The AA flag is set to true, the Id is set to query's ID, the Questions is set to the query's questions, and all resource record TTLs have a max value of 10 seconds.

The answer is Truncate(Int32) if exceeds the maximum packet length.

checkDuplicate should always be true except when answering a probe.

Exceptions
Type Condition
InvalidOperationException

When the service has not started.

ArgumentOutOfRangeException

When the serialised answer is too large.

| Improve this Doc View Source

SendAnswer(Message, Boolean)

Send an answer to a query.

Declaration
public void SendAnswer(Message answer, bool checkDuplicate = true)
Parameters
Type Name Description
Message answer

The answer message.

Boolean checkDuplicate

If true, then if the same answer was recently sent it will not be sent again.

Remarks

The AA flag is set to true, the Id set to zero and any questions are removed.

The answer is Truncate(Int32) if exceeds the maximum packet length.

checkDuplicate should always be true except when answering a probe.

caution

If possible the SendAnswer(Message, MessageEventArgs, Boolean) method should be used, so that legacy unicast queries are supported.

Exceptions
Type Condition
InvalidOperationException

When the service has not started.

ArgumentOutOfRangeException

When the serialised answer is too large.

See Also
CreateResponse()
| Improve this Doc View Source

SendQuery(DomainName, DnsClass, DnsType)

Ask for answers about a name.

Declaration
public void SendQuery(DomainName name, DnsClass klass = DnsClass.IN, DnsType type = DnsType.ANY)
Parameters
Type Name Description
DomainName name

A domain name that should end with ".local", e.g. "myservice.local".

DnsClass klass

The class, defaults to IN.

DnsType type

The question type, defaults to ANY.

Remarks

Answers to any query are obtained on the AnswerReceived event.

Exceptions
Type Condition
InvalidOperationException

When the service has not started.

| Improve this Doc View Source

SendQuery(Message)

Ask for answers.

Declaration
public void SendQuery(Message msg)
Parameters
Type Name Description
Message msg

A query message.

Remarks

Answers to any query are obtained on the AnswerReceived event.

Exceptions
Type Condition
InvalidOperationException

When the service has not started.

ArgumentOutOfRangeException

When the serialised msg is too large.

| Improve this Doc View Source

SendUnicastQuery(DomainName, DnsClass, DnsType)

Ask for answers about a name and accept unicast and/or broadcast response.

Declaration
public void SendUnicastQuery(DomainName name, DnsClass klass = DnsClass.IN, DnsType type = DnsType.ANY)
Parameters
Type Name Description
DomainName name

A domain name that should end with ".local", e.g. "myservice.local".

DnsClass klass

The class, defaults to IN.

DnsType type

The question type, defaults to ANY.

Remarks

Send a "QU" question (unicast). The most significat bit of the Class is set. Answers to any query are obtained on the AnswerReceived event.

Exceptions
Type Condition
InvalidOperationException

When the service has not started.

| Improve this Doc View Source

Start()

Start the service.

Declaration
public void Start()
| Improve this Doc View Source

Stop()

Stop the service.

Declaration
public void Stop()
Remarks

Clears all the event handlers.

Events

| Improve this Doc View Source

AnswerReceived

Raised when any link-local MDNS service responds to a query.

Declaration
public event EventHandler<MessageEventArgs> AnswerReceived
Event Type
Type Description
EventHandler<MessageEventArgs>

Contains the answer Message.

Remarks

Any exception throw by the event handler is simply logged and then forgotten.

| Improve this Doc View Source

MalformedMessage

Raised when a DNS message is received that cannot be decoded.

Declaration
public event EventHandler<byte[]> MalformedMessage
Event Type
Type Description
EventHandler<Byte[]>

The DNS message as a byte array.

| Improve this Doc View Source

NetworkInterfaceDiscovered

Raised when one or more network interfaces are discovered.

Declaration
public event EventHandler<NetworkInterfaceEventArgs> NetworkInterfaceDiscovered
Event Type
Type Description
EventHandler<NetworkInterfaceEventArgs>

Contains the network interface(s).

| Improve this Doc View Source

QueryReceived

Raised when any local MDNS service sends a query.

Declaration
public event EventHandler<MessageEventArgs> QueryReceived
Event Type
Type Description
EventHandler<MessageEventArgs>

Contains the query Message.

Remarks

Any exception throw by the event handler is simply logged and then forgotten.

See Also
SendQuery(Message)

Implements

IResolver
System.IDisposable
  • Improve this Doc
  • View Source
Back to top Generated by DocFX