Commit 066e0511 authored by Brickner_cp's avatar Brickner_cp

DNS

parent fc7e1c71
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<SPACE_AFTER_TYPECAST_PARENTHESES>False</SPACE_AFTER_TYPECAST_PARENTHESES> <SPACE_AFTER_TYPECAST_PARENTHESES>False</SPACE_AFTER_TYPECAST_PARENTHESES>
<SPACE_AROUND_MULTIPLICATIVE_OP>True</SPACE_AROUND_MULTIPLICATIVE_OP> <SPACE_AROUND_MULTIPLICATIVE_OP>True</SPACE_AROUND_MULTIPLICATIVE_OP>
<SPACE_BEFORE_SIZEOF_PARENTHESES>False</SPACE_BEFORE_SIZEOF_PARENTHESES> <SPACE_BEFORE_SIZEOF_PARENTHESES>False</SPACE_BEFORE_SIZEOF_PARENTHESES>
<SPACE_BEFORE_TYPEOF_PARENTHESES>False</SPACE_BEFORE_TYPEOF_PARENTHESES>
<WRAP_LIMIT>160</WRAP_LIMIT> <WRAP_LIMIT>160</WRAP_LIMIT>
</FormatSettings> </FormatSettings>
<UsingsSettings /> <UsingsSettings />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace PcapDotNet.Base
{
/// <summary>
/// Extension methods for MemberInfo.
/// </summary>
public static class MemberInfoExtensions
{
/// <summary>
/// When overridden in a derived class, returns a sequence of custom attributes identified by System.Type.
/// </summary>
/// <typeparam name="T">TThe type of attribute to search for. Only attributes that are assignable to this type are returned.</typeparam>
/// <param name="memberInfo">The memberInfo to look the attributes on.</param>
/// <param name="inherit">Specifies whether to search this member's inheritance chain to find the attributes.</param>
/// <returns>A sequence of custom attributes applied to this member, or a sequence with zero (0) elements if no attributes have been applied.</returns>
public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo memberInfo, bool inherit) where T : Attribute
{
if (memberInfo == null)
throw new ArgumentNullException("memberInfo");
return memberInfo.GetCustomAttributes(typeof(T), inherit).Cast<T>();
}
}
}
\ No newline at end of file
...@@ -93,6 +93,7 @@ ...@@ -93,6 +93,7 @@
<Compile Include="IListExtensions.cs" /> <Compile Include="IListExtensions.cs" />
<Compile Include="InlineEqualityComparer.cs" /> <Compile Include="InlineEqualityComparer.cs" />
<Compile Include="MatchExtensions.cs" /> <Compile Include="MatchExtensions.cs" />
<Compile Include="MemberInfoExtensions.cs" />
<Compile Include="PropertyInfoExtensions.cs" /> <Compile Include="PropertyInfoExtensions.cs" />
<Compile Include="TimeSpanExtensions.cs" /> <Compile Include="TimeSpanExtensions.cs" />
<Compile Include="TypeExtensions.cs" /> <Compile Include="TypeExtensions.cs" />
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace PcapDotNet.Base namespace PcapDotNet.Base
{ {
...@@ -19,24 +17,11 @@ namespace PcapDotNet.Base ...@@ -19,24 +17,11 @@ namespace PcapDotNet.Base
} }
} }
/// <summary> public static class ObjectExtensions
/// Extension methods for MemberInfo.
/// </summary>
public static class MemberInfoExtensions
{ {
/// <summary> public static bool IsDefinedEnumValue<T>(this Object enumValue)
/// When overridden in a derived class, returns a sequence of custom attributes identified by System.Type.
/// </summary>
/// <typeparam name="T">TThe type of attribute to search for. Only attributes that are assignable to this type are returned.</typeparam>
/// <param name="memberInfo">The memberInfo to look the attributes on.</param>
/// <param name="inherit">Specifies whether to search this member's inheritance chain to find the attributes.</param>
/// <returns>A sequence of custom attributes applied to this member, or a sequence with zero (0) elements if no attributes have been applied.</returns>
public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo memberInfo, bool inherit) where T : Attribute
{ {
if (memberInfo == null) return Enum.IsDefined(typeof(T), enumValue);
throw new ArgumentNullException("memberInfo");
return memberInfo.GetCustomAttributes(typeof(T), inherit).Cast<T>();
} }
} }
} }
\ No newline at end of file
...@@ -264,12 +264,19 @@ namespace PcapDotNet.Packets.Dns ...@@ -264,12 +264,19 @@ namespace PcapDotNet.Packets.Dns
}; };
} }
/*
protected override bool CalculateIsValid() protected override bool CalculateIsValid()
{ {
return Length >= HeaderBaseLength && Length == HeaderLength; if (_isValid == null)
{
_isValid = Length >= HeaderLength &&
QueryCount == Queries.Count &&
AnswerCount == Answers.Count &&
AuthorityCount == Authorities.Count &&
AdditionalCount == Additionals.Count;
}
return _isValid.Value;
} }
*/
internal DnsDatagram(byte[] buffer, int offset, int length) internal DnsDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length) : base(buffer, offset, length)
{ {
...@@ -397,7 +404,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -397,7 +404,7 @@ namespace PcapDotNet.Packets.Dns
private delegate TRecord ParseRecord<out TRecord>(DnsDatagram dns, int offset, out int numBytesRead); private delegate TRecord ParseRecord<out TRecord>(DnsDatagram dns, int offset, out int numBytesRead);
private void ParseRecords<TRecord>(int offset, Func<ushort> countDelegate, ParseRecord<TRecord> parseRecord, private void ParseRecords<TRecord>(int offset, Func<ushort> countDelegate, ParseRecord<TRecord> parseRecord,
ref ReadOnlyCollection<TRecord> parsedRecords, ref int nextOffset) ref ReadOnlyCollection<TRecord> parsedRecords, ref int nextOffset) where TRecord : DnsResourceRecord
{ {
if (parsedRecords == null && Length >= offset) if (parsedRecords == null && Length >= offset)
{ {
...@@ -428,5 +435,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -428,5 +435,7 @@ namespace PcapDotNet.Packets.Dns
private int _answersOffset; private int _answersOffset;
private int _authoritiesOffset; private int _authoritiesOffset;
private int _additionalsOffset; private int _additionalsOffset;
private bool? _isValid;
} }
} }
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