Commit 7304ac50 authored by Brickner_cp's avatar Brickner_cp

Warnings, Code Analysis and Documentation. 444 warnings left.

parent 938da66c
...@@ -9,7 +9,7 @@ namespace PcapDotNet.Base ...@@ -9,7 +9,7 @@ namespace PcapDotNet.Base
/// A 128 bit unsigned integer. /// A 128 bit unsigned integer.
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct UInt128 : IEquatable<UInt128>, IFormattable public struct UInt128 : IComparable<UInt128>, IEquatable<UInt128>, IFormattable
{ {
/// <summary> /// <summary>
/// The number of bytes this type will take. /// The number of bytes this type will take.
...@@ -361,10 +361,11 @@ namespace PcapDotNet.Base ...@@ -361,10 +361,11 @@ namespace PcapDotNet.Base
Equals((UInt128)obj); Equals((UInt128)obj);
} }
public bool Smaller(UInt128 other) public int CompareTo(UInt128 other)
{ {
return _mostSignificant < other._mostSignificant || if (_mostSignificant != other._mostSignificant)
_mostSignificant == other._mostSignificant && _leastSignificant < other._leastSignificant; return _mostSignificant.CompareTo(other._mostSignificant);
return _leastSignificant.CompareTo(other._leastSignificant);
} }
/// <summary> /// <summary>
...@@ -391,22 +392,22 @@ namespace PcapDotNet.Base ...@@ -391,22 +392,22 @@ namespace PcapDotNet.Base
public static bool operator <(UInt128 value1, UInt128 value2) public static bool operator <(UInt128 value1, UInt128 value2)
{ {
return value1.Smaller(value2); return value1.CompareTo(value2) < 0;
} }
public static bool operator >(UInt128 value1, UInt128 value2) public static bool operator >(UInt128 value1, UInt128 value2)
{ {
return value2.Smaller(value1); return value1.CompareTo(value2) > 0;
} }
public static bool operator <=(UInt128 value1, UInt128 value2) public static bool operator <=(UInt128 value1, UInt128 value2)
{ {
return !value2.Smaller(value1); return value1.CompareTo(value2) <= 0;
} }
public static bool operator >=(UInt128 value1, UInt128 value2) public static bool operator >=(UInt128 value1, UInt128 value2)
{ {
return !value1.Smaller(value2); return value1.CompareTo(value2) >= 0;
} }
/// <summary> /// <summary>
...@@ -488,10 +489,10 @@ namespace PcapDotNet.Base ...@@ -488,10 +489,10 @@ namespace PcapDotNet.Base
public static UInt128 operator +(UInt128 value1, UInt128 value2) public static UInt128 operator +(UInt128 value1, UInt128 value2)
{ {
return Sum(value1, value2); return Add(value1, value2);
} }
public static UInt128 Sum(UInt128 value1, UInt128 value2) public static UInt128 Add(UInt128 value1, UInt128 value2)
{ {
ulong leastSignificant = value1._leastSignificant + value2._leastSignificant; ulong leastSignificant = value1._leastSignificant + value2._leastSignificant;
bool overflow = (leastSignificant < Math.Max(value1._leastSignificant, value2._leastSignificant)); bool overflow = (leastSignificant < Math.Max(value1._leastSignificant, value2._leastSignificant));
......
...@@ -24,6 +24,7 @@ OfflinePacketCommunicator::OfflinePacketCommunicator(String^ filename) ...@@ -24,6 +24,7 @@ OfflinePacketCommunicator::OfflinePacketCommunicator(String^ filename)
// Private // Private
// static
pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName) pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName)
{ {
std::wstring unamangedFilename = MarshalingServices::ManagedToUnmanagedWideString(fileName); std::wstring unamangedFilename = MarshalingServices::ManagedToUnmanagedWideString(fileName);
...@@ -35,8 +36,11 @@ pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName) ...@@ -35,8 +36,11 @@ pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName)
pcap_t *pcapDescriptor = pcap_fopen_offline(file, errorBuffer); pcap_t *pcapDescriptor = pcap_fopen_offline(file, errorBuffer);
if (pcapDescriptor == NULL) if (pcapDescriptor == NULL)
{ {
fclose(file); int fcloseResult = fclose(file);
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Failed opening file {0}. Error: {1}", fileName, gcnew String(errorBuffer))); String^ errorMessage = String::Format(CultureInfo::InvariantCulture, "Failed opening file {0}. Error: {1}.", fileName, gcnew String(errorBuffer));
if (fcloseResult != 0)
errorMessage += " Also failed closing the file.";
throw gcnew InvalidOperationException(errorMessage);
} }
return pcapDescriptor; return pcapDescriptor;
......
...@@ -28,6 +28,6 @@ namespace PcapDotNet { namespace Core ...@@ -28,6 +28,6 @@ namespace PcapDotNet { namespace Core
OfflinePacketCommunicator(System::String^ fileName); OfflinePacketCommunicator(System::String^ fileName);
private: private:
pcap_t* OpenFile(System::String^ filename); static pcap_t* OpenFile(System::String^ filename);
}; };
}} }}
\ No newline at end of file
...@@ -27,14 +27,14 @@ namespace PcapDotNet.Packets.Dns ...@@ -27,14 +27,14 @@ namespace PcapDotNet.Packets.Dns
/// For example, SOA records are always distributed with a zero TTL to prohibit caching. /// For example, SOA records are always distributed with a zero TTL to prohibit caching.
/// Zero values can also be used for extremely volatile data. /// Zero values can also be used for extremely volatile data.
/// </summary> /// </summary>
public override int Ttl { get; protected set; } public override sealed int Ttl { get; protected set; }
/// <summary> /// <summary>
/// A variable length string of octets that describes the resource. /// A variable length string of octets that describes the resource.
/// The format of this information varies according to the TYPE and CLASS of the resource record. /// The format of this information varies according to the TYPE and CLASS of the resource record.
/// For example, the if the TYPE is A and the CLASS is IN, the RDATA field is a 4 octet ARPA Internet address. /// For example, the if the TYPE is A and the CLASS is IN, the RDATA field is a 4 octet ARPA Internet address.
/// </summary> /// </summary>
public override DnsResourceData Data { get; protected set; } public override sealed DnsResourceData Data { get; protected set; }
public override string ToString() public override string ToString()
{ {
...@@ -75,7 +75,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -75,7 +75,7 @@ namespace PcapDotNet.Packets.Dns
numBytesRead += MinimumLengthAfterBase; numBytesRead += MinimumLengthAfterBase;
if (offsetInDns + numBytesRead + dataLength > dns.Length) if (offsetInDns + numBytesRead + dataLength > dns.Length)
return null; return null;
DnsResourceData data = DnsResourceData.Read(dns, type, dnsClass, offsetInDns + numBytesRead, dataLength); DnsResourceData data = DnsResourceData.Read(dns, type, offsetInDns + numBytesRead, dataLength);
if (data == null) if (data == null)
return null; return null;
numBytesRead += dataLength; numBytesRead += dataLength;
......
...@@ -88,7 +88,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -88,7 +88,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary> /// <summary>
/// The number of bytes the DNS header takes. /// The number of bytes the DNS header takes.
/// </summary> /// </summary>
public const int HeaderLength = 12; public const int HeaderLength = Offset.Query;
/// <summary> /// <summary>
/// A 16 bit identifier assigned by the program that generates any kind of query. /// A 16 bit identifier assigned by the program that generates any kind of query.
...@@ -424,11 +424,6 @@ namespace PcapDotNet.Packets.Dns ...@@ -424,11 +424,6 @@ namespace PcapDotNet.Packets.Dns
} }
} }
private int QueriesOffset
{
get { return HeaderLength; }
}
private int AnswersOffset private int AnswersOffset
{ {
get get
...@@ -458,7 +453,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -458,7 +453,7 @@ namespace PcapDotNet.Packets.Dns
private void ParseQueries() private void ParseQueries()
{ {
ParseRecords(QueriesOffset, () => QueryCount, DnsQueryResourceRecord.Parse, ref _queries, ref _answersOffset); ParseRecords(Offset.Query, () => QueryCount, DnsQueryResourceRecord.Parse, ref _queries, ref _answersOffset);
} }
private void ParseAnswers() private void ParseAnswers()
......
...@@ -31,7 +31,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -31,7 +31,7 @@ namespace PcapDotNet.Packets.Dns
offsetInDns = 0; offsetInDns = 0;
return false; return false;
default: default:
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid DomainNameCompressionMode {0}", throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid Domain Name Compression Mode {0}",
DomainNameCompressionMode)); DomainNameCompressionMode));
} }
} }
...@@ -50,7 +50,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -50,7 +50,7 @@ namespace PcapDotNet.Packets.Dns
case DnsDomainNameCompressionMode.Nothing: case DnsDomainNameCompressionMode.Nothing:
return; return;
default: default:
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid DomainNameCompressionMode {0}", throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid Domain Name Compression Mode {0}",
DomainNameCompressionMode)); DomainNameCompressionMode));
} }
} }
......
...@@ -38,25 +38,25 @@ namespace PcapDotNet.Packets.Dns ...@@ -38,25 +38,25 @@ namespace PcapDotNet.Packets.Dns
public DnsResponseCode ResponseCode { get; set; } public DnsResponseCode ResponseCode { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<DnsQueryResourceRecord> Queries { get; set; } public IList<DnsQueryResourceRecord> Queries { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<DnsDataResourceRecord> Answers { get; set; } public IList<DnsDataResourceRecord> Answers { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<DnsDataResourceRecord> Authorities { get; set; } public IList<DnsDataResourceRecord> Authorities { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<DnsDataResourceRecord> Additionals { get; set; } public IList<DnsDataResourceRecord> Additionals { get; set; }
public IEnumerable<DnsResourceRecord> Records public IEnumerable<DnsResourceRecord> ResourceRecords
{ {
get get
{ {
IEnumerable<DnsResourceRecord> allRecords = null; return new IEnumerable<DnsResourceRecord>[] {Queries, Answers, Authorities, Additionals}
foreach (IEnumerable<DnsResourceRecord> records in new IEnumerable<DnsResourceRecord>[] {Queries,Answers,Authorities,Additionals}) .Where(records => records != null).Aggregate<IEnumerable<DnsResourceRecord>, IEnumerable<DnsResourceRecord>>(
{ null, (current, records) => current == null ? records : current.Concat(records));
if (records != null)
allRecords = allRecords == null ? records : allRecords.Concat(records);
}
return allRecords;
} }
} }
...@@ -69,7 +69,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -69,7 +69,7 @@ namespace PcapDotNet.Packets.Dns
{ {
get get
{ {
return DnsDatagram.GetLength(Records, DomainNameCompressionMode); return DnsDatagram.GetLength(ResourceRecords, DomainNameCompressionMode);
} }
} }
......
using System; using System.Collections;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -36,7 +35,6 @@ namespace PcapDotNet.Packets.Dns ...@@ -36,7 +35,6 @@ namespace PcapDotNet.Packets.Dns
public T this[int index] public T this[int index]
{ {
get { return _data[_startIndex + index]; } get { return _data[_startIndex + index]; }
set { throw new NotSupportedException("ListSegment<T> is read-only"); }
} }
private readonly IList<T> _data; private readonly IList<T> _data;
......
...@@ -32,7 +32,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -32,7 +32,7 @@ namespace PcapDotNet.Packets.Dns
internal abstract int WriteData(byte[] buffer, int dnsOffset, int offsetInDns, DnsDomainNameCompressionData compressionData); internal abstract int WriteData(byte[] buffer, int dnsOffset, int offsetInDns, DnsDomainNameCompressionData compressionData);
internal static DnsResourceData Read(DnsDatagram dns, DnsType type, DnsClass dnsClass, int offsetInDns, int length) internal static DnsResourceData Read(DnsDatagram dns, DnsType type, int offsetInDns, int length)
{ {
DnsResourceData prototype = TryGetPrototype(type); DnsResourceData prototype = TryGetPrototype(type);
if (prototype != null) if (prototype != null)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace PcapDotNet.Packets.Dns namespace PcapDotNet.Packets.Dns
{ {
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
internal class DnsTypeRegistrationAttribute : Attribute internal sealed class DnsTypeRegistrationAttribute : Attribute
{ {
public DnsType Type { get; set; } public DnsType Type { get; set; }
} }
......
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