Skip to content

Commit

Permalink
Complete rewrite of the DnsName with a lot more tests plus performanc…
Browse files Browse the repository at this point in the history
…e optimized
  • Loading branch information
MichaCo committed Jan 4, 2017
1 parent 4b2fd98 commit 5b0015f
Show file tree
Hide file tree
Showing 13 changed files with 890 additions and 251 deletions.
5 changes: 4 additions & 1 deletion src/DnsClient/DnsDatagramReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ public IPAddress ReadIPv6Address()

public DnsName ReadName()
{
return DnsName.FromBytes(_data, ref _index);
var bytesRead = 0;
var name = DnsName.FromBytes(new ArraySegment<byte>(_data, _index, _data.Length - _index), out bytesRead);
_index += bytesRead;
return name;
}

public ushort ReadUInt16()
Expand Down
8 changes: 4 additions & 4 deletions src/DnsClient/DnsMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* */
// 4 more bytes for the type and class
var writer = new DnsDatagramWriter(DnsRequestHeader.HeaderLength + questionData.Length + 4);
var writer = new DnsDatagramWriter(DnsRequestHeader.HeaderLength + questionData.Count + 4);

writer.WriteInt16NetworkOrder((short)request.Header.Id);
writer.WriteUInt16NetworkOrder(request.Header.RawFlags);
Expand All @@ -48,7 +48,7 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// jump to end of header, we didn't write all fields
writer.Index = DnsRequestHeader.HeaderLength;

writer.WriteBytes(questionData, questionData.Length);
writer.WriteBytes(questionData.Array, questionData.Count);
writer.WriteUInt16NetworkOrder((ushort)question.QuestionType);
writer.WriteUInt16NetworkOrder((ushort)question.QuestionClass);

Expand All @@ -66,8 +66,8 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* */
var opt = new OptRecord();
var nameBytes = opt.DomainName.GetBytes();
writer.Extend(nameBytes.Length + 2 + 2 + 4 + 2);
writer.WriteBytes(nameBytes, nameBytes.Length);
writer.Extend(nameBytes.Count + 2 + 2 + 4 + 2);
writer.WriteBytes(nameBytes.Array, nameBytes.Count);
writer.WriteUInt16NetworkOrder((ushort)opt.RecordType);
writer.WriteUInt16NetworkOrder((ushort)opt.RecordClass);
writer.WriteUInt32NetworkOrder((ushort)opt.TimeToLive);
Expand Down
Loading

0 comments on commit 5b0015f

Please sign in to comment.