Skip to content

Commit

Permalink
Merge pull request #191 from YannTremblay96/IPv6_support
Browse files Browse the repository at this point in the history
Add IPv6 address support to the response
  • Loading branch information
clairernovotny authored Aug 16, 2021
2 parents 130be6a + 8080439 commit c055197
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Zeroconf/ZeroconfResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,29 @@ static byte[] GetRequestBytes(ZeroconfOptions options)

static ZeroconfHost ResponseToZeroconf(Response response, string remoteAddress, ResolveOptions options)
{
var z = new ZeroconfHost
{
IPAddresses = response.Answers
List<string> ipv4Adresses = response.Answers
.Select(r => r.RECORD)
.OfType<RecordA>()
.Concat(response.Additionals
.Select(r => r.RECORD)
.OfType<RecordA>())
.Select(aRecord => aRecord.Address)
.Distinct()
.ToList()
.ToList();

List<string> ipv6Adresses = response.Answers
.Select(r => r.RECORD)
.OfType<RecordAAAA>()
.Concat(response.Additionals
.Select(r => r.RECORD)
.OfType<RecordAAAA>())
.Select(aRecord => aRecord.Address)
.Distinct()
.ToList();

var z = new ZeroconfHost
{
IPAddresses = ipv4Adresses.Concat(ipv6Adresses).ToList()
};

z.Id = z.IPAddresses.FirstOrDefault() ?? remoteAddress;
Expand Down

0 comments on commit c055197

Please sign in to comment.