Skip to content

Commit

Permalink
feat(MessageEventArgs): detect legacy unicast messages
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 8, 2019
1 parent f838192 commit eff5b30
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Spike/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ static void Main(string[] args)
}
};

#if false
var sd = new ServiceDiscovery(mdns);
sd.Advertise(new ServiceProfile("x1", "_xservice._tcp", 5011));
sd.Advertise(new ServiceProfile("x2", "_xservice._tcp", 666));
var z1 = new ServiceProfile("z1", "_zservice._udp", 5012);
z1.AddProperty("foo", "bar");
sd.Advertise(z1);

#endif
mdns.Start();
Console.ReadKey();
}
Expand Down
8 changes: 8 additions & 0 deletions src/MessageEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class MessageEventArgs : EventArgs
/// The endpoint from the message was received.
/// </value>
public IPEndPoint RemoteEndPoint { get; set; }

/// <summary>
/// Determines if the sender is using legacy unicast DNS.
/// </summary>
/// <value>
/// <b>false</b> if the sender is using port 5353.
/// </value>
public bool IsLegacyUnicast => RemoteEndPoint.Port != MulticastClient.MulticastPort;
}
}

9 changes: 8 additions & 1 deletion src/MulticastClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class MulticastClient : IDisposable
{
static readonly ILog log = LogManager.GetLogger(typeof(MulticastClient));

const int MulticastPort = 5353;
/// <summary>
/// The port number assigned to Multicast DNS.
/// </summary>
/// <value>
/// Port number 5353.
/// </value>
public static readonly int MulticastPort = 5353;

static readonly IPAddress MulticastAddressIp4 = IPAddress.Parse("224.0.0.251");
static readonly IPAddress MulticastAddressIp6 = IPAddress.Parse("FF02::FB");
static readonly IPEndPoint MdnsEndpointIp6 = new IPEndPoint(MulticastAddressIp6, MulticastPort);
Expand Down
8 changes: 6 additions & 2 deletions test/MulticastServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ public void SendQuery()
mdns.NetworkInterfaceDiscovered += (s, e) => ready.Set();
mdns.QueryReceived += (s, e) =>
{
msg = e.Message;
done.Set();
if ("some-service.local" == e.Message.Questions.First().Name)
{
msg = e.Message;
Assert.IsFalse(e.IsLegacyUnicast);
done.Set();
}
};
try
{
Expand Down

0 comments on commit eff5b30

Please sign in to comment.