Commit c775ec22 authored by Brickner_cp's avatar Brickner_cp

DNS

parent 76715009
...@@ -308,6 +308,10 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -308,6 +308,10 @@ namespace PcapDotNet.Packets.TestUtils
random.NextDataSegment(random.NextInt(0, 100)), random.NextUShort(), random.NextDataSegment(random.NextInt(0, 100)), random.NextUShort(),
random.NextEnum<DnsResponseCode>(), random.NextDataSegment(random.NextInt(0, 100))); random.NextEnum<DnsResponseCode>(), random.NextDataSegment(random.NextInt(0, 100)));
case DnsType.Uri:
return new DnsResourceDataUri(random.NextUShort(), random.NextUShort(),
((Func<DataSegment>)(() => random.NextDataSegment(random.NextInt(0, 100)))).GenerateArray(random.NextInt(0, 10)));
default: default:
return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100))); return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100)));
} }
...@@ -338,7 +342,6 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -338,7 +342,6 @@ namespace PcapDotNet.Packets.TestUtils
default: default:
throw new InvalidOperationException(string.Format("Invalid gateway type: {0}", gatewayType)); throw new InvalidOperationException(string.Format("Invalid gateway type: {0}", gatewayType));
} }
} }
} }
} }
...@@ -6513,4 +6513,109 @@ namespace PcapDotNet.Packets.Dns ...@@ -6513,4 +6513,109 @@ namespace PcapDotNet.Packets.Dns
return new DnsResourceDataTransactionSignature(algorithm, timeSigned, fudge, messageAuthenticationCode, originalId, error, other); return new DnsResourceDataTransactionSignature(algorithm, timeSigned, fudge, messageAuthenticationCode, originalId, error, other);
} }
} }
/// <summary>
/// Faltstrom.
/// <pre>
/// +-----+----------+--------+
/// | bit | 0-15 | 16-31 |
/// +-----+----------+--------+
/// | 0 | Priority | Weight |
/// +-----+----------+--------+
/// | 32 | Target |
/// | ... | |
/// +-----+-------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Uri)]
public sealed class DnsResourceDataUri : DnsResourceDataSimple, IEquatable<DnsResourceDataUri>
{
private static class Offset
{
public const int Priority = 0;
public const int Weight = Priority + sizeof(ushort);
public const int Target = Weight + sizeof(ushort);
}
private const int ConstantPartLength = Offset.Target;
public DnsResourceDataUri(ushort priority, ushort weight, IList<DataSegment> target)
{
Priority = priority;
Weight = weight;
Target = target.AsReadOnly();
}
/// <summary>
/// The priority of the target URI in this RR.
/// A client must attempt to contact the URI with the lowest-numbered priority it can reach;
/// URIs with the same priority should be tried in the order defined by the weight field.
/// </summary>
public ushort Priority { get; private set; }
/// <summary>
/// A server selection mechanism.
/// The weight field specifies a relative weight for entries with the same priority.
/// Larger weights should be given a proportionately higher probability of being selected.
/// </summary>
public ushort Weight { get; private set; }
/// <summary>
/// The URI of the target.
/// Resolution of the URI is according to the definitions for the Scheme of the URI.
/// </summary>
public ReadOnlyCollection<DataSegment> Target { get; private set; }
public bool Equals(DnsResourceDataUri other)
{
return other != null &&
Priority.Equals(other.Priority) &&
Weight.Equals(other.Weight) &&
Target.SequenceEqual(other.Target);
}
public override bool Equals(DnsResourceData other)
{
return Equals(other as DnsResourceDataUri);
}
internal DnsResourceDataUri()
: this(0, 0, new DataSegment[0])
{
}
internal override int GetLength()
{
return ConstantPartLength + Target.Sum(targetPart => GetStringLength(targetPart));
}
internal override void WriteDataSimple(byte[] buffer, int offset)
{
buffer.Write(offset + Offset.Priority, Priority, Endianity.Big);
buffer.Write(offset + Offset.Weight, Weight, Endianity.Big);
int targetOffset = offset + Offset.Target;
foreach (DataSegment targetPart in Target)
WriteString(buffer, ref targetOffset, targetPart);
}
internal override DnsResourceData CreateInstance(DataSegment data)
{
if (data.Length < ConstantPartLength)
return null;
ushort priority = data.ReadUShort(Offset.Priority, Endianity.Big);
ushort weight = data.ReadUShort(Offset.Weight, Endianity.Big);
List<DataSegment> target = new List<DataSegment>();
int targetDataOffset = Offset.Target;
while (data.Length > targetDataOffset)
{
DataSegment targetPart = ReadString(data, ref targetDataOffset);
if (targetPart == null)
return null;
target.Add(targetPart);
}
return new DnsResourceDataUri(priority, weight, target);
}
}
} }
...@@ -453,24 +453,28 @@ ...@@ -453,24 +453,28 @@
/// <summary> /// <summary>
/// RFC 1995. /// RFC 1995.
/// Incremental transfer. /// Incremental transfer.
/// Query Type.
/// </summary> /// </summary>
Ixfr = 251, Ixfr = 251,
/// <summary> /// <summary>
/// RFCs 1035, 5936. /// RFCs 1035, 5936.
/// Transfer of an entire zone. /// Transfer of an entire zone.
/// Query Type.
/// </summary> /// </summary>
Axft = 252, Axfr = 252,
/// <summary> /// <summary>
/// RFC 1035. /// RFC 1035.
/// Mailbox-related RRs (MB, MG or MR). /// Mailbox-related RRs (MB, MG or MR).
/// Query Type.
/// </summary> /// </summary>
MailB = 253, MailB = 253,
/// <summary> /// <summary>
/// RFC 1035. /// RFC 1035.
/// Mail agent RRs (Obsolete - see MX). /// Mail agent RRs (Obsolete - see MX).
/// Query Type.
/// </summary> /// </summary>
MailA = 254, MailA = 254,
...@@ -484,6 +488,7 @@ ...@@ -484,6 +488,7 @@
/// <summary> /// <summary>
/// Faltstrom. /// Faltstrom.
/// URI. /// URI.
/// Payload type: DnsResourceDataUri.
/// </summary> /// </summary>
Uri = 256, Uri = 256,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment