Replace DnDns with HeijdenDns

HeijdenDns seems to do a better job at querying SRV records
This commit is contained in:
ORelio 2017-03-11 15:28:32 +01:00
parent a344ac4101
commit 693073edfc
112 changed files with 5491 additions and 5009 deletions

View file

@ -123,46 +123,75 @@
<Compile Include="Mapping\Material.cs" />
<Compile Include="Mapping\Movement.cs" />
<Compile Include="Mapping\World.cs" />
<Compile Include="Protocol\Dns\DnsHelpers.cs" />
<Compile Include="Protocol\Dns\Enums\NsClass.cs" />
<Compile Include="Protocol\Dns\Enums\NsFlags.cs" />
<Compile Include="Protocol\Dns\Enums\NsType.cs" />
<Compile Include="Protocol\Dns\Enums\TcpServices.cs" />
<Compile Include="Protocol\Dns\Enums\UdpServices.cs" />
<Compile Include="Protocol\Dns\Query\DnsQueryBase.cs" />
<Compile Include="Protocol\Dns\Query\DnsQueryRequest.cs" />
<Compile Include="Protocol\Dns\Query\DnsQueryResponse.cs" />
<Compile Include="Protocol\Dns\Records\AaaaRecord.cs" />
<Compile Include="Protocol\Dns\Records\AfsdbRecord.cs" />
<Compile Include="Protocol\Dns\Records\ARecord.cs" />
<Compile Include="Protocol\Dns\Records\AtmaRecord.cs" />
<Compile Include="Protocol\Dns\Records\BaseDnsRecord.cs" />
<Compile Include="Protocol\Dns\Records\CNameRecord.cs" />
<Compile Include="Protocol\Dns\Records\HInfoRecord.cs" />
<Compile Include="Protocol\Dns\Records\IDnsRecord.cs" />
<Compile Include="Protocol\Dns\Records\IsdnRecord.cs" />
<Compile Include="Protocol\Dns\Records\LocRecord.cs" />
<Compile Include="Protocol\Dns\Records\MbRecord.cs" />
<Compile Include="Protocol\Dns\Records\MgRecord.cs" />
<Compile Include="Protocol\Dns\Records\MInfoRecord.cs" />
<Compile Include="Protocol\Dns\Records\MrRecord.cs" />
<Compile Include="Protocol\Dns\Records\MxRecord.cs" />
<Compile Include="Protocol\Dns\Records\NsRecord.cs" />
<Compile Include="Protocol\Dns\Records\PtrRecord.cs" />
<Compile Include="Protocol\Dns\Records\RecordFactory.cs" />
<Compile Include="Protocol\Dns\Records\RecordHeader.cs" />
<Compile Include="Protocol\Dns\Records\RpRecord.cs" />
<Compile Include="Protocol\Dns\Records\RtRecord.cs" />
<Compile Include="Protocol\Dns\Records\SoaRecord.cs" />
<Compile Include="Protocol\Dns\Records\SrvRecord.cs" />
<Compile Include="Protocol\Dns\Records\TSigRecord.cs" />
<Compile Include="Protocol\Dns\Records\TxtRecord.cs" />
<Compile Include="Protocol\Dns\Records\UnknownRecord.cs" />
<Compile Include="Protocol\Dns\Records\WksRecord.cs" />
<Compile Include="Protocol\Dns\Records\X25Record.cs" />
<Compile Include="Protocol\Dns\Security\IMessageSecurityProvider.cs" />
<Compile Include="Protocol\Dns\Security\TsigMessageSecurityProvider.cs" />
<Compile Include="Protocol\Dns\Tools.cs" />
<Compile Include="Protocol\Dns\Header.cs" />
<Compile Include="Protocol\Dns\Question.cs" />
<Compile Include="Protocol\Dns\RecordReader.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordA6.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordAPL.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordATMA.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordCERT.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordDHCID.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordDNSKEY.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordEID.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordGID.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordHIP.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordIPSECKEY.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordNIMLOC.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordNSEC.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordNSEC3.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordNSEC3PARAM.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordOPT.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordRRSIG.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordSINK.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordSPF.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordSSHFP.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordUID.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordUINFO.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordUnknown.cs" />
<Compile Include="Protocol\Dns\Records\NotUsed\RecordUNSPEC.cs" />
<Compile Include="Protocol\Dns\Records\Obsolete\RecordGPOS.cs" />
<Compile Include="Protocol\Dns\Records\Obsolete\RecordMD.cs" />
<Compile Include="Protocol\Dns\Records\Obsolete\RecordMF.cs" />
<Compile Include="Protocol\Dns\Records\Obsolete\RecordNSAPPTR.cs" />
<Compile Include="Protocol\Dns\Records\Obsolete\RecordNXT.cs" />
<Compile Include="Protocol\Dns\Records\Record.cs" />
<Compile Include="Protocol\Dns\Records\RecordA.cs" />
<Compile Include="Protocol\Dns\Records\RecordAAAA.cs" />
<Compile Include="Protocol\Dns\Records\RecordAFSDB.cs" />
<Compile Include="Protocol\Dns\Records\RecordCNAME.cs" />
<Compile Include="Protocol\Dns\Records\RecordDNAME.cs" />
<Compile Include="Protocol\Dns\Records\RecordDS.cs" />
<Compile Include="Protocol\Dns\Records\RecordHINFO.cs" />
<Compile Include="Protocol\Dns\Records\RecordISDN.cs" />
<Compile Include="Protocol\Dns\Records\RecordKEY.cs" />
<Compile Include="Protocol\Dns\Records\RecordKX.cs" />
<Compile Include="Protocol\Dns\Records\RecordLOC.cs" />
<Compile Include="Protocol\Dns\Records\RecordMB.cs" />
<Compile Include="Protocol\Dns\Records\RecordMG.cs" />
<Compile Include="Protocol\Dns\Records\RecordMINFO.cs" />
<Compile Include="Protocol\Dns\Records\RecordMR.cs" />
<Compile Include="Protocol\Dns\Records\RecordMX.cs" />
<Compile Include="Protocol\Dns\Records\RecordNAPTR.cs" />
<Compile Include="Protocol\Dns\Records\RecordNS.cs" />
<Compile Include="Protocol\Dns\Records\RecordNSAP.cs" />
<Compile Include="Protocol\Dns\Records\RecordNULL.cs" />
<Compile Include="Protocol\Dns\Records\RecordPTR.cs" />
<Compile Include="Protocol\Dns\Records\RecordPX.cs" />
<Compile Include="Protocol\Dns\Records\RecordRP.cs" />
<Compile Include="Protocol\Dns\Records\RecordRT.cs" />
<Compile Include="Protocol\Dns\Records\RecordSIG.cs" />
<Compile Include="Protocol\Dns\Records\RecordSOA.cs" />
<Compile Include="Protocol\Dns\Records\RecordSRV.cs" />
<Compile Include="Protocol\Dns\Records\RecordTKEY.cs" />
<Compile Include="Protocol\Dns\Records\RecordTSIG.cs" />
<Compile Include="Protocol\Dns\Records\RecordTXT.cs" />
<Compile Include="Protocol\Dns\Records\RecordWKS.cs" />
<Compile Include="Protocol\Dns\Records\RecordX25.cs" />
<Compile Include="Protocol\Dns\Request.cs" />
<Compile Include="Protocol\Dns\Resolver.cs" />
<Compile Include="Protocol\Dns\Response.cs" />
<Compile Include="Protocol\Dns\RR.cs" />
<Compile Include="Protocol\Dns\Structs.cs" />
<Compile Include="Protocol\Handlers\Forge\FMLHandshakeClientState.cs" />
<Compile Include="Protocol\Handlers\Forge\FMLHandshakeDiscriminator.cs" />
<Compile Include="Protocol\Handlers\Forge\ForgeInfo.cs" />
@ -229,6 +258,7 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="Protocol\Dns\Records\totla.txt" />
<Content Include="Resources\AppIcon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View file

@ -1,115 +0,0 @@
using System;
using System.Diagnostics;
using System.Text;
namespace DnDns
{
internal static class DnsHelpers
{
private const long Epoch = 621355968000000000;
internal static byte[] CanonicaliseDnsName(string name, bool lowerCase)
{
if (!name.EndsWith("."))
{
name += ".";
}
if (name == ".")
{
return new byte[1];
}
StringBuilder sb = new StringBuilder();
sb.Append('\0');
for (int i = 0, j = 0; i < name.Length; i++, j++)
{
if (lowerCase)
{
sb.Append(char.ToLower(name[i]));
}
else
{
sb.Append(name[i]);
}
if (name[i] == '.')
{
sb[i - j] = (char) (j & 0xff);
j = -1;
}
}
sb[sb.Length - 1] = '\0';
return Encoding.ASCII.GetBytes(sb.ToString());
}
internal static String DumpArrayToString(byte[] bytes)
{
StringBuilder builder = new StringBuilder();
builder.Append("[");
foreach (byte b in bytes)
{
builder.Append(" ");
builder.Append((sbyte)b);
builder.Append(" ");
}
builder.Append("]");
return builder.ToString();
}
/// <summary>
/// Converts a instance of a <see cref="DateTime"/> class to a 48 bit format time since epoch.
/// Epoch is defined as 1-Jan-70 UTC.
/// </summary>
/// <param name="dateTimeToConvert">The <see cref="DateTime"/> instance to convert to DNS format.</param>
/// <param name="timeHigh">The upper 16 bits of time.</param>
/// <param name="timeLow">The lower 32 bits of the time object.</param>
internal static void ConvertToDnsTime(DateTime dateTimeToConvert, out int timeHigh, out long timeLow)
{
long secondsFromEpoch = (dateTimeToConvert.ToUniversalTime().Ticks - Epoch) / 10000000;
timeHigh = (int)(secondsFromEpoch >> 32);
timeLow = (secondsFromEpoch & 0xFFFFFFFFL);
Trace.WriteLine(String.Format("Date: {0}", dateTimeToConvert));
Trace.WriteLine(String.Format("secondsFromEpoch: {0}", secondsFromEpoch));
Trace.WriteLine(String.Format("timeHigh: {0}", timeHigh));
Trace.WriteLine(String.Format("timeLow: {0}", timeLow));
}
/// <summary>
/// Convert from DNS 48 but time format to a <see cref="DateTime"/> instance.
/// </summary>
/// <param name="timeHigh">The upper 16 bits of time.</param>
/// <param name="timeLow">The lower 32 bits of the time object.</param>
/// <returns>The converted date time</returns>
internal static DateTime ConvertFromDnsTime(long timeLow, long timeHigh)
{
long time = (timeHigh << 32) + timeLow;
time = time*10000000;
time += Epoch;
return new DateTime(time);
}
/// <summary>
/// Convert from DNS 48 but time format to a <see cref="DateTime"/> instance.
/// </summary>
/// <param name="dnsTime">The upper 48 bits of time.</param>
/// <returns>The converted date time</returns>
internal static DateTime ConvertFromDnsTime(long dnsTime)
{
dnsTime = dnsTime * 10000000;
dnsTime += Epoch;
return new DateTime(dnsTime);
}
}
}

View file

@ -1,94 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace DnDns.Enums
{
/// <summary>
/// RFC 1035:
///
/// 3.2.4. CLASS values
///
/// CLASS fields appear in resource records. The following CLASS mnemonics
/// and values are defined:
///
/// IN 1 the Internet
///
/// CS 2 the CSNET class (Obsolete - used only for examples in
/// some obsolete RFCs)
///
/// CH 3 the CHAOS class
///
/// HS 4 Hesiod [Dyer 87]
///
/// 3.2.5. QCLASS values
///
/// QCLASS fields appear in the question section of a query. QCLASS values
/// are a superset of CLASS values; every CLASS is a valid QCLASS. In
/// addition to CLASS values, the following QCLASSes are defined:
///
/// * 255 any class
/// </summary>
public enum NsClass : byte
{
/// <summary>
/// Cookie?? - NOT IMPLEMENTED
/// </summary>
INVALID = 0,
/// <summary>
/// // Internet (inet), RFC 1035
/// </summary>
INET = 1,
/// <summary>
/// MIT Chaos-net, RFC 1035 - NOT IMPLEMENTED
/// </summary>
CHAOS = 3,
/// <summary>
/// MIT Hesiod, RFC 1035 - NOT IMPLEMENTED
/// </summary>
HS = 4,
/// <summary>
/// RFC 2136 - None
/// prereq sections in update requests -- NOT IMPLEMENTED
/// </summary>
NONE = 254,
/// <summary>
/// Any QCLASS only, Wildcard match, RFC 1035 - IMPLEMENTED for INET only
/// </summary>
ANY = 255
}
}

View file

@ -1,298 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace DnDns.Enums
{
// DNS HEADER: http://www.faqs.org/rfcs/rfc1035.html
// 1 1 1 1 1 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | Query Identifier |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// |QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE | <-- The Enums below are combined to create this 16 bit (2 byte) field
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QDCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ANCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | NSCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ARCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// <summary>
/// FlagMasks are used as a bitmask to isolate bits 16 through 31 of the DNS header to convert
/// them to their appropriate Enum types
/// </summary>
internal enum FlagMasks : ushort
{
QueryResponseMask = 0x8000,
OpCodeMask = 0x7800,
NsFlagMask = 0x07F0,
RCodeMask = 0x000F
}
/// <summary>
/// |QR| - Starts at bit 16 of DNS Header, size: 1 bit
///
/// RFC 1035:
/// A one bit field that specifies whether this message is a
/// query (0), or a response (1).
///
/// </summary>
[Flags()]
public enum QueryResponse : ushort
{
/// <summary>
/// // QR Query or Response [RFC1035] ( 0 = Query )
/// </summary>
Query = 0x0,
/// <summary>
/// // QR Query or Response [RFC1035] ( 1 = Response )
/// </summary>
Response = 0x8000
}
/// <summary>
/// | OpCode | - 4 bits of Dns header, Bit 17 - 20, see RFC 1035
///
/// RFC 1035:
///
/// A four bit field that specifies kind of query in this
/// message. This value is set by the originator of a query
/// and copied into the response.
///
/// The values are:
///
/// 0 a standard query (QUERY)
///
/// 1 an inverse query (IQUERY)
///
/// 2 a server status request (STATUS)
///
/// 3-15 reserved for future
/// </summary>
[Flags()]
public enum OpCode : ushort
{
/// <summary>
/// Standard query
/// [RFC1035] (QUERY)
/// </summary>
QUERY = 0x0000,
/// <summary>
/// Inverse query
/// [RFC1035] (IQUERY)
/// </summary>
IQUERY = 0x0800,
/// <summary>
/// Server status request
/// [RFC1035] (STATUS)
/// </summary>
STATUS = 0x1000,
}
/// <summary>
/// |AA|TC|RD|RA| Z|AD|CD| - 8 bits (1 byte) flag fields
///
/// reference: http://www.networksorcery.com/enp/protocol/dns.htm
/// </summary>
[Flags()]
public enum NsFlags : ushort
{
/// <summary>
/// AA - Authorative Answer [RFC1035] ( 0 = Not authoritative, 1 = Is authoritative )
/// Authoritative Answer - this bit is valid in responses,
/// and specifies that the responding name server is an
/// authority for the domain name in question section.
///
/// Note that the contents of the answer section may have
/// multiple owner names because of aliases. The AA bit
/// corresponds to the name which matches the query name, or
/// the first owner name in the answer section.
/// </summary>
AA = 0x0400,
/// <summary>
/// TC - Truncated Response [RFC1035] ( 0 = Not truncated, 1 = Message truncated )
///
/// TrunCation - specifies that this message was truncated
/// due to length greater than that permitted on the
/// transmission channel.
/// </summary>
TC = 0x0200,
/// <summary>
/// RD - Recursion Desired [RFC1035] ( 0 = Recursion not desired, 1 = Recursion desired )
///
/// Recursion Desired - this bit may be set in a query and
/// is copied into the response. If RD is set, it directs
/// the name server to pursue the query recursively.
/// Recursive query support is optional.
/// </summary>
RD = 0x0100,
/// <summary>
/// RA - Recursion Allowed [RFC1035] ( 0 = Recursive query support not available, 1 = Recursive query support available )
///
/// Recursion Available - this be is set or cleared in a
/// response, and denotes whether recursive query support is
/// available in the name server.
/// </summary>
RA = 0x0080,
/// <summary>
/// AD - Authentic Data [RFC4035] ( Authenticated data. 1 bit ) [NOT IMPLEMENTED]
///
/// Indicates in a response that all data included in the answer and authority
/// sections of the response have been authenticated by the server according to
/// the policies of that server. It should be set only if all data in the response
/// has been cryptographically verified or otherwise meets the server's local security
/// policy.
/// </summary>
AD = 0x0020,
/// <summary>
/// CD - Checking Disabled [RFC4035] ( Checking Disabled. 1 bit ) [NOT IMPLEMENTED]
/// </summary>
CD = 0x0010
}
/// <summary>
/// | RCODE | - 4 bits error codes
///
/// Response code - this 4 bit field is set as part of
/// responses. The values have the following interpretation:
///
/// Fields 6-15 Reserved for future use.
///
/// reference: http://www.networksorcery.com/enp/protocol/dns.htm
/// </summary>
[Flags()]
public enum RCode : ushort
{
/// <summary>
/// No error condition
/// </summary>
NoError = 0,
/// <summary>
/// Format error - The name server was unable to
/// interpret the query.
/// </summary>
FormatError = 1,
/// <summary>
/// Server failure - The name server was unable to process
/// this query due to a problem with the name server.
/// </summary>
ServerFailure = 2,
/// <summary>
/// Name Error - Meaningful only for responses from an
/// authoritative name server, this code signifies that
/// the domain name referenced in the query does not
/// exist.
/// </summary>
NameError = 3,
/// <summary>
/// Not Implemented - The name server does not support
/// the requested kind of query.
/// </summary>
NotImplemented = 4,
/// <summary>
/// Refused - The name server refuses to perform the
/// specified operation for policy reasons. For example,
/// a name server may not wish to provide the information
/// to the particular requester, or a name server may not
/// wish to perform a particular operation (e.g., zone
/// transfer) for particular data.
/// </summary>
Refused = 5,
/// <summary>
/// RFC 2136
/// Name Exists when it should not.
/// </summary>
YXDomain = 6,
/// <summary>
/// RFC 2136
/// RR Set Exists when it should not.
/// </summary>
YXRRSet = 7,
/// <summary>
/// RFC 2136
/// RR Set that should exist does not.
/// </summary>
NXRRSet = 8,
/// <summary>
/// RFC 2136
/// Server Not Authoritative for zone.
/// </summary>
NotAuth = 9,
/// <summary>
/// RFC 2136
/// Name not contained in zone.
/// </summary>
NotZone = 10,
/// <summary>
/// RFC 2671
/// RFC 2845
///
/// BADVERS Bad OPT Version.
/// BADSIG TSIG Signature Failure.
/// </summary>
BADVERS_BADSIG = 16,
/// <summary>
/// RFC 2845
/// Key not recognized.
/// </summary>
BADKEY = 17,
/// <summary>
/// RFC 2845
/// Signature out of time window.
/// </summary>
BADTIME = 18,
/// <summary>
/// RFC 2930
/// Bad TKEY Mode.
/// </summary>
BADMODE = 19,
/// <summary>
/// RFC 2930
/// Duplicate key name.
/// </summary>
BADNAME = 20,
/// <summary>
/// RFC 2930
/// Algorithm not supported.
/// </summary>
BADALG = 21
}
}

View file

@ -1,305 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace DnDns.Enums
{
/// <summary>
/// Currently defined type values for resources and queries.
///
/// RFC 1034
///
/// 3.2.2. TYPE values
///
/// TYPE fields are used in resource records. Note that these types are a
/// subset of QTYPEs.
///
/// TYPE value and meaning
///
/// A 1 a host address, Implemented
///
/// NS 2 an authoritative name server, Implemented
///
/// MD 3 a mail destination (Obsolete - use MX), NOT Implemented
///
/// MF 4 a mail forwarder (Obsolete - use MX), NOT Implemented
///
/// CNAME 5 the canonical name for an alias, Implemented
///
/// SOA 6 marks the start of a zone of authority, Implemented
///
/// MB 7 a mailbox domain name (EXPERIMENTAL), Implemented
///
/// MG 8 a mail group member (EXPERIMENTAL), Implemented
///
/// MR 9 a mail rename domain name (EXPERIMENTAL), Implemented
///
/// NULL 10 a null RR (EXPERIMENTAL), NOT IMPLEMENTED
///
/// WKS 11 a well known service description
///
/// PTR 12 a domain name pointer
///
/// HINFO 13 host information
///
/// MINFO 14 mailbox or mail list information
///
/// MX 15 mail exchange
///
/// TXT 16 text strings
///
/// 3.2.3. QTYPE values
///
/// QTYPE fields appear in the question part of a query. QTYPES are a
/// superset of TYPEs, hence all TYPEs are valid QTYPEs. In addition, the
/// following QTYPEs are defined:
///
/// AXFR 252 A request for a transfer of an entire zone
///
/// MAILB 253 A request for mailbox-related records (MB, MG or MR)
///
/// MAILA 254 A request for mail agent RRs (Obsolete - see MX)
///
/// * 255 A request for all records
///
/// </summary>
public enum NsType : uint
{
/// <summary>
/// Invalid
/// </summary>
INVALID = 0,
/// <summary>
/// Host address
/// </summary>
A = 1,
/// <summary>
/// Authoritative server
/// </summary>
NS = 2,
/// <summary>
/// Mail destination - NOT IMPLEMENTED
/// </summary>
MD = 3,
/// <summary>
/// Mail forwarder, NOT IMPLEMENTED
/// </summary>
MF = 4,
/// <summary>
/// Canonical name
/// </summary>
CNAME = 5,
/// <summary>
/// Start of authority zone
/// </summary>
SOA = 6,
// Mailbox domain name
MB = 7,
/// <summary>
/// Mail group member
/// </summary>
MG = 8,
/// <summary>
/// Mail rename name
/// </summary>
MR = 9,
/// <summary>
/// Null resource record
/// </summary>
NULL = 10,
/// <summary>
/// Well known service
/// </summary>
WKS = 11,
/// <summary>
/// Domain name pointer
/// </summary>
PTR = 12,
/// <summary>
/// Host information
/// </summary>
HINFO = 13,
/// <summary>
/// Mailbox information
/// </summary>
MINFO = 14,
/// <summary>
/// Mail routing information
/// </summary>
MX = 15,
/// <summary>
/// Text strings, RFC 1464
/// </summary>
TXT = 16,
/// <summary>
/// Responsible person, RFC 1183, Implemented
/// </summary>
RP = 17,
/// <summary>
/// AFS cell database, RFC 1183, Implemented
/// </summary>
AFSDB = 18,
/// <summary>
/// X_25 calling address, RFC 1183, Implemented
/// </summary>
X25 = 19,
/// <summary>
/// ISDN calling address, RFC 1183, Implemented
/// </summary>
ISDN = 20,
/// <summary>
/// Router, RFC 1183, Implemented
/// </summary>
RT = 21,
/// <summary>
/// NSAP address, RFC 1706
/// </summary>
NSAP = 22,
/// <summary>
/// Reverse NSAP lookup - deprecated by PTR ?
/// </summary>
NSAP_PTR = 23,
/// <summary>
/// Security signature, RFC 2535
/// </summary>
SIG = 24,
/// <summary>
/// Security key, RFC 2535
/// </summary>
KEY = 25,
/// <summary>
/// X.400 mail mapping, RFC ?
/// </summary>
PX = 26,
/// <summary>
/// Geographical position - withdrawn, RFC 1712
/// </summary>
GPOS = 27,
/// <summary>
/// Ip6 Address, RFC 1886 -- Implemented
/// </summary>
AAAA = 28,
/// <summary>
/// Location Information, RFC 1876, Implemented
/// </summary>
LOC = 29,
/// <summary>
/// Next domain (security), RFC 2065
/// </summary>
NXT = 30,
/// <summary>
/// Endpoint identifier,RFC ?
/// </summary>
EID = 31,
/// <summary>
/// Nimrod Locator, RFC ?
/// </summary>
NIMLOC = 32,
/// <summary>
/// Server Record, RFC 2052, Implemented
/// </summary>
SRV = 33,
/// <summary>
/// ATM Address, RFC ?, Implemented
/// </summary>
ATMA = 34,
/// <summary>
/// Naming Authority PoinTeR, RFC 2915
/// </summary>
MAPTR = 35,
/// <summary>
/// Key Exchange, RFC 2230
/// </summary>
KX = 36,
/// <summary>
/// Certification record, RFC 2538
/// </summary>
CERT = 37,
/// <summary>
/// IPv6 address (deprecates AAAA), RFC 3226
/// </summary>
A6 = 38,
/// <summary>
/// Non-terminal DNAME (for IPv6), RFC 2874
/// </summary>
DNAME = 39,
/// <summary>
/// Kitchen sink (experimentatl), RFC ?
/// </summary>
SINK = 40,
/// <summary>
/// EDNS0 option (meta-RR), RFC 2671
/// </summary>
OPT = 41,
/// <summary>
/// Transaction key, RFC 2930
/// </summary>
TKEY = 249,
/// <summary>
/// Transaction signature, RFC 2845
/// </summary>
TSIG = 250,
/// <summary>
/// Incremental zone transfer, RFC 1995
/// </summary>
IXFR = 251,
/// <summary>
/// Transfer zone of authority, RFC 1035
/// </summary>
AXFR = 252,
/// <summary>
/// Transfer mailbox records, RFC 1035
/// </summary>
MAILB = 253,
/// <summary>
/// Transfer mail agent records, RFC 1035
/// </summary>
MAILA = 254,
/// <summary>
/// All of the above, RFC 1035
/// </summary>
ANY = 255,
/// <summary>
/// DNSSEC Trust Authorities
/// </summary>
DNSSECTrustAuthorities = 32768,
/// <summary>
/// DNSSEC Lookaside Validation, RFC4431
/// </summary>
DNSSECLookasideValidation = 32769
}
}

View file

@ -1,51 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace DnDns.Enums
{
/// <summary>
/// Defines Well Known TCP Ports for Services
/// </summary>
public enum TcpServices : short
{
/// <summary>
/// Domain Name Server Port
/// </summary>
Domain = 53
}
}

View file

@ -1,51 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace DnDns.Enums
{
/// <summary>
/// Defines Well Known UDP Ports for Services
/// </summary>
public enum UdpServices : short
{
/// <summary>
/// Domain Name Server Protocol Port
/// </summary>
Domain = 53
}
}

View file

@ -0,0 +1,351 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace Heijden.DNS
{
#region RFC specification
/*
4.1.1. Header section format
The header contains the following fields:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
ID A 16 bit identifier assigned by the program that
generates any kind of query. This identifier is copied
the corresponding reply and can be used by the requester
to match up replies to outstanding queries.
QR A one bit field that specifies whether this message is a
query (0), or a response (1).
OPCODE A four bit field that specifies kind of query in this
message. This value is set by the originator of a query
and copied into the response. The values are:
0 a standard query (QUERY)
1 an inverse query (IQUERY)
2 a server status request (STATUS)
3-15 reserved for future use
AA Authoritative Answer - this bit is valid in responses,
and specifies that the responding name server is an
authority for the domain name in question section.
Note that the contents of the answer section may have
multiple owner names because of aliases. The AA bit
corresponds to the name which matches the query name, or
the first owner name in the answer section.
TC TrunCation - specifies that this message was truncated
due to length greater than that permitted on the
transmission channel.
RD Recursion Desired - this bit may be set in a query and
is copied into the response. If RD is set, it directs
the name server to pursue the query recursively.
Recursive query support is optional.
RA Recursion Available - this be is set or cleared in a
response, and denotes whether recursive query support is
available in the name server.
Z Reserved for future use. Must be zero in all queries
and responses.
RCODE Response code - this 4 bit field is set as part of
responses. The values have the following
interpretation:
0 No error condition
1 Format error - The name server was
unable to interpret the query.
2 Server failure - The name server was
unable to process this query due to a
problem with the name server.
3 Name Error - Meaningful only for
responses from an authoritative name
server, this code signifies that the
domain name referenced in the query does
not exist.
4 Not Implemented - The name server does
not support the requested kind of query.
5 Refused - The name server refuses to
perform the specified operation for
policy reasons. For example, a name
server may not wish to provide the
information to the particular requester,
or a name server may not wish to perform
a particular operation (e.g., zone
transfer) for particular data.
6-15 Reserved for future use.
QDCOUNT an unsigned 16 bit integer specifying the number of
entries in the question section.
ANCOUNT an unsigned 16 bit integer specifying the number of
resource records in the answer section.
NSCOUNT an unsigned 16 bit integer specifying the number of name
server resource records in the authority records
section.
ARCOUNT an unsigned 16 bit integer specifying the number of
resource records in the additional records section.
*/
#endregion
public class Header
{
/// <summary>
/// An identifier assigned by the program
/// </summary>
public ushort ID;
// internal flag
private ushort Flags;
/// <summary>
/// the number of entries in the question section
/// </summary>
public ushort QDCOUNT;
/// <summary>
/// the number of resource records in the answer section
/// </summary>
public ushort ANCOUNT;
/// <summary>
/// the number of name server resource records in the authority records section
/// </summary>
public ushort NSCOUNT;
/// <summary>
/// the number of resource records in the additional records section
/// </summary>
public ushort ARCOUNT;
public Header()
{
}
public Header(RecordReader rr)
{
ID = rr.ReadUInt16();
Flags = rr.ReadUInt16();
QDCOUNT = rr.ReadUInt16();
ANCOUNT = rr.ReadUInt16();
NSCOUNT = rr.ReadUInt16();
ARCOUNT = rr.ReadUInt16();
}
private ushort SetBits(ushort oldValue, int position, int length, bool blnValue)
{
return SetBits(oldValue, position, length, blnValue ? (ushort)1 : (ushort)0);
}
private ushort SetBits(ushort oldValue, int position, int length, ushort newValue)
{
// sanity check
if (length <= 0 || position >= 16)
return oldValue;
// get some mask to put on
int mask = (2 << (length - 1)) - 1;
// clear out value
oldValue &= (ushort)~(mask << position);
// set new value
oldValue |= (ushort)((newValue & mask) << position);
return oldValue;
}
private ushort GetBits(ushort oldValue, int position, int length)
{
// sanity check
if (length <= 0 || position >= 16)
return 0;
// get some mask to put on
int mask = (2 << (length - 1)) - 1;
// shift down to get some value and mask it
return (ushort)((oldValue >> position) & mask);
}
/// <summary>
/// Represents the header as a byte array
/// </summary>
public byte[] Data
{
get
{
List<byte> data = new List<byte>();
data.AddRange(WriteShort(ID));
data.AddRange(WriteShort(Flags));
data.AddRange(WriteShort(QDCOUNT));
data.AddRange(WriteShort(ANCOUNT));
data.AddRange(WriteShort(NSCOUNT));
data.AddRange(WriteShort(ARCOUNT));
return data.ToArray();
}
}
private byte[] WriteShort(ushort sValue)
{
return BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)sValue));
}
/// <summary>
/// query (false), or a response (true)
/// </summary>
public bool QR
{
get
{
return GetBits(Flags, 15, 1) == 1;
}
set
{
Flags = SetBits(Flags, 15, 1, value);
}
}
/// <summary>
/// Specifies kind of query
/// </summary>
public OPCode OPCODE
{
get
{
return (OPCode)GetBits(Flags, 11, 4);
}
set
{
Flags = SetBits(Flags, 11, 4, (ushort)value);
}
}
/// <summary>
/// Authoritative Answer
/// </summary>
public bool AA
{
get
{
return GetBits(Flags, 10, 1) == 1;
}
set
{
Flags = SetBits(Flags, 10, 1, value);
}
}
/// <summary>
/// TrunCation
/// </summary>
public bool TC
{
get
{
return GetBits(Flags, 9, 1) == 1;
}
set
{
Flags = SetBits(Flags, 9, 1, value);
}
}
/// <summary>
/// Recursion Desired
/// </summary>
public bool RD
{
get
{
return GetBits(Flags, 8, 1) == 1;
}
set
{
Flags = SetBits(Flags, 8, 1, value);
}
}
/// <summary>
/// Recursion Available
/// </summary>
public bool RA
{
get
{
return GetBits(Flags, 7, 1) == 1;
}
set
{
Flags = SetBits(Flags, 7, 1, value);
}
}
/// <summary>
/// Reserved for future use
/// </summary>
public ushort Z
{
get
{
return GetBits(Flags, 4, 3);
}
set
{
Flags = SetBits(Flags, 4, 3, value);
}
}
/// <summary>
/// Response code
/// </summary>
public RCode RCODE
{
get
{
return (RCode)GetBits(Flags, 0, 4);
}
set
{
Flags = SetBits(Flags, 0, 4, (ushort)value);
}
}
}
}

View file

@ -1,287 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using DnDns.Enums;
using DnDns.Records;
namespace DnDns.Query
{
/// <summary>
/// DnsQueryBase maintains the common state of DNS Queries (both responses and requests)
/// </summary>
public abstract class DnsQueryBase
{
#region Fields
// RFC 1034
//
// 4.1.1. Header section format
//
// 1 1 1 1 1 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ID |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QDCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ANCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | NSCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ARCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// <summary>
/// ID - A 16 bit identifier. This identifier is copied
/// the corresponding reply and can be used by the requester
/// to match up replies to outstanding queries.
/// </summary>
protected ushort _transactionId;
/// <summary>
/// _flags will store a combination of the enums that make up the 16 bits after the
/// TransactionID in the DNS protocol header
/// </summary>
protected ushort _flags;
/// <summary>
/// A one bit field that specifies whether this message is a
/// query (0), or a response (1).
/// </summary>
protected QueryResponse _queryResponse;
/// <summary>
/// OPCODE - A four bit field that specifies kind of query in this
/// message. This value is set by the originator of a query
/// and copied into the response.
/// </summary>
protected OpCode _opCode;
/// <summary>
/// - A combination of flag fields in the DNS header (|AA|TC|RD|RA|)
/// </summary>
protected NsFlags _nsFlags;
/// <summary>
/// Response code - this 4 bit field is set as part of
/// responses only.
/// </summary>
protected RCode _rCode;
/// <summary>
/// QDCOUNT - an unsigned 16 bit integer specifying the number of
/// entries in the question section.
/// </summary>
protected ushort _questions;
/// <summary>
/// ANCOUNT - an unsigned 16 bit integer specifying the number of
/// resource records in the answer section.
/// </summary>
protected ushort _answerRRs;
/// <summary>
/// NSCOUNT - an unsigned 16 bit integer specifying the number of name
/// server resource records in the authority records
/// section.
/// </summary>
protected ushort _authorityRRs;
// RFC 1034
// 4.1.2. Question section format
// 1 1 1 1 1 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | |
// / QNAME /
// / /
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QTYPE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QCLASS |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// <summary>
/// QNAME - a domain name represented as a sequence of labels, where
/// each label consists of a length octet followed by that
/// number of octets. The domain name terminates with the
/// zero length octet for the null label of the root. Note
/// that this field may be an odd number of octets; no
/// padding is used
/// </summary>
protected string _name;
/// <summary>
/// QTYPE - a two octet code which specifies the type of the query.
/// The values for this field include all codes valid for a
/// TYPE field, together with some more general codes which
/// can match more than one type of RR.
/// </summary>
protected NsType _nsType;
/// <summary>
/// QCLASS - a two octet code that specifies the class of the query.
/// For example, the QCLASS field is IN for the Internet.
/// </summary>
protected NsClass _nsClass;
/// <summary>
/// The additional records for the DNS Query
/// </summary>
protected List<IDnsRecord> _additionalRecords = new List<IDnsRecord>();
#endregion Fields
#region Properties
/// ID - A 16 bit identifier. This identifier is copied
/// the corresponding reply and can be used by the requester
/// to match up replies to outstanding queries.
/// </summary>
public ushort TransactionID
{
get { return _transactionId; }
}
/// <summary>
/// A one bit field that specifies whether this message is a
/// query (0), or a response (1).
/// </summary>
public QueryResponse QueryResponse
{
get { return _queryResponse; }
}
/// <summary>
/// OPCODE - A four bit field that specifies kind of query in this
/// message. This value is set by the originator of a query
/// and copied into the response.
/// </summary>
public OpCode OpCode
{
get { return _opCode; }
}
/// <summary>
/// NsFlags - A combination of flag fields in the DNS header (|AA|TC|RD|RA|)
/// </summary>
public NsFlags NsFlags
{
get { return _nsFlags; }
}
/// <summary>
/// Response code - this 4 bit field is set as part of
/// responses only.
/// </summary>
public RCode RCode
{
get { return _rCode; }
}
/// <summary>
/// QDCOUNT - an unsigned 16 bit integer specifying the number of
/// entries in the question section.
/// </summary>
public ushort Questions
{
get { return _questions; }
}
/// <summary>
/// ANCOUNT - an unsigned 16 bit integer specifying the number of
/// resource records in the answer section.
/// </summary>
public ushort AnswerRRs
{
get { return _answerRRs; }
}
/// <summary>
/// NSCOUNT - an unsigned 16 bit integer specifying the number of name
/// server resource records in the authority records
/// section.
/// </summary>
public ushort AuthorityRRs
{
get { return _authorityRRs; }
}
/// <summary>
/// ARCOUNT - an unsigned 16 bit integer specifying the number of
/// resource records in the additional records section.
/// </summary>
public ushort AdditionalRRs
{
get { return (ushort) _additionalRecords.Count; }
}
/// <summary>
/// QNAME - a domain name represented as a sequence of labels, where
/// each label consists of a length octet followed by that
/// number of octets. The domain name terminates with the
/// zero length octet for the null label of the root. Note
/// that this field may be an odd number of octets; no
/// padding is used
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
/// QTYPE - a two octet code which specifies the type of the query.
/// The values for this field include all codes valid for a
/// TYPE field, together with some more general codes which
/// can match more than one type of RR.
/// </summary>
public NsType NsType
{
get { return _nsType; }
set { _nsType = value; }
}
/// <summary>
/// QCLASS - a two octet code that specifies the class of the query.
/// For example, the QCLASS field is IN for the Internet.
/// </summary>
public NsClass NsClass
{
get { return _nsClass; }
set { _nsClass = value; }
}
public List<IDnsRecord> AdditionalRRecords
{
get { return _additionalRecords; }
}
#endregion
}
}

View file

@ -1,377 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Security.Permissions;
using System.Text;
using DnDns.Enums;
using DnDns.Records;
using DnDns.Security;
namespace DnDns.Query
{
/// <summary>
/// Summary description for DnsQueryRequest.
/// </summary>
public class DnsQueryRequest : DnsQueryBase
{
private static Random r = new Random();
private DnsPermission _dnsPermissions;
private int _bytesSent = 0;
private int _socketTimeout = 5000;
/// <summary>
/// The number of bytes sent to query the DNS Server.
/// </summary>
public int BytesSent
{
get { return _bytesSent; }
}
/// <summary>
/// Gets or sets the amount of time in milliseconds that a DnsQueryRequest will wait to receive data once a read operation is initiated.
/// Defauts to 5 seconds (5000 ms)
/// </summary>
public int Timeout
{
get { return _socketTimeout; }
set { _socketTimeout = value; }
}
#region Constructors
public DnsQueryRequest()
{
_dnsPermissions = new DnsPermission(PermissionState.Unrestricted);
// Construct the class with some defaults
_transactionId = (ushort) r.Next();
_flags = 0;
_queryResponse = QueryResponse.Query;
this._opCode = OpCode.QUERY;
// Recursion Desired
this._nsFlags = NsFlags.RD;
this._questions = 1;
}
#endregion Constructors
private byte[] BuildQuery(string host)
{
string newHost;
int newLocation = 0;
int oldLocation = 0;
MemoryStream ms = new MemoryStream();
host = host.Trim();
// decide how to build this query based on type
switch (_nsType)
{
case NsType.PTR:
IPAddress queryIP = IPAddress.Parse(host);
// pointer should be translated as follows
// 209.115.22.3 -> 3.22.115.209.in-addr.arpa
char[] ipDelim = new char[] {'.'};
string[] s = host.Split(ipDelim,4);
newHost = String.Format("{0}.{1}.{2}.{3}.in-addr.arpa", s[3], s[2], s[1], s[0]);
break;
default:
newHost = host;
break;
}
// Package up the host
while(oldLocation < newHost.Length)
{
newLocation = newHost.IndexOf(".", oldLocation);
if (newLocation == -1) newLocation = newHost.Length;
byte subDomainLength = (byte)(newLocation - oldLocation);
char[] sub = newHost.Substring(oldLocation, subDomainLength).ToCharArray();
ms.WriteByte(subDomainLength);
ms.Write(Encoding.ASCII.GetBytes(sub, 0, sub.Length), 0, sub.Length);
oldLocation = newLocation + 1;
}
// Terminate the domain name w/ a 0x00.
ms.WriteByte(0x00);
return ms.ToArray();
}
/// <summary>
///
/// </summary>
/// <param name="host"></param>
/// <param name="queryType"></param>
/// <param name="queryClass"></param>
/// <param name="protocol"></param>
/// <returns></returns>
public DnsQueryResponse Resolve(string host, NsType queryType, NsClass queryClass, ProtocolType protocol)
{
return Resolve(host, queryType, queryClass, protocol, null);
}
public DnsQueryResponse Resolve(string host, NsType queryType, NsClass queryClass, ProtocolType protocol, TsigMessageSecurityProvider provider)
{
string dnsServer = string.Empty;
// Test for Unix/Linux OS
if (Tools.IsPlatformLinuxUnix())
{
dnsServer = Tools.DiscoverUnixDnsServerAddress();
}
else
{
IPAddressCollection dnsServerCollection = Tools.DiscoverDnsServerAddresses();
if (dnsServerCollection.Count == 0)
throw new Exception("Couldn't detect local DNS Server.");
dnsServer = dnsServerCollection[0].ToString();
}
if (String.IsNullOrEmpty(dnsServer))
throw new Exception("Couldn't detect local DNS Server.");
return Resolve(dnsServer, host, queryType, queryClass, protocol, provider);
}
/// <summary>
///
/// </summary>
/// <param name="dnsServer"></param>
/// <param name="host"></param>
/// <param name="queryType"></param>
/// <param name="queryClass"></param>
/// <param name="protocol"></param>
/// <param name="messageSecurityProvider">The instance of the message security provider to use to secure the DNS request.</param>
/// <returns>A <see cref="T:DnDns.Net.Dns.DnsQueryResponse"></see> instance that contains the Dns Answer for the request query.</returns>
/// <PermissionSet>
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
public DnsQueryResponse Resolve(string dnsServer, string host, NsType queryType, NsClass queryClass, ProtocolType protocol, IMessageSecurityProvider messageSecurityProvider)
{
// Do stack walk and Demand all callers have DnsPermission.
_dnsPermissions.Demand();
byte[] bDnsQuery = this.BuildDnsRequest(host, queryType, queryClass, protocol, messageSecurityProvider);
// Connect to DNS server and get the record for the current server.
IPHostEntry ipe = System.Net.Dns.GetHostEntry(dnsServer);
IPAddress ipa = ipe.AddressList[0];
IPEndPoint ipep = new IPEndPoint(ipa, (int)UdpServices.Domain);
byte[] recvBytes = null;
switch (protocol)
{
case ProtocolType.Tcp:
{
recvBytes = ResolveTcp(bDnsQuery, ipep);
break;
}
case ProtocolType.Udp:
{
recvBytes = ResolveUdp(bDnsQuery, ipep);
break;
}
default:
{
throw new InvalidOperationException("Invalid Protocol: " + protocol);
}
}
Trace.Assert(recvBytes != null, "Failed to retrieve data from the remote DNS server.");
DnsQueryResponse dnsQR = new DnsQueryResponse();
dnsQR.ParseResponse(recvBytes, protocol);
return dnsQR;
}
private byte[] ResolveUdp(byte[] bDnsQuery, IPEndPoint ipep)
{
// UDP messages, data size = 512 octets or less
UdpClient udpClient = new UdpClient();
byte[] recvBytes = null;
try
{
udpClient.Client.ReceiveTimeout = _socketTimeout;
udpClient.Connect(ipep);
udpClient.Send(bDnsQuery, bDnsQuery.Length);
recvBytes = udpClient.Receive(ref ipep);
}
finally
{
udpClient.Close();
}
return recvBytes;
}
private static byte[] ResolveTcp(byte[] bDnsQuery, IPEndPoint ipep)
{
TcpClient tcpClient = new TcpClient();
byte[] recvBytes = null;
try
{
tcpClient.Connect(ipep);
NetworkStream netStream = tcpClient.GetStream();
BinaryReader netReader = new System.IO.BinaryReader(netStream);
netStream.Write(bDnsQuery, 0, bDnsQuery.Length);
// wait until data is avail
while (!netStream.DataAvailable) ;
if (tcpClient.Connected && netStream.DataAvailable)
{
// Read first two bytes to find out the length of the response
byte[] bLen = new byte[2];
// NOTE: The order of the next two lines matter. Do not reorder
// Array indexes are also intentionally reversed
bLen[1] = (byte)netStream.ReadByte();
bLen[0] = (byte)netStream.ReadByte();
UInt16 length = BitConverter.ToUInt16(bLen, 0);
recvBytes = new byte[length];
netStream.Read(recvBytes, 0, length);
}
}
finally
{
tcpClient.Close();
}
return recvBytes;
}
private byte[] BuildDnsRequest(string host, NsType queryType, NsClass queryClass, ProtocolType protocol, IMessageSecurityProvider messageSecurityProvider)
{
// Combind the NsFlags with our constant flags
ushort flags = (ushort)((ushort)_queryResponse | (ushort)_opCode | (ushort)_nsFlags);
this._flags = flags;
//NOTE: This limits the librarys ablity to issue multiple queries per request.
this._nsType = queryType;
this._nsClass = queryClass;
this._name = host;
if(messageSecurityProvider != null)
{
messageSecurityProvider.SecureMessage(this);
}
byte[] bDnsQuery = GetMessageBytes();
// Add two byte prefix that contains the packet length per RFC 1035 section 4.2.2
if (protocol == ProtocolType.Tcp)
{
// 4.2.2. TCP usageMessages sent over TCP connections use server port 53 (decimal).
// The message is prefixed with a two byte length field which gives the message
// length, excluding the two byte length field. This length field allows the
// low-level processing to assemble a complete message before beginning to parse
// it.
int len = bDnsQuery.Length;
Array.Resize<byte>(ref bDnsQuery, len + 2);
Array.Copy(bDnsQuery, 0, bDnsQuery, 2, len);
bDnsQuery[0] = (byte)((len >> 8) & 0xFF);
bDnsQuery[1] = (byte)((len & 0xFF));
}
return bDnsQuery;
}
internal byte[] GetMessageBytes()
{
MemoryStream memoryStream = new MemoryStream();
byte[] data = new byte[2];
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_transactionId) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_flags) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_questions) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_answerRRs) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_authorityRRs) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_additionalRecords.Count) >> 16));
memoryStream.Write(data, 0, data.Length);
data = DnsHelpers.CanonicaliseDnsName(_name, false);
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_nsType) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_nsClass) >> 16));
memoryStream.Write(data, 0, data.Length);
foreach (IDnsRecord dnsRecord in AdditionalRRecords)
{
data = dnsRecord.GetMessageBytes();
memoryStream.Write(data, 0, data.Length);
}
Trace.WriteLine(String.Format("The message bytes: {0}", DnsHelpers.DumpArrayToString(memoryStream.ToArray())));
return memoryStream.ToArray();
}
}
}

View file

@ -1,168 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using DnDns.Records;
using DnDns.Enums;
namespace DnDns.Query
{
/// <summary>
/// Summary description for DnsQueryResponse.
/// </summary>
public class DnsQueryResponse : DnsQueryBase
{
#region Fields
private DnsQueryRequest _queryRequest = new DnsQueryRequest();
private IDnsRecord[] _answers;
private IDnsRecord[] _authoritiveNameServers;
private int _bytesReceived = 0;
#endregion Fields
#region properties
public DnsQueryRequest QueryRequest
{
get { return _queryRequest; }
}
public IDnsRecord[] Answers
{
get { return _answers; }
}
public IDnsRecord[] AuthoritiveNameServers
{
get { return _authoritiveNameServers; }
}
public int BytesReceived
{
get { return _bytesReceived; }
}
#endregion
/// <summary>
///
/// </summary>
public DnsQueryResponse()
{
}
private DnsQueryRequest ParseQuery(ref MemoryStream ms)
{
DnsQueryRequest queryRequest = new DnsQueryRequest();
// Read name
queryRequest.Name = DnsRecordBase.ParseName(ref ms);
return queryRequest;
}
internal void ParseResponse(byte[] recvBytes, ProtocolType protocol)
{
MemoryStream memoryStream = new MemoryStream(recvBytes);
byte[] flagBytes = new byte[2];
byte[] transactionId = new byte[2];
byte[] questions = new byte[2];
byte[] answerRRs = new byte[2];
byte[] authorityRRs = new byte[2];
byte[] additionalRRCountBytes = new byte[2];
byte[] nsType = new byte[2];
byte[] nsClass = new byte[2];
this._bytesReceived = recvBytes.Length;
// Parse DNS Response
memoryStream.Read(transactionId, 0, 2);
memoryStream.Read(flagBytes, 0, 2);
memoryStream.Read(questions, 0, 2);
memoryStream.Read(answerRRs, 0, 2);
memoryStream.Read(authorityRRs, 0, 2);
memoryStream.Read(additionalRRCountBytes, 0, 2);
// Parse Header
_transactionId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(transactionId, 0));
_flags = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(flagBytes, 0));
_queryResponse = (QueryResponse)(_flags & (ushort)FlagMasks.QueryResponseMask);
_opCode = (OpCode)(_flags & (ushort)FlagMasks.OpCodeMask);
_nsFlags = (NsFlags)(_flags & (ushort)FlagMasks.NsFlagMask);
_rCode = (RCode)(_flags & (ushort)FlagMasks.RCodeMask);
// Parse Questions Section
_questions = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(questions, 0));
_answerRRs = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(answerRRs, 0));
_authorityRRs = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(authorityRRs, 0));
ushort additionalRRCount = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(additionalRRCountBytes, 0));
_additionalRecords = new List<IDnsRecord>();
_answers = new DnsRecordBase[_answerRRs];
_authoritiveNameServers = new DnsRecordBase[_authorityRRs];
// Parse Queries
_queryRequest = this.ParseQuery(ref memoryStream);
// Read dnsType
memoryStream.Read(nsType, 0, 2);
// Read dnsClass
memoryStream.Read(nsClass, 0, 2);
_nsType = (NsType)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsType, 0));
_nsClass = (NsClass)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsClass, 0));
// Read in Answer Blocks
for (int i=0; i < _answerRRs; i++)
{
_answers[i] = RecordFactory.Create(ref memoryStream);
}
// Parse Authority Records
for (int i=0; i < _authorityRRs; i++)
{
_authoritiveNameServers[i] = RecordFactory.Create(ref memoryStream);
}
// Parse Additional Records
for (int i=0; i < additionalRRCount; i++)
{
_additionalRecords.Add(RecordFactory.Create(ref memoryStream));
}
}
}
}

View file

@ -0,0 +1,129 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace Heijden.DNS
{
#region Rfc 1034/1035
/*
4.1.2. Question section format
The question section is used to carry the "question" in most queries,
i.e., the parameters that define what is being asked. The section
contains QDCOUNT (usually 1) entries, each of the following format:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ QNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QTYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QCLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
QNAME a domain name represented as a sequence of labels, where
each label consists of a length octet followed by that
number of octets. The domain name terminates with the
zero length octet for the null label of the root. Note
that this field may be an odd number of octets; no
padding is used.
QTYPE a two octet code which specifies the type of the query.
The values for this field include all codes valid for a
TYPE field, together with some more general codes which
can match more than one type of RR.
QCLASS a two octet code that specifies the class of the query.
For example, the QCLASS field is IN for the Internet.
*/
#endregion
public class Question
{
private string m_QName;
public string QName
{
get
{
return m_QName;
}
set
{
m_QName = value;
if (!m_QName.EndsWith("."))
m_QName += ".";
}
}
public QType QType;
public QClass QClass;
public Question(string QName,QType QType,QClass QClass)
{
this.QName = QName;
this.QType = QType;
this.QClass = QClass;
}
public Question(RecordReader rr)
{
QName = rr.ReadDomainName();
QType = (QType)rr.ReadUInt16();
QClass = (QClass)rr.ReadUInt16();
}
private byte[] WriteName(string src)
{
if (!src.EndsWith("."))
src += ".";
if (src == ".")
return new byte[1];
StringBuilder sb = new StringBuilder();
int intI, intJ, intLen = src.Length;
sb.Append('\0');
for (intI = 0, intJ = 0; intI < intLen; intI++, intJ++)
{
sb.Append(src[intI]);
if (src[intI] == '.')
{
sb[intI - intJ] = (char)(intJ & 0xff);
intJ = -1;
}
}
sb[sb.Length - 1] = '\0';
return System.Text.Encoding.ASCII.GetBytes(sb.ToString());
}
public byte[] Data
{
get
{
List<byte> data = new List<byte>();
data.AddRange(WriteName(QName));
data.AddRange(WriteShort((ushort)QType));
data.AddRange(WriteShort((ushort)QClass));
return data.ToArray();
}
}
private byte[] WriteShort(ushort sValue)
{
return BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)sValue));
}
public override string ToString()
{
return string.Format("{0,-32}\t{1}\t{2}", QName, QClass, QType);
}
}
}

View file

@ -0,0 +1,156 @@
using System;
namespace Heijden.DNS
{
#region RFC info
/*
3.2. RR definitions
3.2.1. Format
All RRs have the same top level format shown below:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ /
/ NAME /
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| CLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TTL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RDLENGTH |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/ RDATA /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
NAME an owner name, i.e., the name of the node to which this
resource record pertains.
TYPE two octets containing one of the RR TYPE codes.
CLASS two octets containing one of the RR CLASS codes.
TTL a 32 bit signed integer that specifies the time interval
that the resource record may be cached before the source
of the information should again be consulted. Zero
values are interpreted to mean that the RR can only be
used for the transaction in progress, and should not be
cached. For example, SOA records are always distributed
with a zero TTL to prohibit caching. Zero values can
also be used for extremely volatile data.
RDLENGTH an unsigned 16 bit integer that specifies the length in
octets of the RDATA field.
RDATA 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.
*/
#endregion
/// <summary>
/// Resource Record (rfc1034 3.6.)
/// </summary>
public class RR
{
/// <summary>
/// The name of the node to which this resource record pertains
/// </summary>
public string NAME;
/// <summary>
/// Specifies type of resource record
/// </summary>
public Type Type;
/// <summary>
/// Specifies type class of resource record, mostly IN but can be CS, CH or HS
/// </summary>
public Class Class;
/// <summary>
/// Time to live, the time interval that the resource record may be cached
/// </summary>
public uint TTL
{
get
{
return (uint)Math.Max(0, m_TTL - TimeLived);
}
set
{
m_TTL = value;
}
}
private uint m_TTL;
/// <summary>
///
/// </summary>
public ushort RDLENGTH;
/// <summary>
/// One of the Record* classes
/// </summary>
public Record RECORD;
public int TimeLived;
public RR(RecordReader rr)
{
TimeLived = 0;
NAME = rr.ReadDomainName();
Type = (Type)rr.ReadUInt16();
Class = (Class)rr.ReadUInt16();
TTL = rr.ReadUInt32();
RDLENGTH = rr.ReadUInt16();
RECORD = rr.ReadRecord(Type);
RECORD.RR = this;
}
public override string ToString()
{
return string.Format("{0,-32} {1}\t{2}\t{3}\t{4}",
NAME,
TTL,
Class,
Type,
RECORD);
}
}
public class AnswerRR : RR
{
public AnswerRR(RecordReader br)
: base(br)
{
}
}
public class AuthorityRR : RR
{
public AuthorityRR(RecordReader br)
: base(br)
{
}
}
public class AdditionalRR : RR
{
public AdditionalRR(RecordReader br)
: base(br)
{
}
}
}

View file

@ -0,0 +1,243 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Heijden.DNS
{
public class RecordReader
{
private byte[] m_Data;
private int m_Position;
public RecordReader(byte[] data)
{
m_Data = data;
m_Position = 0;
}
public int Position
{
get
{
return m_Position;
}
set
{
m_Position = value;
}
}
public RecordReader(byte[] data, int Position)
{
m_Data = data;
m_Position = Position;
}
public byte ReadByte()
{
if (m_Position >= m_Data.Length)
return 0;
else
return m_Data[m_Position++];
}
public char ReadChar()
{
return (char)ReadByte();
}
public UInt16 ReadUInt16()
{
return (UInt16)(ReadByte() << 8 | ReadByte());
}
public UInt16 ReadUInt16(int offset)
{
m_Position += offset;
return ReadUInt16();
}
public UInt32 ReadUInt32()
{
return (UInt32)(ReadUInt16() << 16 | ReadUInt16());
}
public string ReadDomainName()
{
StringBuilder name = new StringBuilder();
int length = 0;
// get the length of the first label
while ((length = ReadByte()) != 0)
{
// top 2 bits set denotes domain name compression and to reference elsewhere
if ((length & 0xc0) == 0xc0)
{
// work out the existing domain name, copy this pointer
RecordReader newRecordReader = new RecordReader(m_Data, (length & 0x3f) << 8 | ReadByte());
name.Append(newRecordReader.ReadDomainName());
return name.ToString();
}
// if not using compression, copy a char at a time to the domain name
while (length > 0)
{
name.Append(ReadChar());
length--;
}
name.Append('.');
}
if (name.Length == 0)
return ".";
else
return name.ToString();
}
public string ReadString()
{
short length = this.ReadByte();
StringBuilder name = new StringBuilder();
for(int intI=0;intI<length;intI++)
name.Append(ReadChar());
return name.ToString();
}
public byte[] ReadBytes(int intLength)
{
List<byte> list = new List<byte>();
for(int intI=0;intI<intLength;intI++)
list.Add(ReadByte());
return list.ToArray();
}
public Record ReadRecord(Type type)
{
switch (type)
{
case Type.A:
return new RecordA(this);
case Type.NS:
return new RecordNS(this);
case Type.MD:
return new RecordMD(this);
case Type.MF:
return new RecordMF(this);
case Type.CNAME:
return new RecordCNAME(this);
case Type.SOA:
return new RecordSOA(this);
case Type.MB:
return new RecordMB(this);
case Type.MG:
return new RecordMG(this);
case Type.MR:
return new RecordMR(this);
case Type.NULL:
return new RecordNULL(this);
case Type.WKS:
return new RecordWKS(this);
case Type.PTR:
return new RecordPTR(this);
case Type.HINFO:
return new RecordHINFO(this);
case Type.MINFO:
return new RecordMINFO(this);
case Type.MX:
return new RecordMX(this);
case Type.TXT:
return new RecordTXT(this);
case Type.RP:
return new RecordRP(this);
case Type.AFSDB:
return new RecordAFSDB(this);
case Type.X25:
return new RecordX25(this);
case Type.ISDN:
return new RecordISDN(this);
case Type.RT:
return new RecordRT(this);
case Type.NSAP:
return new RecordNSAP(this);
case Type.NSAPPTR:
return new RecordNSAPPTR(this);
case Type.SIG:
return new RecordSIG(this);
case Type.KEY:
return new RecordKEY(this);
case Type.PX:
return new RecordPX(this);
case Type.GPOS:
return new RecordGPOS(this);
case Type.AAAA:
return new RecordAAAA(this);
case Type.LOC:
return new RecordLOC(this);
case Type.NXT:
return new RecordNXT(this);
case Type.EID:
return new RecordEID(this);
case Type.NIMLOC:
return new RecordNIMLOC(this);
case Type.SRV:
return new RecordSRV(this);
case Type.ATMA:
return new RecordATMA(this);
case Type.NAPTR:
return new RecordNAPTR(this);
case Type.KX:
return new RecordKX(this);
case Type.CERT:
return new RecordCERT(this);
case Type.A6:
return new RecordA6(this);
case Type.DNAME:
return new RecordDNAME(this);
case Type.SINK:
return new RecordSINK(this);
case Type.OPT:
return new RecordOPT(this);
case Type.APL:
return new RecordAPL(this);
case Type.DS:
return new RecordDS(this);
case Type.SSHFP:
return new RecordSSHFP(this);
case Type.IPSECKEY:
return new RecordIPSECKEY(this);
case Type.RRSIG:
return new RecordRRSIG(this);
case Type.NSEC:
return new RecordNSEC(this);
case Type.DNSKEY:
return new RecordDNSKEY(this);
case Type.DHCID:
return new RecordDHCID(this);
case Type.NSEC3:
return new RecordNSEC3(this);
case Type.NSEC3PARAM:
return new RecordNSEC3PARAM(this);
case Type.HIP:
return new RecordHIP(this);
case Type.SPF:
return new RecordSPF(this);
case Type.UINFO:
return new RecordUINFO(this);
case Type.UID:
return new RecordUID(this);
case Type.GID:
return new RecordGID(this);
case Type.UNSPEC:
return new RecordUNSPEC(this);
case Type.TKEY:
return new RecordTKEY(this);
case Type.TSIG:
return new RecordTSIG(this);
default:
return new RecordUnknown(this);
}
}
}
}

View file

@ -1,83 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
/// <summary>
/// RFC 1035:
///
/// 3.4.1. A RDATA format
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | ADDRESS |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
///
/// where:
///
/// ADDRESS A 32 bit Internet address.
///
/// Hosts that have multiple Internet addresses will have multiple A
/// records.
///
/// A records cause no additional section processing. The RDATA section of
/// an A line in a master file is an Internet address expressed as four
/// decimal numbers separated by dots without any imbedded spaces (e.g.,
/// "10.2.0.52" or "192.0.5.6").
///
/// </summary>
public sealed class ARecord : DnsRecordBase, IDnsRecord
{
private string _hostAddress;
/// <summary>
/// The answer host address for the DNS A Record.
/// </summary>
public string HostAddress
{
get { return _hostAddress; }
}
internal ARecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
_hostAddress = ms.ReadByte() + "." + ms.ReadByte() + "." + ms.ReadByte() + "." + ms.ReadByte();
_answer = "Address: " + _hostAddress;
}
}
}

View file

@ -1,97 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class AaaaRecord : DnsRecordBase
{
private string m_ipAddress;
internal AaaaRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
// TODO: Test and incorporate BinToHex function below
m_ipAddress =
ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" + ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" +
ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" + ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" +
ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" + ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" +
ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2") + ":" + ms.ReadByte().ToString("x2") + ms.ReadByte().ToString("x2");
_answer = "IPv6 Address: " + m_ipAddress;
}
// TODO: converted from VB.NET, test to make sure it works properly
private static string BinToHex(byte[] data)
{
if (data != null)
{
StringBuilder sb = new System.Text.StringBuilder(1024);
for (int i = 0; i < data.Length; i++)
{
sb.Append(data[i].ToString("X2"));
}
return sb.ToString();
}
else
{
return null;
}
}
// TODO: converted from VB.NET, test to make sure it works properly
private static byte[] HexToBin(string s)
{
int arraySize = s.Length / 2;
byte[] bytes = new byte[arraySize - 1];
int counter = 0;
for (int i = 0; i < s.Length - 1; i = 2)
{
string hexValue = s.Substring(i, 2);
// Tell convert to interpret the string as a 16 bit hex value
int intValue = Convert.ToInt32(hexValue, 16);
// Convert the integer to a byte and store it in the array
bytes[counter] = Convert.ToByte(intValue);
counter += 1;
}
return bytes;
}
}
}

View file

@ -1,78 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace DnDns.Records
{
public sealed class AfsdbRecord : DnsRecordBase
{
private ushort _port;
private string _name;
private short _type;
public ushort Port
{
get { return _port; }
}
public string AfsdbName
{
get { return _name; }
}
public short Type
{
get { return _type; }
}
internal AfsdbRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
byte[] type = new byte[2];
ms.Read(type, 0, 2);
// _port = (ushort)Tools.ByteToUInt(type);
_port = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(type, 0));
_name = DnsRecordBase.ParseName(ref ms);
//_type = (short)Tools.ByteToUInt(type);
_type = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(type, 0));
_answer = "Name: " + _name + ", Port: " + _port + ", Type: " + _type;
}
}
}

View file

@ -1,74 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class AtmaRecord : DnsRecordBase
{
private string _address;
private ATMFormat _format;
public string Address
{
get { return _address; }
}
public ATMFormat Format
{
get { return _format; }
}
internal AtmaRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
byte[] address = new byte[this.DnsHeader.DataLength - 1];
_format = (ATMFormat)ms.ReadByte();
ms.Read(address, 0, this.DnsHeader.DataLength - 1);
_address = Encoding.ASCII.GetString(address);
_answer = "Address: " + _address + ", Format: " + _format;
}
public enum ATMFormat : byte
{
E164 = 0x01,
NSAP = 0x02
}
}
}

View file

@ -1,338 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Diagnostics;
namespace DnDns.Records
{
/// <summary>
/// Handles a basic Dns record
///
/// From RFC 1035:
///
/// 3.2.1. Format
///
/// All RRs have the same top level format shown below:
///
/// 1 1 1 1 1 1
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | |
/// / /
/// / NAME /
/// | |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | TYPE |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | CLASS |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | TTL |
/// | |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | RDLENGTH |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/// / RDATA /
/// / /
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
///
/// where:
///
/// NAME an owner name, i.e., the name of the node to which this
/// resource record pertains.
///
/// TYPE two octets containing one of the RR TYPE codes.
///
/// CLASS two octets containing one of the RR CLASS codes.
///
/// TTL a 32 bit signed integer that specifies the time interval
/// that the resource record may be cached before the source
/// of the information should again be consulted. Zero
/// values are interpreted to mean that the RR can only be
/// used for the transaction in progress, and should not be
/// cached. For example, SOA records are always distributed
/// with a zero TTL to prohibit caching. Zero values can
/// also be used for extremely volatile data.
///
/// RDLENGTH an unsigned 16 bit integer that specifies the length in
/// octets of the RDATA field.
///
/// RDATA 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.
/// </summary>
public abstract class DnsRecordBase : IDnsRecord
{
#region Fields
// NAME an owner name, i.e., the name of the node to which this
// resource record pertains.
//private string _name;
// TYPE two octets containing one of the RR TYPE codes.
//protected NsType _nsType;
// CLASS - two octets containing one of the RR CLASS codes.
//private NsClass _nsClass;
// TTL - a 32 bit signed integer that specifies the time interval
// that the resource record may be cached before the source
// of the information should again be consulted. Zero
// values are interpreted to mean that the RR can only be
// used for the transaction in progress, and should not be
// cached. For example, SOA records are always distributed
// with a zero TTL to prohibit caching. Zero values can
/// also be used for extremely volatile data.
//private int _timeToLive;
// RDLENGTH - an unsigned 16 bit integer that specifies the length in
// octets of the RDATA field.
//protected short _dataLength;
protected RecordHeader _dnsHeader;
protected string _answer;
protected string _errorMsg;
#endregion
#region Properties
/// <summary>
/// NAME - an owner name, i.e., the name of the node to which this
/// resource record pertains.
/// </summary>
//public string Name
//{
// get { return _name; }
//}
public RecordHeader DnsHeader
{
get { return _dnsHeader; }
protected set { _dnsHeader = value; }
}
public string Answer
{
get { return _answer; }
}
/// <summary>
/// TYPE two octets containing one of the RR TYPE codes.
/// </summary>
//public NsType NsType
//{
// get { return _nsType; }
//}
/// <summary>
/// CLASS - two octets containing one of the RR CLASS codes.
/// </summary>
//public NsClass NsClass
//{
// get { return _nsClass; }
//}
/// <summary>
/// TTL - a 32 bit signed integer that specifies the time interval
/// that the resource record may be cached before the source
/// of the information should again be consulted. Zero
/// values are interpreted to mean that the RR can only be
/// used for the transaction in progress, and should not be
/// cached. 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 int TimeToLive
//{
// get { return _timeToLive; }
//}
/// <summary>
/// RDLENGTH - an unsigned 16 bit integer that specifies the length in
/// octets of the RDATA field.
/// </summary>
//public short DataLength
//{
// get { return _dataLength; }
//}
public string ErrorMsg
{
get { return _errorMsg; }
}
#endregion
internal DnsRecordBase()
{
}
public virtual void ParseRecord(ref MemoryStream ms)
{
// Default implementation - the most common.
_answer = DnsRecordBase.ParseName(ref ms);
}
internal DnsRecordBase(RecordHeader dnsHeader)
{
_dnsHeader = dnsHeader;
}
// RFC
// 4.1.4. Message compression
//
// In order to reduce the size of messages, the domain system utilizes a
// compression scheme which eliminates the repetition of domain names in a
// message. In this scheme, an entire domain name or a list of labels at
// the end of a domain name is replaced with a pointer to a prior occurance
// of the same name.
//
// The pointer takes the form of a two octet sequence:
//
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | 1 1| OFFSET |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
//
// The first two bits are ones. This allows a pointer to be distinguished
// from a label, since the label must begin with two zero bits because
// labels are restricted to 63 octets or less. (The 10 and 01 combinations
// are reserved for future use.) The OFFSET field specifies an offset from
// the start of the message (i.e., the first octet of the ID field in the
// domain header). A zero offset specifies the first byte of the ID field,
// etc.
//
// The compression scheme allows a domain name in a message to be
// represented as either:
//
// - a sequence of labels ending in a zero octet
// - a pointer
// - a sequence of labels ending with a pointer
//
internal static string ParseName(ref MemoryStream ms)
{
Trace.WriteLine("Reading Name...");
StringBuilder sb = new StringBuilder();
uint next = (uint)ms.ReadByte();
Trace.WriteLine("Next is 0x" + next.ToString("x2"));
int bPointer;
while ((next != 0x00))
{
// Isolate 2 most significat bits -> e.g. 11xx xxxx
// if it's 0xc0 (11000000b} then pointer
switch (0xc0 & next)
{
// 0xc0 -> Name is a pointer.
case 0xc0:
{
// Isolate Offset
int offsetMASK = ~0xc0;
// Example on how to calculate the offset
// e.g.
//
// So if given the following 2 bytes - 0xc1 0x1c (11000001 00011100)
//
// The pointer takes the form of a two octet sequence:
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | 1 1| OFFSET |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | 1 1| 0 0 0 0 0 1 0 0 0 1 1 1 0 0|
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
//
// A pointer is indicated by the a 1 in the two most significant bits
// The Offset is the remaining bits.
//
// The Pointer = 0xc0 (11000000 00000000)
// The offset = 0x11c (00000001 00011100)
// Move offset into the proper position
int offset = (int)(offsetMASK & next) << 8;
// extract the pointer to the data in the stream
bPointer = ms.ReadByte() + offset;
// store the position so we can resume later
long oldPtr = ms.Position;
// Move to the specified position in the stream and
// parse the name (recursive call)
ms.Position = bPointer;
sb.Append(DnsRecordBase.ParseName(ref ms));
Trace.WriteLine(sb.ToString());
// Move back to original position, and continue
ms.Position = oldPtr;
next = 0x00;
break;
}
case 0x00:
{
Debug.Assert(next < 0xc0, "Offset cannot be greater then 0xc0.");
byte[] buffer = new byte[next];
ms.Read(buffer, 0, (int)next);
sb.Append(Encoding.ASCII.GetString(buffer) + ".");
next = (uint)ms.ReadByte();
Trace.WriteLine("0x" + next.ToString("x2"));
break;
}
default:
throw new InvalidOperationException("There was a problem decompressing the DNS Message.");
}
}
return sb.ToString();
}
internal string ParseText(ref MemoryStream ms)
{
StringBuilder sb = new StringBuilder();
int len = ms.ReadByte();
byte[] buffer = new byte[len];
ms.Read(buffer, 0, len);
sb.Append(Encoding.ASCII.GetString(buffer));
return sb.ToString();
}
public override string ToString()
{
return _answer;
}
#region IDnsRecord Members
public virtual byte[] GetMessageBytes()
{
return new byte[]{};
}
#endregion
}
}

View file

@ -1,52 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class CNameRecord : DnsRecordBase
{
internal CNameRecord(RecordHeader dnsHeader) : base(dnsHeader) {}
public override void ParseRecord(ref MemoryStream ms)
{
base.ParseRecord(ref ms);
_answer = "Host: " + _answer;
}
}
}

View file

@ -1,67 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class HInfoRecord : DnsRecordBase
{
private string _cpuType;
private string _operatingSys;
public string CpuType
{
get { return _cpuType; }
}
public string OperatingSys
{
get { return _operatingSys; }
}
internal HInfoRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
_cpuType = base.ParseText(ref ms);
_operatingSys = base.ParseText(ref ms);
_answer = "CPU: " + _cpuType + ", OS: " + _operatingSys;
}
}
}

View file

@ -1,58 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public interface IDnsRecord
{
RecordHeader DnsHeader { get; }
string Answer { get; }
//short DataLength { get; }
string ErrorMsg { get; }
//string Name { get; }
//NsClass NsClass { get; }
//NsType NsType { get; }
//int TimeToLive { get; }
//void ParseRecordHeader(ref MemoryStream ms);
void ParseRecord(ref MemoryStream ms);
string ToString();
byte[] GetMessageBytes();
}
}

View file

@ -1,66 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class IsdnRecord : DnsRecordBase
{
private string _address;
private string _subAddress;
public string Address
{
get { return _address; }
}
public string SubAddress
{
get { return _subAddress; }
}
internal IsdnRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
_address = base.ParseText(ref ms);
_subAddress = base.ParseText(ref ms);
_answer = "ISDN Address: " + _address + ", SubAddress: " + _subAddress;
}
}
}

View file

@ -1,194 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace DnDns.Records
{
public sealed class LocRecord : DnsRecordBase
{
// For LOC
#region Fields
private byte _version;
private byte _size;
private byte _horPrecision;
private byte _vertPrecision;
private uint _latitude;
private uint _longitude;
private uint _altitude;
#endregion
#region Properties
public byte Version
{
get { return _version; }
}
public byte Size
{
get { return _size; }
}
public byte HorPrecision
{
get { return _horPrecision; }
}
public byte VertPrecision
{
get { return _vertPrecision; }
}
public uint Latitude
{
get { return _latitude; }
}
public uint Longitude
{
get { return _longitude; }
}
public uint Altitude
{
get { return _altitude; }
}
#endregion
private char[] _latDirection = new char[2] {'N', 'S'};
private char[] _longDirection = new char[2] {'E', 'W'};
internal LocRecord(RecordHeader dnsHeader) : base(dnsHeader) {}
public override void ParseRecord(ref MemoryStream ms)
{
byte[] latitude = new Byte[4];
byte[] longitude = new Byte[4];
byte[] altitude = new Byte[4];
_version = (byte)ms.ReadByte();
_size = (byte)ms.ReadByte();
_horPrecision = (byte)ms.ReadByte();
_vertPrecision = (byte)ms.ReadByte();
ms.Read(latitude,0,latitude.Length);
// _latitude = Tools.ByteToUInt(latitude);
_latitude = (uint)IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(latitude, 0));
ms.Read(longitude,0,longitude.Length);
// _longitude = Tools.ByteToUInt(longitude);
_longitude = (uint)IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(longitude, 0));
ms.Read(altitude,0,altitude.Length);
// _altitude = Tools.ByteToUInt(altitude);
_altitude = (uint)IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(altitude, 0));
StringBuilder sb = new StringBuilder();
sb.Append("Version: ");
sb.Append(_version);
sb.Append("\r\n");
sb.Append("Size: ");
sb.Append(CalcSize(_size));
sb.Append(" m\r\n");
sb.Append("Horizontal Precision: ");
sb.Append(CalcSize(_horPrecision));
sb.Append(" m\r\n");
sb.Append("Vertical Precision: ");
sb.Append(CalcSize(_vertPrecision));
sb.Append(" m\r\n");
sb.Append("Latitude: ");
sb.Append(CalcLoc(_latitude, _latDirection));
sb.Append("\r\n");
sb.Append("Longitude: ");
sb.Append(CalcLoc(_longitude, _longDirection));
sb.Append("\r\n");
sb.Append("Altitude: ");
sb.Append((_altitude - 10000000) / 100.0);
sb.Append(" m\r\n");
_answer = sb.ToString();
}
private string CalcLoc(uint angle, char[] nsew)
{
char direction;
if (angle < 0x80000000)
{
angle = 0x80000000 - angle;
direction = nsew[1];
}
else
{
angle = angle - 0x80000000;
direction = nsew[0];
}
uint tsecs = angle % 1000;
angle = angle / 1000;
uint secs = angle % 60;
angle = angle / 60;
uint minutes = angle % 60;
uint degrees = angle / 60;
return degrees + " deg, " + minutes + " min " + secs+ "." + tsecs + " sec " + direction;
}
// return size in meters
private double CalcSize(byte val)
{
double size;
int exponent;
size = (val & 0xF0) >> 4;
exponent = (val & 0x0F);
while (exponent != 0)
{
size *= 10;
exponent--;
}
return size / 100;
}
}
}

View file

@ -1,66 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class MInfoRecord : DnsRecordBase
{
private string _responsibleMb;
private string _errorMb;
public string ResponsibleMb
{
get { return _responsibleMb; }
}
public string ErrorMb
{
get { return _errorMb; }
}
internal MInfoRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
_responsibleMb = DnsRecordBase.ParseName(ref ms);
_errorMb = DnsRecordBase.ParseName(ref ms);
_answer = "Responsible MailBox: " + _responsibleMb + ", Error MailBox: " + _errorMb;
}
}
}

View file

@ -1,52 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class MbRecord : DnsRecordBase
{
internal MbRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
//public override void ParseRecord(ref MemoryStream ms)
//{
// _answer = BaseDnsRecord.ParseName(ref ms);
//}
}
}

View file

@ -1,51 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class MgRecord : DnsRecordBase
{
internal MgRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
//public override void ParseRecord(ref MemoryStream ms)
//{
// _answer = BaseDnsRecord.ParseName(ref ms);
//}
}
}

View file

@ -1,51 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class MrRecord : DnsRecordBase
{
internal MrRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
//public override void ParseRecord(ref MemoryStream ms)
//{
// _answer = BaseDnsRecord.ParseName(ref ms);
//}
}
}

View file

@ -1,75 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace DnDns.Records
{
public sealed class MxRecord : DnsRecordBase
{
// For MX
private short _preference;
private string _mailExchange;
public short Preference
{
get { return _preference; }
}
public string MailExchange
{
get { return _mailExchange; }
}
internal MxRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
// Preference is a function of MX records
byte[] nsPreference = new byte[2];
ms.Read(nsPreference, 0, 2);
//_preference = (short)Tools.ByteToUInt(nsPreference);
// TODO: Should this be a UShort instead of a short?
_preference = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsPreference, 0));
// Parse Name
_mailExchange = DnsRecordBase.ParseName(ref ms);
_answer = "MX Preference: " + _preference + ", Mail Exchanger: " + _mailExchange;
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordA6 : Record
{
public byte[] RDATA;
public RecordA6(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordAPL : Record
{
public byte[] RDATA;
public RecordAPL(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordATMA : Record
{
public byte[] RDATA;
public RecordATMA(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordCERT : Record
{
public byte[] RDATA;
public RecordCERT(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordDHCID : Record
{
public byte[] RDATA;
public RecordDHCID(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordDNSKEY : Record
{
public byte[] RDATA;
public RecordDNSKEY(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordEID : Record
{
public byte[] RDATA;
public RecordEID(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordGID : Record
{
public byte[] RDATA;
public RecordGID(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordHIP : Record
{
public byte[] RDATA;
public RecordHIP(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordIPSECKEY : Record
{
public byte[] RDATA;
public RecordIPSECKEY(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordNIMLOC : Record
{
public byte[] RDATA;
public RecordNIMLOC(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordNSEC : Record
{
public byte[] RDATA;
public RecordNSEC(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordNSEC3 : Record
{
public byte[] RDATA;
public RecordNSEC3(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordNSEC3PARAM : Record
{
public byte[] RDATA;
public RecordNSEC3PARAM(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordOPT : Record
{
public byte[] RDATA;
public RecordOPT(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordRRSIG : Record
{
public byte[] RDATA;
public RecordRRSIG(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordSINK : Record
{
public byte[] RDATA;
public RecordSINK(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordSPF : Record
{
public byte[] RDATA;
public RecordSPF(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordSSHFP : Record
{
public byte[] RDATA;
public RecordSSHFP(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordUID : Record
{
public byte[] RDATA;
public RecordUID(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordUINFO : Record
{
public byte[] RDATA;
public RecordUINFO(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,25 @@
using System;
/*
*/
namespace Heijden.DNS
{
public class RecordUNSPEC : Record
{
public byte[] RDATA;
public RecordUNSPEC(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("not-used");
}
}
}

View file

@ -0,0 +1,15 @@
using System;
namespace Heijden.DNS
{
public class RecordUnknown : Record
{
public byte[] RDATA;
public RecordUnknown(RecordReader rr)
{
// re-read length
ushort RDLENGTH = rr.ReadUInt16(-2);
RDATA = rr.ReadBytes(RDLENGTH);
}
}
}

View file

@ -1,51 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class NsRecord : DnsRecordBase
{
internal NsRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
//public override void ParseRecord(ref MemoryStream ms)
//{
// _answer = BaseDnsRecord.ParseName(ref ms);
//}
}
}

View file

@ -0,0 +1,65 @@
using System;
/*
* http://tools.ietf.org/rfc/rfc1712.txt
*
3. RDATA Format
MSB LSB
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ LONGITUDE /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ LATITUDE /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ ALTITUDE /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
LONGITUDE The real number describing the longitude encoded as a
printable string. The precision is limited by 256 charcters
within the range -90..90 degrees. Positive numbers
indicate locations north of the equator.
LATITUDE The real number describing the latitude encoded as a
printable string. The precision is limited by 256 charcters
within the range -180..180 degrees. Positive numbers
indicate locations east of the prime meridian.
ALTITUDE The real number describing the altitude (in meters) from
mean sea-level encoded as a printable string. The precision
is limited by 256 charcters. Positive numbers indicate
locations above mean sea-level.
Latitude/Longitude/Altitude values are encoded as strings as to avoid
the precision limitations imposed by encoding as unsigned integers.
Although this might not be considered optimal, it allows for a very
high degree of precision with an acceptable average encoded record
length.
*/
namespace Heijden.DNS
{
public class RecordGPOS : Record
{
public string LONGITUDE;
public string LATITUDE;
public string ALTITUDE;
public RecordGPOS(RecordReader rr)
{
LONGITUDE = rr.ReadString();
LATITUDE = rr.ReadString();
ALTITUDE = rr.ReadString();
}
public override string ToString()
{
return string.Format("{0} {1} {2}",
LONGITUDE,
LATITUDE,
ALTITUDE);
}
}
}

View file

@ -0,0 +1,41 @@
using System;
/*
3.3.4. MD RDATA format (Obsolete)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MADNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MADNAME A <domain-name> which specifies a host which has a mail
agent for the domain which should be able to deliver
mail for the domain.
MD records cause additional section processing which looks up an A type
record corresponding to MADNAME.
MD is obsolete. See the definition of MX and [RFC-974] for details of
the new scheme. The recommended policy for dealing with MD RRs found in
a master file is to reject them, or to convert them to MX RRs with a
preference of 0.
* */
namespace Heijden.DNS
{
public class RecordMD : Record
{
public string MADNAME;
public RecordMD(RecordReader rr)
{
MADNAME = rr.ReadDomainName();
}
public override string ToString()
{
return MADNAME;
}
}
}

View file

@ -0,0 +1,41 @@
using System;
/*
*
3.3.5. MF RDATA format (Obsolete)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MADNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MADNAME A <domain-name> which specifies a host which has a mail
agent for the domain which will accept mail for
forwarding to the domain.
MF records cause additional section processing which looks up an A type
record corresponding to MADNAME.
MF is obsolete. See the definition of MX and [RFC-974] for details ofw
the new scheme. The recommended policy for dealing with MD RRs found in
a master file is to reject them, or to convert them to MX RRs with a
preference of 10. */
namespace Heijden.DNS
{
public class RecordMF : Record
{
public string MADNAME;
public RecordMF(RecordReader rr)
{
MADNAME = rr.ReadDomainName();
}
public override string ToString()
{
return MADNAME;
}
}
}

View file

@ -0,0 +1,57 @@
using System;
/*
* http://tools.ietf.org/rfc/rfc1348.txt
* The NSAP-PTR RR
The NSAP-PTR RR is defined with mnemonic NSAP-PTR and a type code 23
(decimal).
Its function is analogous to the PTR record used for IP addresses [4,7].
NSAP-PTR has the following format:
<NSAP-suffix> <ttl> <class> NSAP-PTR <owner>
All fields are required.
<NSAP-suffix> enumerates the actual octet values assigned by the
assigning authority for the LOCAL network. Its format in master
files is a <character-string> syntactically identical to that used in
TXT and HINFO.
The format of NSAP-PTR is class insensitive. NSAP-PTR RR causes no
additional section processing.
For example:
In net ff08000574.nsap-in-addr.arpa:
444433332222111199990123000000ff NSAP-PTR foo.bar.com.
Or in net 11110031f67293.nsap-in-addr.arpa:
67894444333322220000 NSAP-PTR host.school.de.
The RR data is the ASCII representation of the digits. It is encoded
as a <character-string>.
*/
namespace Heijden.DNS
{
public class RecordNSAPPTR : Record
{
public string OWNER;
public RecordNSAPPTR(RecordReader rr)
{
OWNER = rr.ReadString();
}
public override string ToString()
{
return string.Format("{0}",OWNER);
}
}
}

View file

@ -0,0 +1,80 @@
using System;
using System.Text;
/*
* http://tools.ietf.org/rfc/rfc2065.txt
*
5.2 NXT RDATA Format
The RDATA for an NXT RR consists simply of a domain name followed by
a bit map.
The type number for the NXT RR is 30.
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| next domain name /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| type bit map /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The NXT RR type bit map is one bit per RR type present for the owner
name similar to the WKS socket bit map. The first bit represents RR
type zero (an illegal type which should not be present.) A one bit
indicates that at least one RR of that type is present for the owner
name. A zero indicates that no such RR is present. All bits not
specified because they are beyond the end of the bit map are assumed
to be zero. Note that bit 30, for NXT, will always be on so the
minimum bit map length is actually four octets. The NXT bit map
should be printed as a list of RR type mnemonics or decimal numbers
similar to the WKS RR.
The domain name may be compressed with standard DNS name compression
when being transmitted over the network. The size of the bit map can
be inferred from the RDLENGTH and the length of the next domain name.
*/
namespace Heijden.DNS
{
public class RecordNXT : Record
{
public string NEXTDOMAINNAME;
public byte[] BITMAP;
public RecordNXT(RecordReader rr)
{
ushort length = rr.ReadUInt16(-2);
NEXTDOMAINNAME = rr.ReadDomainName();
length -= (ushort)rr.Position;
BITMAP = new byte[length];
BITMAP = rr.ReadBytes(length);
}
private bool IsSet(int bitNr)
{
int intByte = (int)(bitNr / 8);
int intOffset = (bitNr % 8);
byte b = BITMAP[intByte];
int intTest = 1 << intOffset;
if ((b & intTest) == 0)
return false;
else
return true;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
for (int bitNr = 1; bitNr < (BITMAP.Length * 8); bitNr++)
{
if (IsSet(bitNr))
sb.Append(" " + (Type)bitNr);
}
return string.Format("{0}{1}", NEXTDOMAINNAME, sb.ToString());
}
}
}

View file

@ -1,51 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class PtrRecord : DnsRecordBase
{
internal PtrRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
//public override void ParseRecord(ref MemoryStream ms)
//{
// _answer = BaseDnsRecord.ParseName(ref ms);
//}
}
}

View file

@ -0,0 +1,12 @@
// Stuff records are made of
namespace Heijden.DNS
{
public abstract class Record
{
/// <summary>
/// The Resource Record this RDATA record belongs to
/// </summary>
public RR RR;
}
}

View file

@ -0,0 +1,38 @@
using System;
/*
3.4.1. A RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ADDRESS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
ADDRESS A 32 bit Internet address.
Hosts that have multiple Internet addresses will have multiple A
records.
*
*/
namespace Heijden.DNS
{
public class RecordA : Record
{
public System.Net.IPAddress Address;
public RecordA(RecordReader rr)
{
System.Net.IPAddress.TryParse(string.Format("{0}.{1}.{2}.{3}",
rr.ReadByte(),
rr.ReadByte(),
rr.ReadByte(),
rr.ReadByte()), out this.Address);
}
public override string ToString()
{
return Address.ToString();
}
}
}

View file

@ -0,0 +1,38 @@
using System;
#region Rfc info
/*
2.2 AAAA data format
A 128 bit IPv6 address is encoded in the data portion of an AAAA
resource record in network byte order (high-order byte first).
*/
#endregion
namespace Heijden.DNS
{
public class RecordAAAA : Record
{
public System.Net.IPAddress Address;
public RecordAAAA(RecordReader rr)
{
System.Net.IPAddress.TryParse(
string.Format("{0:x}:{1:x}:{2:x}:{3:x}:{4:x}:{5:x}:{6:x}:{7:x}",
rr.ReadUInt16(),
rr.ReadUInt16(),
rr.ReadUInt16(),
rr.ReadUInt16(),
rr.ReadUInt16(),
rr.ReadUInt16(),
rr.ReadUInt16(),
rr.ReadUInt16()), out this.Address);
}
public override string ToString()
{
return Address.ToString();
}
}
}

View file

@ -0,0 +1,52 @@
using System;
/* http://tools.ietf.org/rfc/rfc1183.txt
* 1. AFS Data Base location
This section defines an extension of the DNS to locate servers both
for AFS (AFS is a registered trademark of Transarc Corporation) and
for the Open Software Foundation's (OSF) Distributed Computing
Environment (DCE) authenticated naming system using HP/Apollo's NCA,
both to be components of the OSF DCE. The discussion assumes that
the reader is familiar with AFS [5] and NCA [6].
The AFS (originally the Andrew File System) system uses the DNS to
map from a domain name to the name of an AFS cell database server.
The DCE Naming service uses the DNS for a similar function: mapping
from the domain name of a cell to authenticated name servers for that
cell. The method uses a new RR type with mnemonic AFSDB and type
code of 18 (decimal).
AFSDB has the following format:
<owner> <ttl> <class> AFSDB <subtype> <hostname>
Both RDATA fields are required in all AFSDB RRs. The <subtype> field
is a 16 bit integer. The <hostname> field is a domain name of a host
that has a server for the cell named by the owner name of the RR.
*/
namespace Heijden.DNS
{
public class RecordAFSDB : Record
{
public ushort SUBTYPE;
public string HOSTNAME;
public RecordAFSDB(RecordReader rr)
{
SUBTYPE = rr.ReadUInt16();
//HOSTNAME = rr.ReadString();
HOSTNAME = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1}",
SUBTYPE,
HOSTNAME);
}
}
}

View file

@ -0,0 +1,39 @@
using System;
/*
*
3.3.1. CNAME RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ CNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
CNAME A <domain-name> which specifies the canonical or primary
name for the owner. The owner name is an alias.
CNAME RRs cause no additional section processing, but name servers may
choose to restart the query at the canonical name in certain cases. See
the description of name server logic in [RFC-1034] for details.
*
*/
namespace Heijden.DNS
{
public class RecordCNAME : Record
{
public string CNAME;
public RecordCNAME(RecordReader rr)
{
CNAME = rr.ReadDomainName();
}
public override string ToString()
{
return CNAME;
}
}
}

View file

@ -0,0 +1,34 @@
using System;
/*
* http://tools.ietf.org/rfc/rfc2672.txt
*
3. The DNAME Resource Record
The DNAME RR has mnemonic DNAME and type code 39 (decimal).
DNAME has the following format:
<owner> <ttl> <class> DNAME <target>
The format is not class-sensitive. All fields are required. The
RDATA field <target> is a <domain-name> [DNSIS].
*
*/
namespace Heijden.DNS
{
public class RecordDNAME : Record
{
public string TARGET;
public RecordDNAME(RecordReader rr)
{
TARGET = rr.ReadDomainName();
}
public override string ToString()
{
return TARGET;
}
}
}

View file

@ -0,0 +1,64 @@
using System;
using System.Text;
/*
* http://tools.ietf.org/rfc/rfc3658.txt
*
2.4. Wire Format of the DS record
The DS (type=43) record contains these fields: key tag, algorithm,
digest type, and the digest of a public key KEY record that is
allowed and/or used to sign the child's apex KEY RRset. Other keys
MAY sign the child's apex KEY RRset.
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| key tag | algorithm | Digest type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| digest (length depends on type) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| (SHA-1 digest is 20 bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
namespace Heijden.DNS
{
public class RecordDS : Record
{
public UInt16 KEYTAG;
public byte ALGORITHM;
public byte DIGESTTYPE;
public byte[] DIGEST;
public RecordDS(RecordReader rr)
{
ushort length = rr.ReadUInt16(-2);
KEYTAG = rr.ReadUInt16();
ALGORITHM = rr.ReadByte();
DIGESTTYPE = rr.ReadByte();
length -= 4;
DIGEST = new byte[length];
DIGEST = rr.ReadBytes(length);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
for (int intI = 0; intI < DIGEST.Length; intI++)
sb.AppendFormat("{0:x2}", DIGEST[intI]);
return string.Format("{0} {1} {2} {3}",
KEYTAG,
ALGORITHM,
DIGESTTYPE,
sb.ToString());
}
}
}

View file

@ -1,191 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using DnDns.Enums;
namespace DnDns.Records
{
class RecordFactory
{
public static IDnsRecord Create(ref MemoryStream ms)
{
IDnsRecord dnsRecord;
// Have to start out with an unknown record, since we have to parse the entire
// header before we can determine the type of DNS record it is.
// TODO: Consider other options.
// start as an unknown type, then create a known type, parse the response
// and return the object.
//DnsRecordBase dr = new DnsUnknownRecord();
//dr.ParseRecordHeader(ref ms);
RecordHeader dnsHeader = new RecordHeader();
dnsHeader.ParseRecordHeader(ref ms);
switch (dnsHeader.NsType)
{
case NsType.A:
{
dnsRecord = new ARecord(dnsHeader);
break;
}
case NsType.AAAA:
{
dnsRecord = new AaaaRecord(dnsHeader);
break;
}
case NsType.MX:
{
dnsRecord = new MxRecord(dnsHeader);
break;
}
case NsType.RP:
{
dnsRecord = new RpRecord(dnsHeader);
break;
}
case NsType.MR:
{
dnsRecord = new MrRecord(dnsHeader);
break;
}
case NsType.MB:
{
dnsRecord = new MbRecord(dnsHeader);
break;
}
case NsType.MG:
{
dnsRecord = new MgRecord(dnsHeader);
break;
}
case NsType.NS:
{
dnsRecord = new NsRecord(dnsHeader);
break;
}
case NsType.CNAME:
{
dnsRecord = new CNameRecord(dnsHeader);
break;
}
case NsType.PTR:
{
dnsRecord = new PtrRecord(dnsHeader);
break;
}
case NsType.HINFO:
{
dnsRecord = new HInfoRecord(dnsHeader);
break;
}
case NsType.MINFO:
{
dnsRecord = new MInfoRecord(dnsHeader);
break;
}
case NsType.X25:
{
dnsRecord = new X25Record(dnsHeader);
break;
}
case NsType.TXT:
{
dnsRecord = new TxtRecord(dnsHeader);
break;
}
case NsType.LOC:
{
dnsRecord = new LocRecord(dnsHeader);
break;
}
case NsType.SOA:
{
dnsRecord = new SoaRecord(dnsHeader);
break;
}
case NsType.SRV:
{
dnsRecord = new SrvRecord(dnsHeader);
break;
}
case NsType.AFSDB:
{
dnsRecord = new AfsdbRecord(dnsHeader);
break;
}
case NsType.ATMA:
{
dnsRecord = new AtmaRecord(dnsHeader);
break;
}
case NsType.ISDN:
{
dnsRecord = new IsdnRecord(dnsHeader);
break;
}
case NsType.RT:
{
dnsRecord = new RtRecord(dnsHeader);
break;
}
case NsType.WKS:
{
dnsRecord = new WksRecord(dnsHeader);
break;
}
case NsType.TSIG:
{
dnsRecord = new TSigRecord(dnsHeader);
break;
}
default:
{
// Unknown type. parse and return the DnsUnknownRecord
dnsRecord = new UnknownRecord(dnsHeader);
break;
}
}
//dnsRecord.ParseRecordHeader(ref ms);
dnsRecord.ParseRecord(ref ms);
return dnsRecord;
}
}
}

View file

@ -0,0 +1,45 @@
using System;
/*
3.3.2. HINFO RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ CPU /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ OS /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
CPU A <character-string> which specifies the CPU type.
OS A <character-string> which specifies the operating
system type.
Standard values for CPU and OS can be found in [RFC-1010].
HINFO records are used to acquire general information about a host. The
main use is for protocols such as FTP that can use special procedures
when talking between machines or operating systems of the same type.
*/
namespace Heijden.DNS
{
public class RecordHINFO : Record
{
public string CPU;
public string OS;
public RecordHINFO(RecordReader rr)
{
CPU = rr.ReadString();
OS = rr.ReadString();
}
public override string ToString()
{
return string.Format("CPU={0} OS={1}",CPU,OS);
}
}
}

View file

@ -1,242 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using DnDns.Enums;
namespace DnDns.Records
{
/// <summary>
/// The DnsRecordHeader class contains fields, properties and
/// parsing cababilities within the DNS Record except the the
/// RDATA. The Name, Type, Class, TTL, and RDLength.
///
/// This class is used in the DnsRecordFactory to instantiate
/// concrete DnsRecord Classes.
///
/// RFC 1035
///
/// 3.2.1. Format
///
/// All RRs have the same top level format shown below:
///
/// 1 1 1 1 1 1
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | |
/// / /
/// / NAME /
/// | |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | TYPE |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | CLASS |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | TTL |
/// | |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | RDLENGTH |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
///
/// where:
///
/// NAME an owner name, i.e., the name of the node to which this
/// resource record pertains.
///
/// TYPE two octets containing one of the RR TYPE codes.
///
/// CLASS two octets containing one of the RR CLASS codes.
///
/// TTL a 32 bit signed integer that specifies the time interval
/// that the resource record may be cached before the source
/// of the information should again be consulted. Zero
/// values are interpreted to mean that the RR can only be
/// used for the transaction in progress, and should not be
/// cached. For example, SOA records are always distributed
/// with a zero TTL to prohibit caching. Zero values can
/// also be used for extremely volatile data.
///
/// RDLENGTH an unsigned 16 bit integer that specifies the length in
/// octets of the RDATA field.
///
/// </summary>
public class RecordHeader
{
#region Fields
// NAME an owner name, i.e., the name of the node to which this
// resource record pertains.
private string _name;
// TYPE two octets containing one of the RR TYPE codes.
private NsType _nsType;
// CLASS - two octets containing one of the RR CLASS codes.
private NsClass _nsClass;
// TTL - a 32 bit signed integer that specifies the time interval
// that the resource record may be cached before the source
// of the information should again be consulted. Zero
// values are interpreted to mean that the RR can only be
// used for the transaction in progress, and should not be
// cached. For example, SOA records are always distributed
// with a zero TTL to prohibit caching. Zero values can
/// also be used for extremely volatile data.
private int _timeToLive;
// RDLENGTH - an unsigned 16 bit integer that specifies the length in
// octets of the RDATA field.
private short _dataLength;
/// <summary>
/// Initalise the <see cref="RecordHeader"/>
/// </summary>
/// <param name="name">The header name</param>
/// <param name="nsType">The resource type</param>
/// <param name="nsClass">The class type</param>
/// <param name="timeToLive">The time to live</param>
public RecordHeader(string name, NsType nsType, NsClass nsClass, int timeToLive)
{
_name = name;
_nsType = nsType;
_nsClass = nsClass;
_timeToLive = timeToLive;
}
public RecordHeader()
{
}
#endregion
#region Properties
/// <summary>
/// NAME - an owner name, i.e., the name of the node to which this
/// resource record pertains.
/// </summary>
public string Name
{
get { return _name; }
}
/// <summary>
/// TYPE two octets containing one of the RR TYPE codes.
/// </summary>
public NsType NsType
{
get { return _nsType; }
}
/// <summary>
/// CLASS - two octets containing one of the RR CLASS codes.
/// </summary>
public NsClass NsClass
{
get { return _nsClass; }
}
/// <summary>
/// TTL - a 32 bit signed integer that specifies the time interval
/// that the resource record may be cached before the source
/// of the information should again be consulted. Zero
/// values are interpreted to mean that the RR can only be
/// used for the transaction in progress, and should not be
/// cached. 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 int TimeToLive
{
get { return _timeToLive; }
}
/// <summary>
/// RDLENGTH - an unsigned 16 bit integer that specifies the length in
/// octets of the RDATA field.
/// </summary>
public short DataLength
{
get { return _dataLength; }
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="ms"></param>
public void ParseRecordHeader(ref MemoryStream ms)
{
byte[] nsType = new byte[2];
byte[] nsClass = new byte[2];
byte[] nsTTL = new byte[4];
byte[] nsDataLength = new byte[2];
// Read the name
_name = DnsRecordBase.ParseName(ref ms);
// Read the data header
ms.Read(nsType, 0, 2);
ms.Read(nsClass, 0, 2);
ms.Read(nsTTL, 0, 4);
ms.Read(nsDataLength, 0, 2);
_nsType = (NsType)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsType, 0));
_nsClass = (NsClass)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsClass, 0));
_timeToLive = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(nsTTL, 0));
_dataLength = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsDataLength, 0));
}
internal byte[] GetMessageBytes()
{
MemoryStream memoryStream = new MemoryStream();
byte[] data = DnsHelpers.CanonicaliseDnsName(_name, false);
memoryStream.Write(data,0,data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_nsType) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_nsClass) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((uint)(IPAddress.HostToNetworkOrder((ushort)_timeToLive) >> 32));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_dataLength) >> 16));
memoryStream.Write(data, 0, data.Length);
return memoryStream.ToArray();
}
}
}

View file

@ -0,0 +1,91 @@
using System;
/* http://tools.ietf.org/rfc/rfc1183.txt
3.2. The ISDN RR
The ISDN RR is defined with mnemonic ISDN and type code 20 (decimal).
An ISDN (Integrated Service Digital Network) number is simply a
telephone number. The intent of the members of the CCITT is to
upgrade all telephone and data network service to a common service.
The numbering plan (E.163/E.164) is the same as the familiar
international plan for POTS (an un-official acronym, meaning Plain
Old Telephone Service). In E.166, CCITT says "An E.163/E.164
telephony subscriber may become an ISDN subscriber without a number
change."
ISDN has the following format:
<owner> <ttl> <class> ISDN <ISDN-address> <sa>
The <ISDN-address> field is required; <sa> is optional.
<ISDN-address> identifies the ISDN number of <owner> and DDI (Direct
Dial In) if any, as defined by E.164 [8] and E.163 [7], the ISDN and
PSTN (Public Switched Telephone Network) numbering plan. E.163
defines the country codes, and E.164 the form of the addresses. Its
format in master files is a <character-string> syntactically
identical to that used in TXT and HINFO.
<sa> specifies the subaddress (SA). The format of <sa> in master
files is a <character-string> syntactically identical to that used in
TXT and HINFO.
The format of ISDN is class insensitive. ISDN RRs cause no
additional section processing.
The <ISDN-address> is a string of characters, normally decimal
digits, beginning with the E.163 country code and ending with the DDI
if any. Note that ISDN, in Q.931, permits any IA5 character in the
general case.
The <sa> is a string of hexadecimal digits. For digits 0-9, the
concrete encoding in the Q.931 call setup information element is
identical to BCD.
For example:
Relay.Prime.COM. IN ISDN 150862028003217
sh.Prime.COM. IN ISDN 150862028003217 004
(Note: "1" is the country code for the North American Integrated
Numbering Area, i.e., the system of "area codes" familiar to people
in those countries.)
The RR data is the ASCII representation of the digits. It is encoded
as one or two <character-string>s, i.e., count followed by
characters.
CCITT recommendation E.166 [9] defines prefix escape codes for the
representation of ISDN (E.163/E.164) addresses in X.121, and PSDN
(X.121) addresses in E.164. It specifies that the exact codes are a
"national matter", i.e., different on different networks. A host
connected to the ISDN may be able to use both the X25 and ISDN
addresses, with the local prefix added.
*/
namespace Heijden.DNS
{
public class RecordISDN : Record
{
public string ISDNADDRESS;
public string SA;
public RecordISDN(RecordReader rr)
{
ISDNADDRESS = rr.ReadString();
SA = rr.ReadString();
}
public override string ToString()
{
return string.Format("{0} {1}",
ISDNADDRESS,
SA);
}
}
}

View file

@ -0,0 +1,65 @@
using System;
#region Rfc info
/* http://www.ietf.org/rfc/rfc2535.txt
*
3.1 KEY RDATA format
The RDATA for a KEY RR consists of flags, a protocol octet, the
algorithm number octet, and the public key itself. The format is as
follows:
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| flags | protocol | algorithm |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /
/ public key /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
The KEY RR is not intended for storage of certificates and a separate
certificate RR has been developed for that purpose, defined in [RFC
2538].
The meaning of the KEY RR owner name, flags, and protocol octet are
described in Sections 3.1.1 through 3.1.5 below. The flags and
algorithm must be examined before any data following the algorithm
octet as they control the existence and format of any following data.
The algorithm and public key fields are described in Section 3.2.
The format of the public key is algorithm dependent.
KEY RRs do not specify their validity period but their authenticating
SIG RR(s) do as described in Section 4 below.
*/
#endregion
namespace Heijden.DNS
{
public class RecordKEY : Record
{
public UInt16 FLAGS;
public byte PROTOCOL;
public byte ALGORITHM;
public string PUBLICKEY;
public RecordKEY(RecordReader rr)
{
FLAGS = rr.ReadUInt16();
PROTOCOL = rr.ReadByte();
ALGORITHM = rr.ReadByte();
PUBLICKEY = rr.ReadString();
}
public override string ToString()
{
return string.Format("{0} {1} {2} \"{3}\"",
FLAGS,
PROTOCOL,
ALGORITHM,
PUBLICKEY);
}
}
}

View file

@ -0,0 +1,65 @@
using System;
/*
* http://tools.ietf.org/rfc/rfc2230.txt
*
* 3.1 KX RDATA format
The KX DNS record has the following RDATA format:
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PREFERENCE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ EXCHANGER /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
PREFERENCE A 16 bit non-negative integer which specifies the
preference given to this RR among other KX records
at the same owner. Lower values are preferred.
EXCHANGER A <domain-name> which specifies a host willing to
act as a mail exchange for the owner name.
KX records MUST cause type A additional section processing for the
host specified by EXCHANGER. In the event that the host processing
the DNS transaction supports IPv6, KX records MUST also cause type
AAAA additional section processing.
The KX RDATA field MUST NOT be compressed.
*/
namespace Heijden.DNS
{
public class RecordKX : Record, IComparable
{
public ushort PREFERENCE;
public string EXCHANGER;
public RecordKX(RecordReader rr)
{
PREFERENCE = rr.ReadUInt16();
EXCHANGER = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1}", PREFERENCE, EXCHANGER);
}
public int CompareTo(object objA)
{
RecordKX recordKX = objA as RecordKX;
if (recordKX == null)
return -1;
else if (this.PREFERENCE > recordKX.PREFERENCE)
return 1;
else if (this.PREFERENCE < recordKX.PREFERENCE)
return -1;
else // they are the same, now compare case insensitive names
return string.Compare(this.EXCHANGER, recordKX.EXCHANGER, true);
}
}
}

View file

@ -0,0 +1,199 @@
using System;
using System.Text;
/*
* http://www.ietf.org/rfc/rfc1876.txt
*
2. RDATA Format
MSB LSB
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
0| VERSION | SIZE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
2| HORIZ PRE | VERT PRE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
4| LATITUDE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
6| LATITUDE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
8| LONGITUDE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
10| LONGITUDE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
12| ALTITUDE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
14| ALTITUDE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
VERSION Version number of the representation. This must be zero.
Implementations are required to check this field and make
no assumptions about the format of unrecognized versions.
SIZE The diameter of a sphere enclosing the described entity, in
centimeters, expressed as a pair of four-bit unsigned
integers, each ranging from zero to nine, with the most
significant four bits representing the base and the second
number representing the power of ten by which to multiply
the base. This allows sizes from 0e0 (<1cm) to 9e9
(90,000km) to be expressed. This representation was chosen
such that the hexadecimal representation can be read by
eye; 0x15 = 1e5. Four-bit values greater than 9 are
undefined, as are values with a base of zero and a non-zero
exponent.
Since 20000000m (represented by the value 0x29) is greater
than the equatorial diameter of the WGS 84 ellipsoid
(12756274m), it is therefore suitable for use as a
"worldwide" size.
HORIZ PRE The horizontal precision of the data, in centimeters,
expressed using the same representation as SIZE. This is
the diameter of the horizontal "circle of error", rather
than a "plus or minus" value. (This was chosen to match
the interpretation of SIZE; to get a "plus or minus" value,
divide by 2.)
VERT PRE The vertical precision of the data, in centimeters,
expressed using the sane representation as for SIZE. This
is the total potential vertical error, rather than a "plus
or minus" value. (This was chosen to match the
interpretation of SIZE; to get a "plus or minus" value,
divide by 2.) Note that if altitude above or below sea
level is used as an approximation for altitude relative to
the [WGS 84] ellipsoid, the precision value should be
adjusted.
LATITUDE The latitude of the center of the sphere described by the
SIZE field, expressed as a 32-bit integer, most significant
octet first (network standard byte order), in thousandths
of a second of arc. 2^31 represents the equator; numbers
above that are north latitude.
LONGITUDE The longitude of the center of the sphere described by the
SIZE field, expressed as a 32-bit integer, most significant
octet first (network standard byte order), in thousandths
of a second of arc, rounded away from the prime meridian.
2^31 represents the prime meridian; numbers above that are
east longitude.
ALTITUDE The altitude of the center of the sphere described by the
SIZE field, expressed as a 32-bit integer, most significant
octet first (network standard byte order), in centimeters,
from a base of 100,000m below the [WGS 84] reference
spheroid used by GPS (semimajor axis a=6378137.0,
reciprocal flattening rf=298.257223563). Altitude above
(or below) sea level may be used as an approximation of
altitude relative to the the [WGS 84] spheroid, though due
to the Earth's surface not being a perfect spheroid, there
will be differences. (For example, the geoid (which sea
level approximates) for the continental US ranges from 10
meters to 50 meters below the [WGS 84] spheroid.
Adjustments to ALTITUDE and/or VERT PRE will be necessary
in most cases. The Defense Mapping Agency publishes geoid
height values relative to the [WGS 84] ellipsoid.
*/
namespace Heijden.DNS
{
public class RecordLOC : Record
{
public byte VERSION;
public byte SIZE;
public byte HORIZPRE;
public byte VERTPRE;
public UInt32 LATITUDE;
public UInt32 LONGITUDE;
public UInt32 ALTITUDE;
private string SizeToString(byte s)
{
string strUnit = "cm";
int intBase = s >> 4;
int intPow = s & 0x0f;
if (intPow >= 2)
{
intPow -= 2;
strUnit = "m";
}
/*
if (intPow >= 3)
{
intPow -= 3;
strUnit = "km";
}
*/
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}", intBase);
for (; intPow > 0; intPow--)
sb.Append('0');
sb.Append(strUnit);
return sb.ToString();
}
private string LonToTime(UInt32 r)
{
UInt32 Mid = 2147483648; // 2^31
char Dir = 'E';
if (r > Mid)
{
Dir = 'W';
r -= Mid;
}
double h = r / (360000.0 * 10.0);
double m = 60.0 * (h - (int)h);
double s = 60.0 * (m - (int)m);
return string.Format("{0} {1} {2:0.000} {3}", (int)h, (int)m, s, Dir);
}
private string ToTime(UInt32 r, char Below,char Above)
{
UInt32 Mid = 2147483648; // 2^31
char Dir = '?';
if (r > Mid)
{
Dir = Above;
r -= Mid;
}
else
{
Dir = Below;
r = Mid - r;
}
double h = r / (360000.0 * 10.0);
double m = 60.0 * (h - (int)h);
double s = 60.0 * (m - (int)m);
return string.Format("{0} {1} {2:0.000} {3}", (int)h, (int)m, s, Dir);
}
private string ToAlt(UInt32 a)
{
double alt = (a / 100.0) - 100000.00;
return string.Format("{0:0.00}m", alt);
}
public RecordLOC(RecordReader rr)
{
VERSION = rr.ReadByte(); // must be 0!
SIZE = rr.ReadByte();
HORIZPRE = rr.ReadByte();
VERTPRE = rr.ReadByte();
LATITUDE = rr.ReadUInt32();
LONGITUDE = rr.ReadUInt32();
ALTITUDE = rr.ReadUInt32();
}
public override string ToString()
{
return string.Format("{0} {1} {2} {3} {4} {5}",
ToTime(LATITUDE,'S','N'),
ToTime(LONGITUDE,'W','E'),
ToAlt(ALTITUDE),
SizeToString(SIZE),
SizeToString(HORIZPRE),
SizeToString(VERTPRE));
}
}
}

View file

@ -0,0 +1,35 @@
using System;
/*
3.3.3. MB RDATA format (EXPERIMENTAL)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MADNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MADNAME A <domain-name> which specifies a host which has the
specified mailbox.
MB records cause additional section processing which looks up an A type
RRs corresponding to MADNAME.
*/
namespace Heijden.DNS
{
public class RecordMB : Record
{
public string MADNAME;
public RecordMB(RecordReader rr)
{
MADNAME = rr.ReadDomainName();
}
public override string ToString()
{
return MADNAME;
}
}
}

View file

@ -0,0 +1,34 @@
using System;
/*
3.3.6. MG RDATA format (EXPERIMENTAL)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MGMNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MGMNAME A <domain-name> which specifies a mailbox which is a
member of the mail group specified by the domain name.
MG records cause no additional section processing.
*/
namespace Heijden.DNS
{
public class RecordMG : Record
{
public string MGMNAME;
public RecordMG(RecordReader rr)
{
MGMNAME = rr.ReadDomainName();
}
public override string ToString()
{
return MGMNAME;
}
}
}

View file

@ -0,0 +1,52 @@
using System;
/*
3.3.7. MINFO RDATA format (EXPERIMENTAL)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ RMAILBX /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ EMAILBX /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
RMAILBX A <domain-name> which specifies a mailbox which is
responsible for the mailing list or mailbox. If this
domain name names the root, the owner of the MINFO RR is
responsible for itself. Note that many existing mailing
lists use a mailbox X-request for the RMAILBX field of
mailing list X, e.g., Msgroup-request for Msgroup. This
field provides a more general mechanism.
EMAILBX A <domain-name> which specifies a mailbox which is to
receive error messages related to the mailing list or
mailbox specified by the owner of the MINFO RR (similar
to the ERRORS-TO: field which has been proposed). If
this domain name names the root, errors should be
returned to the sender of the message.
MINFO records cause no additional section processing. Although these
records can be associated with a simple mailbox, they are usually used
with a mailing list.
*/
namespace Heijden.DNS
{
public class RecordMINFO : Record
{
public string RMAILBX;
public string EMAILBX;
public RecordMINFO(RecordReader rr)
{
RMAILBX = rr.ReadDomainName();
EMAILBX = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1}",RMAILBX,EMAILBX);
}
}
}

View file

@ -0,0 +1,36 @@
using System;
/*
3.3.8. MR RDATA format (EXPERIMENTAL)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ NEWNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
NEWNAME A <domain-name> which specifies a mailbox which is the
proper rename of the specified mailbox.
MR records cause no additional section processing. The main use for MR
is as a forwarding entry for a user who has moved to a different
mailbox.
*/
namespace Heijden.DNS
{
public class RecordMR : Record
{
public string NEWNAME;
public RecordMR(RecordReader rr)
{
NEWNAME = rr.ReadDomainName();
}
public override string ToString()
{
return NEWNAME;
}
}
}

View file

@ -0,0 +1,59 @@
using System;
namespace Heijden.DNS
{
/*
3.3.9. MX RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PREFERENCE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ EXCHANGE /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
PREFERENCE A 16 bit integer which specifies the preference given to
this RR among others at the same owner. Lower values
are preferred.
EXCHANGE A <domain-name> which specifies a host willing to act as
a mail exchange for the owner name.
MX records cause type A additional section processing for the host
specified by EXCHANGE. The use of MX RRs is explained in detail in
[RFC-974].
*/
public class RecordMX : Record, IComparable
{
public ushort PREFERENCE;
public string EXCHANGE;
public RecordMX(RecordReader rr)
{
PREFERENCE = rr.ReadUInt16();
EXCHANGE = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1}", PREFERENCE, EXCHANGE);
}
public int CompareTo(object objA)
{
RecordMX recordMX = objA as RecordMX;
if (recordMX == null)
return -1;
else if (this.PREFERENCE > recordMX.PREFERENCE)
return 1;
else if (this.PREFERENCE < recordMX.PREFERENCE)
return -1;
else // they are the same, now compare case insensitive names
return string.Compare(this.EXCHANGE, recordMX.EXCHANGE, true);
}
}
}

View file

@ -0,0 +1,77 @@
using System;
/*
* http://www.faqs.org/rfcs/rfc2915.html
*
8. DNS Packet Format
The packet format for the NAPTR record is:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ORDER |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PREFERENCE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ FLAGS /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ SERVICES /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ REGEXP /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ REPLACEMENT /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
FLAGS A <character-string> which contains various flags.
SERVICES A <character-string> which contains protocol and service
identifiers.
REGEXP A <character-string> which contains a regular expression.
REPLACEMENT A <domain-name> which specifies the new value in the
case where the regular expression is a simple replacement
operation.
<character-string> and <domain-name> as used here are defined in
RFC1035 [1].
*/
namespace Heijden.DNS
{
public class RecordNAPTR : Record
{
public ushort ORDER;
public ushort PREFERENCE;
public string FLAGS;
public string SERVICES;
public string REGEXP;
public string REPLACEMENT;
public RecordNAPTR(RecordReader rr)
{
ORDER = rr.ReadUInt16();
PREFERENCE = rr.ReadUInt16();
FLAGS = rr.ReadString();
SERVICES = rr.ReadString();
REGEXP = rr.ReadString();
REPLACEMENT = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1} \"{2}\" \"{3}\" \"{4}\" {5}",
ORDER,
PREFERENCE,
FLAGS,
SERVICES,
REGEXP,
REPLACEMENT);
}
}
}

View file

@ -0,0 +1,43 @@
using System;
/*
3.3.11. NS RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ NSDNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
NSDNAME A <domain-name> which specifies a host which should be
authoritative for the specified class and domain.
NS records cause both the usual additional section processing to locate
a type A record, and, when used in a referral, a special search of the
zone in which they reside for glue information.
The NS RR states that the named host should be expected to have a zone
starting at owner name of the specified class. Note that the class may
not indicate the protocol family which should be used to communicate
with the host, although it is typically a strong hint. For example,
hosts which are name servers for either Internet (IN) or Hesiod (HS)
class information are normally queried using IN class protocols.
*/
namespace Heijden.DNS
{
public class RecordNS : Record
{
public string NSDNAME;
public RecordNS(RecordReader rr)
{
NSDNAME = rr.ReadDomainName();
}
public override string ToString()
{
return NSDNAME;
}
}
}

View file

@ -0,0 +1,72 @@
using System;
using System.Text;
/*
* http://tools.ietf.org/rfc/rfc1348.txt
* http://tools.ietf.org/html/rfc1706
*
* |--------------|
| <-- IDP --> |
|--------------|-------------------------------------|
| AFI | IDI | <-- DSP --> |
|-----|--------|-------------------------------------|
| 47 | 0005 | DFI | AA |Rsvd | RD |Area | ID |Sel |
|-----|--------|-----|----|-----|----|-----|----|----|
octets | 1 | 2 | 1 | 3 | 2 | 2 | 2 | 6 | 1 |
|-----|--------|-----|----|-----|----|-----|----|----|
IDP Initial Domain Part
AFI Authority and Format Identifier
IDI Initial Domain Identifier
DSP Domain Specific Part
DFI DSP Format Identifier
AA Administrative Authority
Rsvd Reserved
RD Routing Domain Identifier
Area Area Identifier
ID System Identifier
SEL NSAP Selector
Figure 1: GOSIP Version 2 NSAP structure.
*/
namespace Heijden.DNS
{
public class RecordNSAP : Record
{
public ushort LENGTH;
public byte[] NSAPADDRESS;
public RecordNSAP(RecordReader rr)
{
LENGTH = rr.ReadUInt16();
NSAPADDRESS = rr.ReadBytes(LENGTH);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} ", LENGTH);
for (int intI = 0; intI < NSAPADDRESS.Length; intI++)
sb.AppendFormat("{0:X00}", NSAPADDRESS[intI]);
return sb.ToString();
}
public string ToGOSIPV2()
{
return string.Format("{0:X}.{1:X}.{2:X}.{3:X}.{4:X}.{5:X}.{6:X}{7:X}.{8:X}",
NSAPADDRESS[0], // AFI
NSAPADDRESS[1] << 8 | NSAPADDRESS[2], // IDI
NSAPADDRESS[3], // DFI
NSAPADDRESS[4] << 16 | NSAPADDRESS[5] << 8 | NSAPADDRESS[6], // AA
NSAPADDRESS[7] << 8 | NSAPADDRESS[8], // Rsvd
NSAPADDRESS[9] << 8 | NSAPADDRESS[10],// RD
NSAPADDRESS[11] << 8 | NSAPADDRESS[12],// Area
NSAPADDRESS[13] << 16 | NSAPADDRESS[14] << 8 | NSAPADDRESS[15], // ID-High
NSAPADDRESS[16] << 16 | NSAPADDRESS[17] << 8 | NSAPADDRESS[18], // ID-Low
NSAPADDRESS[19]);
}
}
}

View file

@ -0,0 +1,38 @@
using System;
/*
3.3.10. NULL RDATA format (EXPERIMENTAL)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ <anything> /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Anything at all may be in the RDATA field so long as it is 65535 octets
or less.
NULL records cause no additional section processing. NULL RRs are not
allowed in master files. NULLs are used as placeholders in some
experimental extensions of the DNS.
*/
namespace Heijden.DNS
{
public class RecordNULL : Record
{
public byte[] ANYTHING;
public RecordNULL(RecordReader rr)
{
rr.Position -= 2;
// re-read length
ushort RDLENGTH = rr.ReadUInt16();
ANYTHING = new byte[RDLENGTH];
ANYTHING = rr.ReadBytes(RDLENGTH);
}
public override string ToString()
{
return string.Format("...binary data... ({0}) bytes",ANYTHING.Length);
}
}
}

View file

@ -0,0 +1,38 @@
using System;
/*
3.3.12. PTR RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ PTRDNAME /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
PTRDNAME A <domain-name> which points to some location in the
domain name space.
PTR records cause no additional section processing. These RRs are used
in special domains to point to some other location in the domain space.
These records are simple data, and don't imply any special processing
similar to that performed by CNAME, which identifies aliases. See the
description of the IN-ADDR.ARPA domain for an example.
*/
namespace Heijden.DNS
{
public class RecordPTR : Record
{
public string PTRDNAME;
public RecordPTR(RecordReader rr)
{
PTRDNAME = rr.ReadDomainName();
}
public override string ToString()
{
return PTRDNAME;
}
}
}

View file

@ -0,0 +1,97 @@
using System;
/*
* http://tools.ietf.org/rfc/rfc2163.txt
*
4. The new DNS resource record for MIXER mapping rules: PX
The specification of the Internet DNS (RFC1035) provides a number of
specific resource records (RRs) to contain specific pieces of
information. In particular they contain the Mail eXchanger (MX) RR
and the host Address (A) records which are used by the Internet SMTP
mailers. As we will store the RFC822 to X.400 mapping information in
the already existing DNS name tree, we need to define a new DNS RR in
order to avoid any possible clash or misuse of already existing data
structures. The same new RR will also be used to store the mappings
from X.400 to RFC822. More over the mapping information, i.e., the
MCGAMs, has a specific format and syntax which require an appropriate
data structure and processing. A further advantage of defining a new
RR is the ability to include flexibility for some eventual future
development.
The definition of the new 'PX' DNS resource record is:
class: IN (Internet)
name: PX (pointer to X.400/RFC822 mapping information)
value: 26
The PX RDATA format is:
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PREFERENCE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MAP822 /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MAPX400 /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
PREFERENCE A 16 bit integer which specifies the preference given to
this RR among others at the same owner. Lower values
are preferred;
MAP822 A <domain-name> element containing <rfc822-domain>, the
RFC822 part of the MCGAM;
MAPX400 A <domain-name> element containing the value of
<x400-in-domain-syntax> derived from the X.400 part of
the MCGAM (see sect. 4.2);
PX records cause no additional section processing. The PX RR format
is the usual one:
<name> [<class>] [<TTL>] <type> <RDATA>
When we store in DNS a 'table1' or a 'gate1' entry, then <name> will
be an X.400 mail domain name in DNS syntax (see sect. 4.2). When we
store a 'table2' or a 'gate2' table entry, <name> will be an RFC822
mail domain name, including both fully qualified DNS domains and mail
only domains (MX-only domains). All normal DNS conventions, like
default values, wildcards, abbreviations and message compression,
apply also for all the components of the PX RR. In particular <name>,
MAP822 and MAPX400, as <domain-name> elements, must have the final
"." (root) when they are fully qualified.
*/
namespace Heijden.DNS
{
public class RecordPX : Record
{
public UInt16 PREFERENCE;
public string MAP822;
public string MAPX400;
public RecordPX(RecordReader rr)
{
PREFERENCE = rr.ReadUInt16();
MAP822 = rr.ReadDomainName();
MAPX400 = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1} {2}",
PREFERENCE,
MAP822,
MAPX400);
}
}
}

View file

@ -0,0 +1,54 @@
using System;
/* http://tools.ietf.org/rfc/rfc1183.txt
2.2. The Responsible Person RR
The method uses a new RR type with mnemonic RP and type code of 17
(decimal).
RP has the following format:
<owner> <ttl> <class> RP <mbox-dname> <txt-dname>
Both RDATA fields are required in all RP RRs.
The first field, <mbox-dname>, is a domain name that specifies the
mailbox for the responsible person. Its format in master files uses
the DNS convention for mailbox encoding, identical to that used for
the RNAME mailbox field in the SOA RR. The root domain name (just
".") may be specified for <mbox-dname> to indicate that no mailbox is
available.
The second field, <txt-dname>, is a domain name for which TXT RR's
exist. A subsequent query can be performed to retrieve the
associated TXT resource records at <txt-dname>. This provides a
level of indirection so that the entity can be referred to from
multiple places in the DNS. The root domain name (just ".") may be
specified for <txt-dname> to indicate that the TXT_DNAME is absent,
and no associated TXT RR exists.
*/
namespace Heijden.DNS
{
public class RecordRP : Record
{
public string MBOXDNAME;
public string TXTDNAME;
public RecordRP(RecordReader rr)
{
//MBOXDNAME = rr.ReadString();
MBOXDNAME = rr.ReadDomainName();
TXTDNAME = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1}",
MBOXDNAME,
TXTDNAME);
}
}
}

View file

@ -0,0 +1,76 @@
using System;
/* http://tools.ietf.org/rfc/rfc1183.txt
3.3. The Route Through RR
The Route Through RR is defined with mnemonic RT and type code 21
(decimal).
The RT resource record provides a route-through binding for hosts
that do not have their own direct wide area network addresses. It is
used in much the same way as the MX RR.
RT has the following format:
<owner> <ttl> <class> RT <preference> <intermediate-host>
Both RDATA fields are required in all RT RRs.
The first field, <preference>, is a 16 bit integer, representing the
preference of the route. Smaller numbers indicate more preferred
routes.
<intermediate-host> is the domain name of a host which will serve as
an intermediate in reaching the host specified by <owner>. The DNS
RRs associated with <intermediate-host> are expected to include at
least one A, X25, or ISDN record.
The format of the RT RR is class insensitive. RT records cause type
X25, ISDN, and A additional section processing for <intermediate-
host>.
For example,
sh.prime.com. IN RT 2 Relay.Prime.COM.
IN RT 10 NET.Prime.COM.
*.prime.com. IN RT 90 Relay.Prime.COM.
When a host is looking up DNS records to attempt to route a datagram,
it first looks for RT records for the destination host, which point
to hosts with address records (A, X25, ISDN) compatible with the wide
area networks available to the host. If it is itself in the set of
RT records, it discards any RTs with preferences higher or equal to
its own. If there are no (remaining) RTs, it can then use address
records of the destination itself.
Wild-card RTs are used exactly as are wild-card MXs. RT's do not
"chain"; that is, it is not valid to use the RT RRs found for a host
referred to by an RT.
The concrete encoding is identical to the MX RR.
*/
namespace Heijden.DNS
{
public class RecordRT : Record
{
public ushort PREFERENCE;
public string INTERMEDIATEHOST;
public RecordRT(RecordReader rr)
{
PREFERENCE = rr.ReadUInt16();
INTERMEDIATEHOST = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1}",
PREFERENCE,
INTERMEDIATEHOST);
}
}
}

View file

@ -0,0 +1,77 @@
using System;
#region Rfc info
/*
* http://www.ietf.org/rfc/rfc2535.txt
* 4.1 SIG RDATA Format
The RDATA portion of a SIG RR is as shown below. The integrity of
the RDATA information is protected by the signature field.
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| type covered | algorithm | labels |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| original TTL |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| signature expiration |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| signature inception |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| key tag | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ signer's name +
| /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-/
/ /
/ signature /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#endregion
namespace Heijden.DNS
{
public class RecordSIG : Record
{
public UInt16 TYPECOVERED;
public byte ALGORITHM;
public byte LABELS;
public UInt32 ORIGINALTTL;
public UInt32 SIGNATUREEXPIRATION;
public UInt32 SIGNATUREINCEPTION;
public UInt16 KEYTAG;
public string SIGNERSNAME;
public string SIGNATURE;
public RecordSIG(RecordReader rr)
{
TYPECOVERED = rr.ReadUInt16();
ALGORITHM = rr.ReadByte();
LABELS = rr.ReadByte();
ORIGINALTTL = rr.ReadUInt32();
SIGNATUREEXPIRATION = rr.ReadUInt32();
SIGNATUREINCEPTION = rr.ReadUInt32();
KEYTAG = rr.ReadUInt16();
SIGNERSNAME = rr.ReadDomainName();
SIGNATURE = rr.ReadString();
}
public override string ToString()
{
return string.Format("{0} {1} {2} {3} {4} {5} {6} {7} \"{8}\"",
TYPECOVERED,
ALGORITHM,
LABELS,
ORIGINALTTL,
SIGNATUREEXPIRATION,
SIGNATUREINCEPTION,
KEYTAG,
SIGNERSNAME,
SIGNATURE);
}
}
}

View file

@ -0,0 +1,105 @@
using System;
/*
3.3.13. SOA RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ RNAME /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| SERIAL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| REFRESH |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RETRY |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| EXPIRE |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| MINIMUM |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MNAME The <domain-name> of the name server that was the
original or primary source of data for this zone.
RNAME A <domain-name> which specifies the mailbox of the
person responsible for this zone.
SERIAL The unsigned 32 bit version number of the original copy
of the zone. Zone transfers preserve this value. This
value wraps and should be compared using sequence space
arithmetic.
REFRESH A 32 bit time interval before the zone should be
refreshed.
RETRY A 32 bit time interval that should elapse before a
failed refresh should be retried.
EXPIRE A 32 bit time value that specifies the upper limit on
the time interval that can elapse before the zone is no
longer authoritative.
MINIMUM The unsigned 32 bit minimum TTL field that should be
exported with any RR from this zone.
SOA records cause no additional section processing.
All times are in units of seconds.
Most of these fields are pertinent only for name server maintenance
operations. However, MINIMUM is used in all query operations that
retrieve RRs from a zone. Whenever a RR is sent in a response to a
query, the TTL field is set to the maximum of the TTL field from the RR
and the MINIMUM field in the appropriate SOA. Thus MINIMUM is a lower
bound on the TTL field for all RRs in a zone. Note that this use of
MINIMUM should occur when the RRs are copied into the response and not
when the zone is loaded from a master file or via a zone transfer. The
reason for this provison is to allow future dynamic update facilities to
change the SOA RR with known semantics.
*/
namespace Heijden.DNS
{
public class RecordSOA : Record
{
public string MNAME;
public string RNAME;
public uint SERIAL;
public uint REFRESH;
public uint RETRY;
public uint EXPIRE;
public uint MINIMUM;
public RecordSOA(RecordReader rr)
{
MNAME = rr.ReadDomainName();
RNAME = rr.ReadDomainName();
SERIAL = rr.ReadUInt32();
REFRESH = rr.ReadUInt32();
RETRY = rr.ReadUInt32();
EXPIRE = rr.ReadUInt32();
MINIMUM = rr.ReadUInt32();
}
public override string ToString()
{
return string.Format("{0} {1} {2} {3} {4} {5} {6}",
MNAME,
RNAME,
SERIAL,
REFRESH,
RETRY,
EXPIRE,
MINIMUM);
}
}
}

View file

@ -0,0 +1,93 @@
using System;
/*
* http://www.ietf.org/rfc/rfc2782.txt
*
Priority
The priority of this target host. A client MUST attempt to
contact the target host with the lowest-numbered priority it can
reach; target hosts with the same priority SHOULD be tried in an
order defined by the weight field. The range is 0-65535. This
is a 16 bit unsigned integer in network byte order.
Weight
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. The range of this number is 0-65535. This is a
16 bit unsigned integer in network byte order. Domain
administrators SHOULD use Weight 0 when there isn't any server
selection to do, to make the RR easier to read for humans (less
noisy). In the presence of records containing weights greater
than 0, records with weight 0 should have a very small chance of
being selected.
In the absence of a protocol whose specification calls for the
use of other weighting information, a client arranges the SRV
RRs of the same Priority in the order in which target hosts,
specified by the SRV RRs, will be contacted. The following
algorithm SHOULD be used to order the SRV RRs of the same
priority:
To select a target to be contacted next, arrange all SRV RRs
(that have not been ordered yet) in any order, except that all
those with weight 0 are placed at the beginning of the list.
Compute the sum of the weights of those RRs, and with each RR
associate the running sum in the selected order. Then choose a
uniform random number between 0 and the sum computed
(inclusive), and select the RR whose running sum value is the
first in the selected order which is greater than or equal to
the random number selected. The target host specified in the
selected SRV RR is the next one to be contacted by the client.
Remove this SRV RR from the set of the unordered SRV RRs and
apply the described algorithm to the unordered SRV RRs to select
the next target host. Continue the ordering process until there
are no unordered SRV RRs. This process is repeated for each
Priority.
Port
The port on this target host of this service. The range is 0-
65535. This is a 16 bit unsigned integer in network byte order.
This is often as specified in Assigned Numbers but need not be.
Target
The domain name of the target host. There MUST be one or more
address records for this name, the name MUST NOT be an alias (in
the sense of RFC 1034 or RFC 2181). Implementors are urged, but
not required, to return the address record(s) in the Additional
Data section. Unless and until permitted by future standards
action, name compression is not to be used for this field.
A Target of "." means that the service is decidedly not
available at this domain.
*/
namespace Heijden.DNS
{
public class RecordSRV : Record
{
public ushort PRIORITY;
public ushort WEIGHT;
public ushort PORT;
public string TARGET;
public RecordSRV(RecordReader rr)
{
PRIORITY = rr.ReadUInt16();
WEIGHT = rr.ReadUInt16();
PORT = rr.ReadUInt16();
TARGET = rr.ReadDomainName();
}
public override string ToString()
{
return string.Format("{0} {1} {2} {3}",
PRIORITY,
WEIGHT,
PORT,
TARGET);
}
}
}

View file

@ -0,0 +1,62 @@
using System;
/*
* http://tools.ietf.org/rfc/rfc2930.txt
*
2. The TKEY Resource Record
The TKEY resource record (RR) has the structure given below. Its RR
type code is 249.
Field Type Comment
----- ---- -------
Algorithm: domain
Inception: u_int32_t
Expiration: u_int32_t
Mode: u_int16_t
Error: u_int16_t
Key Size: u_int16_t
Key Data: octet-stream
Other Size: u_int16_t
Other Data: octet-stream undefined by this specification
*/
namespace Heijden.DNS
{
public class RecordTKEY : Record
{
public string ALGORITHM;
public UInt32 INCEPTION;
public UInt32 EXPIRATION;
public UInt16 MODE;
public UInt16 ERROR;
public UInt16 KEYSIZE;
public byte[] KEYDATA;
public UInt16 OTHERSIZE;
public byte[] OTHERDATA;
public RecordTKEY(RecordReader rr)
{
ALGORITHM = rr.ReadDomainName();
INCEPTION = rr.ReadUInt32();
EXPIRATION = rr.ReadUInt32();
MODE = rr.ReadUInt16();
ERROR = rr.ReadUInt16();
KEYSIZE = rr.ReadUInt16();
KEYDATA = rr.ReadBytes(KEYSIZE);
OTHERSIZE = rr.ReadUInt16();
OTHERDATA = rr.ReadBytes(OTHERSIZE);
}
public override string ToString()
{
return string.Format("{0} {1} {2} {3} {4}",
ALGORITHM,
INCEPTION,
EXPIRATION,
MODE,
ERROR);
}
}
}

View file

@ -0,0 +1,64 @@
using System;
/*
* http://www.ietf.org/rfc/rfc2845.txt
*
* Field Name Data Type Notes
--------------------------------------------------------------
Algorithm Name domain-name Name of the algorithm
in domain name syntax.
Time Signed u_int48_t seconds since 1-Jan-70 UTC.
Fudge u_int16_t seconds of error permitted
in Time Signed.
MAC Size u_int16_t number of octets in MAC.
MAC octet stream defined by Algorithm Name.
Original ID u_int16_t original message ID
Error u_int16_t expanded RCODE covering
TSIG processing.
Other Len u_int16_t length, in octets, of
Other Data.
Other Data octet stream empty unless Error == BADTIME
*/
namespace Heijden.DNS
{
public class RecordTSIG : Record
{
public string ALGORITHMNAME;
public long TIMESIGNED;
public UInt16 FUDGE;
public UInt16 MACSIZE;
public byte[] MAC;
public UInt16 ORIGINALID;
public UInt16 ERROR;
public UInt16 OTHERLEN;
public byte[] OTHERDATA;
public RecordTSIG(RecordReader rr)
{
ALGORITHMNAME = rr.ReadDomainName();
TIMESIGNED = rr.ReadUInt32() << 32 | rr.ReadUInt32();
FUDGE = rr.ReadUInt16();
MACSIZE = rr.ReadUInt16();
MAC = rr.ReadBytes(MACSIZE);
ORIGINALID = rr.ReadUInt16();
ERROR = rr.ReadUInt16();
OTHERLEN = rr.ReadUInt16();
OTHERDATA = rr.ReadBytes(OTHERLEN);
}
public override string ToString()
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddSeconds(TIMESIGNED);
string printDate = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString();
return string.Format("{0} {1} {2} {3} {4}",
ALGORITHMNAME,
printDate,
FUDGE,
ORIGINALID,
ERROR);
}
}
}

View file

@ -0,0 +1,38 @@
using System;
#region Rfc info
/*
3.3.14. TXT RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ TXT-DATA /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
TXT-DATA One or more <character-string>s.
TXT RRs are used to hold descriptive text. The semantics of the text
depends on the domain where it is found.
*
*/
#endregion
namespace Heijden.DNS
{
public class RecordTXT : Record
{
public string TXT;
public RecordTXT(RecordReader rr)
{
TXT = rr.ReadString();
}
public override string ToString()
{
return string.Format("\"{0}\"",TXT);
}
}
}

View file

@ -0,0 +1,75 @@
using System;
/*
* 3.4.2. WKS RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ADDRESS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PROTOCOL | |
+--+--+--+--+--+--+--+--+ |
| |
/ <BIT MAP> /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
ADDRESS An 32 bit Internet address
PROTOCOL An 8 bit IP protocol number
<BIT MAP> A variable length bit map. The bit map must be a
multiple of 8 bits long.
The WKS record is used to describe the well known services supported by
a particular protocol on a particular internet address. The PROTOCOL
field specifies an IP protocol number, and the bit map has one bit per
port of the specified protocol. The first bit corresponds to port 0,
the second to port 1, etc. If the bit map does not include a bit for a
protocol of interest, that bit is assumed zero. The appropriate values
and mnemonics for ports and protocols are specified in [RFC-1010].
For example, if PROTOCOL=TCP (6), the 26th bit corresponds to TCP port
25 (SMTP). If this bit is set, a SMTP server should be listening on TCP
port 25; if zero, SMTP service is not supported on the specified
address.
The purpose of WKS RRs is to provide availability information for
servers for TCP and UDP. If a server supports both TCP and UDP, or has
multiple Internet addresses, then multiple WKS RRs are used.
WKS RRs cause no additional section processing.
In master files, both ports and protocols are expressed using mnemonics
or decimal numbers.
*/
namespace Heijden.DNS
{
public class RecordWKS : Record
{
public string ADDRESS;
public int PROTOCOL;
public byte[] BITMAP;
public RecordWKS(RecordReader rr)
{
ushort length = rr.ReadUInt16(-2);
ADDRESS = string.Format("{0}.{1}.{2}.{3}",
rr.ReadByte(),
rr.ReadByte(),
rr.ReadByte(),
rr.ReadByte());
PROTOCOL = (int)rr.ReadByte();
length -= 5;
BITMAP = new byte[length];
BITMAP = rr.ReadBytes(length);
}
public override string ToString()
{
return string.Format("{0} {1}",ADDRESS,PROTOCOL);
}
}
}

View file

@ -0,0 +1,51 @@
using System;
/* http://tools.ietf.org/rfc/rfc1183.txt
3.1. The X25 RR
The X25 RR is defined with mnemonic X25 and type code 19 (decimal).
X25 has the following format:
<owner> <ttl> <class> X25 <PSDN-address>
<PSDN-address> is required in all X25 RRs.
<PSDN-address> identifies the PSDN (Public Switched Data Network)
address in the X.121 [10] numbering plan associated with <owner>.
Its format in master files is a <character-string> syntactically
identical to that used in TXT and HINFO.
The format of X25 is class insensitive. X25 RRs cause no additional
section processing.
The <PSDN-address> is a string of decimal digits, beginning with the
4 digit DNIC (Data Network Identification Code), as specified in
X.121. National prefixes (such as a 0) MUST NOT be used.
For example:
Relay.Prime.COM. X25 311061700956
*/
namespace Heijden.DNS
{
public class RecordX25 : Record
{
public string PSDNADDRESS;
public RecordX25(RecordReader rr)
{
PSDNADDRESS = rr.ReadString();
}
public override string ToString()
{
return string.Format("{0}",
PSDNADDRESS);
}
}
}

View file

@ -1,68 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
public sealed class RpRecord : DnsRecordBase
{
// For RP
private string _name;
private string _textLocation;
public string RpName
{
get { return _name; }
}
public string TextLocation
{
get { return _textLocation; }
}
internal RpRecord(RecordHeader dnsHeader) : base(dnsHeader) {}
public override void ParseRecord(ref MemoryStream ms)
{
_name = DnsRecordBase.ParseName(ref ms);
_textLocation = DnsRecordBase.ParseName(ref ms);
_answer = _name + ", " + _textLocation;
}
}
}

View file

@ -1,71 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace DnDns.Records
{
public sealed class RtRecord : DnsRecordBase
{
private ushort _preference;
private string _intermediateHost;
public ushort Preference
{
get { return _preference; }
}
public string IntermediateHost
{
get { return _intermediateHost; }
}
internal RtRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
byte[] preference = new byte[2];
ms.Read(preference, 0, 2);
//_preference = (ushort)Tools.ByteToUInt(preference);
_preference = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(preference, 0));
_intermediateHost = DnsRecordBase.ParseName(ref ms);
_answer = "Preference: " + _preference + ", Intermediate Host: " + _intermediateHost;
}
}
}

View file

@ -1,160 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace DnDns.Records
{
public sealed class SoaRecord : DnsRecordBase
{
// For SOA
#region fields
private string _primaryNameServer;
private string _responsiblePerson;
private uint _serial;
private uint _refreshInterval;
private uint _retryInterval;
private uint _expirationLimit;
// RFC 1034: TTL - only positive values of a signed 32 bit number.
private int _minimumTimeToLive;
#endregion
#region properties
public string PrimaryNameServer
{
get { return _primaryNameServer; }
}
public string ResponsiblePerson
{
get { return _responsiblePerson; }
}
public uint Serial
{
get { return _serial; }
}
public uint RefreshInterval
{
get { return _refreshInterval; }
}
public uint RetryInterval
{
get { return _retryInterval; }
}
public uint ExpirationLimit
{
get { return _expirationLimit; }
}
public int MinimumTimeToLive
{
get { return _minimumTimeToLive; }
}
#endregion
internal SoaRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
StringBuilder sb = new StringBuilder();
// Parse Name
_primaryNameServer = DnsRecordBase.ParseName(ref ms);
sb.Append("Primary NameServer: ");
sb.Append(_primaryNameServer);
sb.Append("\r\n");
// Parse Responsible Persons Mailbox (Parse Name)
_responsiblePerson = DnsRecordBase.ParseName(ref ms);
sb.Append("Responsible Person: ");
sb.Append(_responsiblePerson);
sb.Append("\r\n");
byte[] serial = new Byte[4];
byte[] refreshInterval = new Byte[4];
byte[] retryInterval = new Byte[4];
byte[] expirationLimit = new Byte[4];
byte[] minTTL = new Byte[4];
// Parse Serial (4 bytes)
ms.Read(serial, 0, 4);
//_serial = Tools.ByteToUInt(serial);
_serial = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(serial, 0));
sb.Append("Serial: ");
sb.Append(_serial);
sb.Append("\r\n");
// Parse Refresh Interval (4 bytes)
ms.Read(refreshInterval, 0, 4);
// _refreshInterval = Tools.ByteToUInt(refreshInterval);
_refreshInterval = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(refreshInterval, 0));
sb.Append("Refresh Interval: ");
sb.Append(_refreshInterval);
sb.Append("\r\n");
// Parse Retry Interval (4 bytes)
ms.Read(retryInterval, 0, 4);
//_retryInterval = Tools.ByteToUInt(retryInterval);
_retryInterval = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(retryInterval, 0));
sb.Append("Retry Interval: ");
sb.Append(_retryInterval);
sb.Append("\r\n");
// Parse Expiration limit (4 bytes)
ms.Read(expirationLimit, 0, 4);
// _expirationLimit = Tools.ByteToUInt(expirationLimit);
_expirationLimit = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(expirationLimit, 0));
sb.Append("Expire: ");
sb.Append(_expirationLimit);
sb.Append("\r\n");
// Parse Min TTL (4 bytes)
ms.Read(minTTL, 0, 4);
// _minTTL = Tools.ByteToUInt(minTTL);
_minimumTimeToLive = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(minTTL, 0));
sb.Append("TTL: ");
sb.Append(_minimumTimeToLive);
sb.Append("\r\n");
_answer = sb.ToString();
}
}
}

View file

@ -1,95 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace DnDns.Records
{
public sealed class SrvRecord : DnsRecordBase
{
// For SRV
private ushort _priority;
private ushort _weight;
private ushort _port;
private string _hostName;
public ushort Priority
{
get { return _priority; }
}
public ushort Weight
{
get { return _weight; }
}
public ushort Port
{
get { return _port; }
}
public string HostName
{
get { return _hostName; }
}
internal SrvRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
byte[] priority = new byte[2];
ms.Read(priority, 0, 2);
//_priority = (ushort)Tools.ByteToUInt(Priority);
_priority = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(priority, 0));
byte[] weight = new byte[2];
ms.Read(weight, 0, 2);
// _weight = (ushort)Tools.ByteToUInt(Weight);
_weight = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(weight, 0));
byte[] port = new byte[2];
ms.Read(port, 0, 2);
//_port = (ushort)Tools.ByteToUInt(port);
_port = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(port, 0));
_hostName = DnsRecordBase.ParseName(ref ms);
_answer = "Service Location: \r\nPriority: " + _priority + "\r\nWeight: " +
_weight + "\r\nPort: " + _port + "\r\nHostName: " + _hostName + "\r\n";
}
}
}

View file

@ -1,235 +0,0 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using DnDns.Enums;
namespace DnDns.Records
{
/// <summary>
/// Implementation of a TSIG record structure as per RFC 2845
/// </summary>
public sealed class TSigRecord : DnsRecordBase
{
private string _algorithmName;
private RCode _error;
private ushort _fudge;
private ushort _originalId;
private byte[] _otherData;
private byte[] _mac;
private DateTime _timeSigned;
public string AlgorithmName
{
get { return _algorithmName; }
}
public RCode Error
{
get { return _error; }
}
public ushort Fudge
{
get { return _fudge; }
}
public ushort OriginalID
{
get { return _originalId; }
}
public byte[] OtherData
{
get { return _otherData; }
}
public byte[] Mac
{
get { return _mac; }
}
public DateTime TimeSigned
{
get { return _timeSigned; }
}
public TSigRecord(RecordHeader dnsHeader) : base(dnsHeader)
{
}
public TSigRecord(string name, string algorithmName, RCode error, ushort fudge, ushort originalId, byte[] otherData, byte[] mac, DateTime timeSigned)
{
DnsHeader = new RecordHeader(name, NsType.TSIG, NsClass.ANY, 0);
_algorithmName = algorithmName;
_error = error;
_fudge = fudge;
_originalId = originalId;
_otherData = otherData;
_mac = mac;
_timeSigned = timeSigned;
if(otherData == null)
{
_otherData = new byte[]{};
}
}
public override void ParseRecord(ref MemoryStream memoryStream)
{
Byte[] dataUInt16 = new byte[2];
Byte[] dataUInt32 = new byte[4];
_algorithmName = ParseName(ref memoryStream);
memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
long timeHigh = (ushort) IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
memoryStream.Read(dataUInt32, 0, dataUInt32.Length);
long timeLow = (uint) IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(dataUInt32, 0));
_timeSigned = DnsHelpers.ConvertFromDnsTime(timeLow, timeHigh);
memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
_fudge = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
Int32 macLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
_mac = new byte[macLen];
memoryStream.Read(_mac, 0, macLen);
memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
_originalId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
_error = (RCode)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
Int32 otherLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
if(otherLen > 0)
{
_otherData = new byte[otherLen];
memoryStream.Read(_otherData, 0, otherLen);
}
else
{
_otherData = null;
}
_answer = ToString();
}
public override byte[] GetMessageBytes()
{
MemoryStream memoryStream = new MemoryStream();
byte[] data = DnsHeader.GetMessageBytes();
memoryStream.Write(data,0,data.Length);
long rLengthPosition = memoryStream.Position;
data = DnsHelpers.CanonicaliseDnsName(_algorithmName, false);
memoryStream.Write(data, 0, data.Length);
int timeHigh;
long timeLow;
DnsHelpers.ConvertToDnsTime(_timeSigned.ToUniversalTime(), out timeHigh, out timeLow);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)timeHigh) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((uint)(IPAddress.HostToNetworkOrder((uint)timeLow) >> 32));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_fudge) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_mac.Length) >> 16));
memoryStream.Write(data, 0, data.Length);
memoryStream.Write(_mac, 0, _mac.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder(_originalId) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_error) >> 16));
memoryStream.Write(data, 0, data.Length);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)_otherData.Length) >> 16));
memoryStream.Write(data, 0, data.Length);
if(_otherData.Length != 0)
{
memoryStream.Write(_otherData, 0, _otherData.Length);
}
// Add the rdata lenght
long rlength = memoryStream.Position - rLengthPosition;
memoryStream.Seek(rLengthPosition - 2, SeekOrigin.Begin);
data = BitConverter.GetBytes((ushort)(IPAddress.HostToNetworkOrder((ushort)rlength) >> 16));
memoryStream.Write(data, 0, data.Length);
return memoryStream.ToArray();
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append(_algorithmName);
sb.Append(" ");
sb.Append(_timeSigned);
sb.Append(" ");
sb.Append(_fudge);
sb.Append(" ");
sb.Append(_mac.Length);
sb.Append(" ");
sb.Append(Convert.ToBase64String(Mac));
sb.Append(" ");
sb.Append(_error);
sb.Append(" ");
if (_otherData == null)
{
sb.Append(0);
}
else
{
sb.Append(_otherData.Length);
sb.Append(" ");
if (_error == RCode.BADTIME)
{
if (_otherData.Length != 6)
{
sb.Append("<invalid BADTIME other data>");
}
else
{
long time = ((long)(_otherData[0] & 0xFF) << 40) +
((long)(_otherData[1] & 0xFF) << 32) +
((_otherData[2] & 0xFF) << 24) +
((_otherData[3] & 0xFF) << 16) +
((_otherData[4] & 0xFF) << 8) +
((_otherData[5] & 0xFF));
sb.Append("<server time: ");
sb.Append(DnsHelpers.ConvertFromDnsTime(time));
sb.Append(">");
}
}
else
{
sb.Append("<");
sb.Append(Convert.ToBase64String(_otherData));
sb.Append(">");
}
}
return sb.ToString();
}
}
}

View file

@ -1,63 +0,0 @@
/**********************************************************************
* Copyright (c) 2010, j. montgomery *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* + Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* + Redistributions in binary form must reproduce the above copyright*
* notice, this list of conditions and the following disclaimer *
* in the documentation and/or other materials provided with the *
* distribution. *
* *
* + Neither the name of j. montgomery's employer nor the names of *
* its contributors may be used to endorse or promote products *
* derived from this software without specific prior written *
* permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
* OF THE POSSIBILITY OF SUCH DAMAGE. *
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DnDns.Records
{
/// <summary>
///
/// </summary>
public sealed class TxtRecord : DnsRecordBase
{
private string _text;
public string Text
{
get { return _text; }
}
internal TxtRecord(RecordHeader dnsHeader) : base(dnsHeader) { }
public override void ParseRecord(ref MemoryStream ms)
{
_text = base.ParseText(ref ms);
_answer = "text: " + _text;
}
}
}

Some files were not shown because too many files have changed in this diff Show more