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