Skip to content

Commit eff5b30

Browse files
feat(MessageEventArgs): detect legacy unicast messages
1 parent f838192 commit eff5b30

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

Spike/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ static void Main(string[] args)
5151
}
5252
};
5353

54+
#if false
5455
var sd = new ServiceDiscovery(mdns);
5556
sd.Advertise(new ServiceProfile("x1", "_xservice._tcp", 5011));
5657
sd.Advertise(new ServiceProfile("x2", "_xservice._tcp", 666));
5758
var z1 = new ServiceProfile("z1", "_zservice._udp", 5012);
5859
z1.AddProperty("foo", "bar");
5960
sd.Advertise(z1);
60-
61+
#endif
6162
mdns.Start();
6263
Console.ReadKey();
6364
}

src/MessageEventArgs.cs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public class MessageEventArgs : EventArgs
2424
/// The endpoint from the message was received.
2525
/// </value>
2626
public IPEndPoint RemoteEndPoint { get; set; }
27+
28+
/// <summary>
29+
/// Determines if the sender is using legacy unicast DNS.
30+
/// </summary>
31+
/// <value>
32+
/// <b>false</b> if the sender is using port 5353.
33+
/// </value>
34+
public bool IsLegacyUnicast => RemoteEndPoint.Port != MulticastClient.MulticastPort;
2735
}
2836
}
2937

src/MulticastClient.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ class MulticastClient : IDisposable
1919
{
2020
static readonly ILog log = LogManager.GetLogger(typeof(MulticastClient));
2121

22-
const int MulticastPort = 5353;
22+
/// <summary>
23+
/// The port number assigned to Multicast DNS.
24+
/// </summary>
25+
/// <value>
26+
/// Port number 5353.
27+
/// </value>
28+
public static readonly int MulticastPort = 5353;
29+
2330
static readonly IPAddress MulticastAddressIp4 = IPAddress.Parse("224.0.0.251");
2431
static readonly IPAddress MulticastAddressIp6 = IPAddress.Parse("FF02::FB");
2532
static readonly IPEndPoint MdnsEndpointIp6 = new IPEndPoint(MulticastAddressIp6, MulticastPort);

test/MulticastServiceTest.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public void SendQuery()
4040
mdns.NetworkInterfaceDiscovered += (s, e) => ready.Set();
4141
mdns.QueryReceived += (s, e) =>
4242
{
43-
msg = e.Message;
44-
done.Set();
43+
if ("some-service.local" == e.Message.Questions.First().Name)
44+
{
45+
msg = e.Message;
46+
Assert.IsFalse(e.IsLegacyUnicast);
47+
done.Set();
48+
}
4549
};
4650
try
4751
{

0 commit comments

Comments
 (0)