diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index b4df8d82..66f79230 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -123,46 +123,75 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -229,6 +258,7 @@ + diff --git a/MinecraftClient/Protocol/Dns/DnsHelpers.cs b/MinecraftClient/Protocol/Dns/DnsHelpers.cs deleted file mode 100644 index 61c7e4a5..00000000 --- a/MinecraftClient/Protocol/Dns/DnsHelpers.cs +++ /dev/null @@ -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(); - } - - /// - /// Converts a instance of a class to a 48 bit format time since epoch. - /// Epoch is defined as 1-Jan-70 UTC. - /// - /// The instance to convert to DNS format. - /// The upper 16 bits of time. - /// The lower 32 bits of the time object. - 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)); - } - - /// - /// Convert from DNS 48 but time format to a instance. - /// - /// The upper 16 bits of time. - /// The lower 32 bits of the time object. - /// The converted date time - internal static DateTime ConvertFromDnsTime(long timeLow, long timeHigh) - { - long time = (timeHigh << 32) + timeLow; - time = time*10000000; - time += Epoch; - - return new DateTime(time); - } - - /// - /// Convert from DNS 48 but time format to a instance. - /// - /// The upper 48 bits of time. - /// The converted date time - internal static DateTime ConvertFromDnsTime(long dnsTime) - { - dnsTime = dnsTime * 10000000; - dnsTime += Epoch; - - return new DateTime(dnsTime); - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Enums/NsClass.cs b/MinecraftClient/Protocol/Dns/Enums/NsClass.cs deleted file mode 100644 index ed1e2c49..00000000 --- a/MinecraftClient/Protocol/Dns/Enums/NsClass.cs +++ /dev/null @@ -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 -{ - /// - /// 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 - /// - public enum NsClass : byte - { - /// - /// Cookie?? - NOT IMPLEMENTED - /// - INVALID = 0, - /// - /// // Internet (inet), RFC 1035 - /// - INET = 1, - /// - /// MIT Chaos-net, RFC 1035 - NOT IMPLEMENTED - /// - CHAOS = 3, - /// - /// MIT Hesiod, RFC 1035 - NOT IMPLEMENTED - /// - HS = 4, - /// - /// RFC 2136 - None - /// prereq sections in update requests -- NOT IMPLEMENTED - /// - NONE = 254, - /// - /// Any QCLASS only, Wildcard match, RFC 1035 - IMPLEMENTED for INET only - /// - ANY = 255 - } -} diff --git a/MinecraftClient/Protocol/Dns/Enums/NsFlags.cs b/MinecraftClient/Protocol/Dns/Enums/NsFlags.cs deleted file mode 100644 index f66553f4..00000000 --- a/MinecraftClient/Protocol/Dns/Enums/NsFlags.cs +++ /dev/null @@ -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 | - // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ - - /// - /// FlagMasks are used as a bitmask to isolate bits 16 through 31 of the DNS header to convert - /// them to their appropriate Enum types - /// - internal enum FlagMasks : ushort - { - QueryResponseMask = 0x8000, - OpCodeMask = 0x7800, - NsFlagMask = 0x07F0, - RCodeMask = 0x000F - } - - /// - /// |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). - /// - /// - [Flags()] - public enum QueryResponse : ushort - { - /// - /// // QR Query or Response [RFC1035] ( 0 = Query ) - /// - Query = 0x0, - /// - /// // QR Query or Response [RFC1035] ( 1 = Response ) - /// - Response = 0x8000 - } - - /// - /// | 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 - /// - [Flags()] - public enum OpCode : ushort - { - /// - /// Standard query - /// [RFC1035] (QUERY) - /// - QUERY = 0x0000, - /// - /// Inverse query - /// [RFC1035] (IQUERY) - /// - IQUERY = 0x0800, - /// - /// Server status request - /// [RFC1035] (STATUS) - /// - STATUS = 0x1000, - } - - /// - /// |AA|TC|RD|RA| Z|AD|CD| - 8 bits (1 byte) flag fields - /// - /// reference: http://www.networksorcery.com/enp/protocol/dns.htm - /// - [Flags()] - public enum NsFlags : ushort - { - /// - /// 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. - /// - AA = 0x0400, - /// - /// 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. - /// - TC = 0x0200, - /// - /// 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. - /// - RD = 0x0100, - /// - /// 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. - /// - RA = 0x0080, - /// - /// 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. - /// - AD = 0x0020, - /// - /// CD - Checking Disabled [RFC4035] ( Checking Disabled. 1 bit ) [NOT IMPLEMENTED] - /// - CD = 0x0010 - } - - /// - /// | 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 - /// - [Flags()] - public enum RCode : ushort - { - /// - /// No error condition - /// - NoError = 0, - /// - /// Format error - The name server was unable to - /// interpret the query. - /// - FormatError = 1, - /// - /// Server failure - The name server was unable to process - /// this query due to a problem with the name server. - /// - ServerFailure = 2, - /// - /// 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. - /// - NameError = 3, - /// - /// Not Implemented - The name server does not support - /// the requested kind of query. - /// - NotImplemented = 4, - /// - /// 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. - /// - Refused = 5, - /// - /// RFC 2136 - /// Name Exists when it should not. - /// - YXDomain = 6, - /// - /// RFC 2136 - /// RR Set Exists when it should not. - /// - YXRRSet = 7, - /// - /// RFC 2136 - /// RR Set that should exist does not. - /// - NXRRSet = 8, - /// - /// RFC 2136 - /// Server Not Authoritative for zone. - /// - NotAuth = 9, - /// - /// RFC 2136 - /// Name not contained in zone. - /// - NotZone = 10, - /// - /// RFC 2671 - /// RFC 2845 - /// - /// BADVERS Bad OPT Version. - /// BADSIG TSIG Signature Failure. - /// - BADVERS_BADSIG = 16, - /// - /// RFC 2845 - /// Key not recognized. - /// - BADKEY = 17, - /// - /// RFC 2845 - /// Signature out of time window. - /// - BADTIME = 18, - /// - /// RFC 2930 - /// Bad TKEY Mode. - /// - BADMODE = 19, - /// - /// RFC 2930 - /// Duplicate key name. - /// - BADNAME = 20, - /// - /// RFC 2930 - /// Algorithm not supported. - /// - BADALG = 21 - } -} \ No newline at end of file diff --git a/MinecraftClient/Protocol/Dns/Enums/NsType.cs b/MinecraftClient/Protocol/Dns/Enums/NsType.cs deleted file mode 100644 index b97e9904..00000000 --- a/MinecraftClient/Protocol/Dns/Enums/NsType.cs +++ /dev/null @@ -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 -{ - /// - /// 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 - /// - /// - public enum NsType : uint - { - /// - /// Invalid - /// - INVALID = 0, - /// - /// Host address - /// - A = 1, - /// - /// Authoritative server - /// - NS = 2, - /// - /// Mail destination - NOT IMPLEMENTED - /// - MD = 3, - /// - /// Mail forwarder, NOT IMPLEMENTED - /// - MF = 4, - /// - /// Canonical name - /// - CNAME = 5, - /// - /// Start of authority zone - /// - SOA = 6, - // Mailbox domain name - MB = 7, - /// - /// Mail group member - /// - MG = 8, - /// - /// Mail rename name - /// - MR = 9, - /// - /// Null resource record - /// - NULL = 10, - /// - /// Well known service - /// - WKS = 11, - /// - /// Domain name pointer - /// - PTR = 12, - /// - /// Host information - /// - HINFO = 13, - /// - /// Mailbox information - /// - MINFO = 14, - /// - /// Mail routing information - /// - MX = 15, - /// - /// Text strings, RFC 1464 - /// - TXT = 16, - /// - /// Responsible person, RFC 1183, Implemented - /// - RP = 17, - /// - /// AFS cell database, RFC 1183, Implemented - /// - AFSDB = 18, - /// - /// X_25 calling address, RFC 1183, Implemented - /// - X25 = 19, - /// - /// ISDN calling address, RFC 1183, Implemented - /// - ISDN = 20, - /// - /// Router, RFC 1183, Implemented - /// - RT = 21, - /// - /// NSAP address, RFC 1706 - /// - NSAP = 22, - /// - /// Reverse NSAP lookup - deprecated by PTR ? - /// - NSAP_PTR = 23, - /// - /// Security signature, RFC 2535 - /// - SIG = 24, - /// - /// Security key, RFC 2535 - /// - KEY = 25, - /// - /// X.400 mail mapping, RFC ? - /// - PX = 26, - /// - /// Geographical position - withdrawn, RFC 1712 - /// - GPOS = 27, - /// - /// Ip6 Address, RFC 1886 -- Implemented - /// - AAAA = 28, - /// - /// Location Information, RFC 1876, Implemented - /// - LOC = 29, - /// - /// Next domain (security), RFC 2065 - /// - NXT = 30, - /// - /// Endpoint identifier,RFC ? - /// - EID = 31, - /// - /// Nimrod Locator, RFC ? - /// - NIMLOC = 32, - /// - /// Server Record, RFC 2052, Implemented - /// - SRV = 33, - /// - /// ATM Address, RFC ?, Implemented - /// - ATMA = 34, - /// - /// Naming Authority PoinTeR, RFC 2915 - /// - MAPTR = 35, - /// - /// Key Exchange, RFC 2230 - /// - KX = 36, - /// - /// Certification record, RFC 2538 - /// - CERT = 37, - /// - /// IPv6 address (deprecates AAAA), RFC 3226 - /// - A6 = 38, - /// - /// Non-terminal DNAME (for IPv6), RFC 2874 - /// - DNAME = 39, - /// - /// Kitchen sink (experimentatl), RFC ? - /// - SINK = 40, - /// - /// EDNS0 option (meta-RR), RFC 2671 - /// - OPT = 41, - /// - /// Transaction key, RFC 2930 - /// - TKEY = 249, - /// - /// Transaction signature, RFC 2845 - /// - TSIG = 250, - /// - /// Incremental zone transfer, RFC 1995 - /// - IXFR = 251, - /// - /// Transfer zone of authority, RFC 1035 - /// - AXFR = 252, - /// - /// Transfer mailbox records, RFC 1035 - /// - MAILB = 253, - /// - /// Transfer mail agent records, RFC 1035 - /// - MAILA = 254, - /// - /// All of the above, RFC 1035 - /// - ANY = 255, - /// - /// DNSSEC Trust Authorities - /// - DNSSECTrustAuthorities = 32768, - /// - /// DNSSEC Lookaside Validation, RFC4431 - /// - DNSSECLookasideValidation = 32769 - } -} \ No newline at end of file diff --git a/MinecraftClient/Protocol/Dns/Enums/TcpServices.cs b/MinecraftClient/Protocol/Dns/Enums/TcpServices.cs deleted file mode 100644 index c646f00a..00000000 --- a/MinecraftClient/Protocol/Dns/Enums/TcpServices.cs +++ /dev/null @@ -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 -{ - /// - /// Defines Well Known TCP Ports for Services - /// - public enum TcpServices : short - { - /// - /// Domain Name Server Port - /// - Domain = 53 - } -} diff --git a/MinecraftClient/Protocol/Dns/Enums/UdpServices.cs b/MinecraftClient/Protocol/Dns/Enums/UdpServices.cs deleted file mode 100644 index 0e57058a..00000000 --- a/MinecraftClient/Protocol/Dns/Enums/UdpServices.cs +++ /dev/null @@ -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 -{ - /// - /// Defines Well Known UDP Ports for Services - /// - public enum UdpServices : short - { - /// - /// Domain Name Server Protocol Port - /// - Domain = 53 - } -} diff --git a/MinecraftClient/Protocol/Dns/Header.cs b/MinecraftClient/Protocol/Dns/Header.cs new file mode 100644 index 00000000..ef52f609 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Header.cs @@ -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 + { + /// + /// An identifier assigned by the program + /// + public ushort ID; + + // internal flag + private ushort Flags; + + /// + /// the number of entries in the question section + /// + public ushort QDCOUNT; + + /// + /// the number of resource records in the answer section + /// + public ushort ANCOUNT; + + /// + /// the number of name server resource records in the authority records section + /// + public ushort NSCOUNT; + + /// + /// the number of resource records in the additional records section + /// + 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); + } + + /// + /// Represents the header as a byte array + /// + public byte[] Data + { + get + { + List data = new List(); + 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)); + } + + + /// + /// query (false), or a response (true) + /// + public bool QR + { + get + { + return GetBits(Flags, 15, 1) == 1; + } + set + { + Flags = SetBits(Flags, 15, 1, value); + } + } + + /// + /// Specifies kind of query + /// + public OPCode OPCODE + { + get + { + return (OPCode)GetBits(Flags, 11, 4); + } + set + { + Flags = SetBits(Flags, 11, 4, (ushort)value); + } + } + + /// + /// Authoritative Answer + /// + public bool AA + { + get + { + return GetBits(Flags, 10, 1) == 1; + } + set + { + Flags = SetBits(Flags, 10, 1, value); + } + } + + /// + /// TrunCation + /// + public bool TC + { + get + { + return GetBits(Flags, 9, 1) == 1; + } + set + { + Flags = SetBits(Flags, 9, 1, value); + } + } + + /// + /// Recursion Desired + /// + public bool RD + { + get + { + return GetBits(Flags, 8, 1) == 1; + } + set + { + Flags = SetBits(Flags, 8, 1, value); + } + } + + /// + /// Recursion Available + /// + public bool RA + { + get + { + return GetBits(Flags, 7, 1) == 1; + } + set + { + Flags = SetBits(Flags, 7, 1, value); + } + } + + /// + /// Reserved for future use + /// + public ushort Z + { + get + { + return GetBits(Flags, 4, 3); + } + set + { + Flags = SetBits(Flags, 4, 3, value); + } + } + + /// + /// Response code + /// + public RCode RCODE + { + get + { + return (RCode)GetBits(Flags, 0, 4); + } + set + { + Flags = SetBits(Flags, 0, 4, (ushort)value); + } + } + } +} diff --git a/MinecraftClient/Protocol/Dns/Query/DnsQueryBase.cs b/MinecraftClient/Protocol/Dns/Query/DnsQueryBase.cs deleted file mode 100644 index a70ebde2..00000000 --- a/MinecraftClient/Protocol/Dns/Query/DnsQueryBase.cs +++ /dev/null @@ -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 -{ - /// - /// DnsQueryBase maintains the common state of DNS Queries (both responses and requests) - /// - 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 | - // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ - - /// - /// 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. - /// - protected ushort _transactionId; - /// - /// _flags will store a combination of the enums that make up the 16 bits after the - /// TransactionID in the DNS protocol header - /// - protected ushort _flags; - /// - /// A one bit field that specifies whether this message is a - /// query (0), or a response (1). - /// - protected QueryResponse _queryResponse; - /// - /// 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. - /// - protected OpCode _opCode; - /// - /// - A combination of flag fields in the DNS header (|AA|TC|RD|RA|) - /// - protected NsFlags _nsFlags; - /// - /// Response code - this 4 bit field is set as part of - /// responses only. - /// - protected RCode _rCode; - /// - /// QDCOUNT - an unsigned 16 bit integer specifying the number of - /// entries in the question section. - /// - protected ushort _questions; - /// - /// ANCOUNT - an unsigned 16 bit integer specifying the number of - /// resource records in the answer section. - /// - protected ushort _answerRRs; - /// - /// NSCOUNT - an unsigned 16 bit integer specifying the number of name - /// server resource records in the authority records - /// section. - /// - 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 | - // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ - - /// - /// 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 - /// - protected string _name; - /// - /// 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. - /// - protected NsType _nsType; - /// - /// QCLASS - a two octet code that specifies the class of the query. - /// For example, the QCLASS field is IN for the Internet. - /// - protected NsClass _nsClass; - - /// - /// The additional records for the DNS Query - /// - protected List _additionalRecords = new List(); - - #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. - /// - public ushort TransactionID - { - get { return _transactionId; } - } - - /// - /// A one bit field that specifies whether this message is a - /// query (0), or a response (1). - /// - public QueryResponse QueryResponse - { - get { return _queryResponse; } - } - - /// - /// 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. - /// - public OpCode OpCode - { - get { return _opCode; } - } - - /// - /// NsFlags - A combination of flag fields in the DNS header (|AA|TC|RD|RA|) - /// - public NsFlags NsFlags - { - get { return _nsFlags; } - } - - /// - /// Response code - this 4 bit field is set as part of - /// responses only. - /// - public RCode RCode - { - get { return _rCode; } - } - - /// - /// QDCOUNT - an unsigned 16 bit integer specifying the number of - /// entries in the question section. - /// - public ushort Questions - { - get { return _questions; } - } - - /// - /// ANCOUNT - an unsigned 16 bit integer specifying the number of - /// resource records in the answer section. - /// - public ushort AnswerRRs - { - get { return _answerRRs; } - } - - /// - /// NSCOUNT - an unsigned 16 bit integer specifying the number of name - /// server resource records in the authority records - /// section. - /// - public ushort AuthorityRRs - { - get { return _authorityRRs; } - } - - /// - /// ARCOUNT - an unsigned 16 bit integer specifying the number of - /// resource records in the additional records section. - /// - public ushort AdditionalRRs - { - get { return (ushort) _additionalRecords.Count; } - } - - /// - /// 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 - /// - public string Name - { - get { return _name; } - set { _name = value; } - } - - /// - /// 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. - /// - public NsType NsType - { - get { return _nsType; } - set { _nsType = value; } - } - - /// - /// QCLASS - a two octet code that specifies the class of the query. - /// For example, the QCLASS field is IN for the Internet. - /// - public NsClass NsClass - { - get { return _nsClass; } - set { _nsClass = value; } - } - - public List AdditionalRRecords - { - get { return _additionalRecords; } - } - #endregion - } -} diff --git a/MinecraftClient/Protocol/Dns/Query/DnsQueryRequest.cs b/MinecraftClient/Protocol/Dns/Query/DnsQueryRequest.cs deleted file mode 100644 index f781111f..00000000 --- a/MinecraftClient/Protocol/Dns/Query/DnsQueryRequest.cs +++ /dev/null @@ -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 description for DnsQueryRequest. - /// - public class DnsQueryRequest : DnsQueryBase - { - private static Random r = new Random(); - - private DnsPermission _dnsPermissions; - - private int _bytesSent = 0; - private int _socketTimeout = 5000; - - /// - /// The number of bytes sent to query the DNS Server. - /// - public int BytesSent - { - get { return _bytesSent; } - } - - /// - /// 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) - /// - 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(); - } - - /// - /// - /// - /// - /// - /// - /// - /// - 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); - - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// The instance of the message security provider to use to secure the DNS request. - /// A instance that contains the Dns Answer for the request query. - /// - /// - /// - 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(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(); - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Query/DnsQueryResponse.cs b/MinecraftClient/Protocol/Dns/Query/DnsQueryResponse.cs deleted file mode 100644 index 7332e84e..00000000 --- a/MinecraftClient/Protocol/Dns/Query/DnsQueryResponse.cs +++ /dev/null @@ -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 description for DnsQueryResponse. - /// - 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 - - /// - /// - /// - 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(); - _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)); - } - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Question.cs b/MinecraftClient/Protocol/Dns/Question.cs new file mode 100644 index 00000000..8fa574d7 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Question.cs @@ -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 data = new List(); + 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); + } + } +} diff --git a/MinecraftClient/Protocol/Dns/RR.cs b/MinecraftClient/Protocol/Dns/RR.cs new file mode 100644 index 00000000..dbddfc5d --- /dev/null +++ b/MinecraftClient/Protocol/Dns/RR.cs @@ -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 + + /// + /// Resource Record (rfc1034 3.6.) + /// + public class RR + { + /// + /// The name of the node to which this resource record pertains + /// + public string NAME; + + /// + /// Specifies type of resource record + /// + public Type Type; + + /// + /// Specifies type class of resource record, mostly IN but can be CS, CH or HS + /// + public Class Class; + + /// + /// Time to live, the time interval that the resource record may be cached + /// + public uint TTL + { + get + { + return (uint)Math.Max(0, m_TTL - TimeLived); + } + set + { + m_TTL = value; + } + } + private uint m_TTL; + + /// + /// + /// + public ushort RDLENGTH; + + /// + /// One of the Record* classes + /// + 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) + { + } + } +} diff --git a/MinecraftClient/Protocol/Dns/RecordReader.cs b/MinecraftClient/Protocol/Dns/RecordReader.cs new file mode 100644 index 00000000..07f4cf12 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/RecordReader.cs @@ -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 list = new List(); + for(int intI=0;intI - /// 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"). - /// - /// - public sealed class ARecord : DnsRecordBase, IDnsRecord - { - private string _hostAddress; - - /// - /// The answer host address for the DNS A Record. - /// - 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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/AaaaRecord.cs b/MinecraftClient/Protocol/Dns/Records/AaaaRecord.cs deleted file mode 100644 index dc592f3f..00000000 --- a/MinecraftClient/Protocol/Dns/Records/AaaaRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/AfsdbRecord.cs b/MinecraftClient/Protocol/Dns/Records/AfsdbRecord.cs deleted file mode 100644 index d92a5208..00000000 --- a/MinecraftClient/Protocol/Dns/Records/AfsdbRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/AtmaRecord.cs b/MinecraftClient/Protocol/Dns/Records/AtmaRecord.cs deleted file mode 100644 index 58f51032..00000000 --- a/MinecraftClient/Protocol/Dns/Records/AtmaRecord.cs +++ /dev/null @@ -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 - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/BaseDnsRecord.cs b/MinecraftClient/Protocol/Dns/Records/BaseDnsRecord.cs deleted file mode 100644 index b0aec061..00000000 --- a/MinecraftClient/Protocol/Dns/Records/BaseDnsRecord.cs +++ /dev/null @@ -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 -{ - /// - /// 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. - /// - 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 - /// - /// NAME - an owner name, i.e., the name of the node to which this - /// resource record pertains. - /// - //public string Name - //{ - // get { return _name; } - //} - - public RecordHeader DnsHeader - { - get { return _dnsHeader; } - protected set { _dnsHeader = value; } - } - - public string Answer - { - get { return _answer; } - } - - - /// - /// TYPE two octets containing one of the RR TYPE codes. - /// - //public NsType NsType - //{ - // get { return _nsType; } - //} - - /// - /// CLASS - two octets containing one of the RR CLASS codes. - /// - //public NsClass NsClass - //{ - // get { return _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. - /// - //public int TimeToLive - //{ - // get { return _timeToLive; } - //} - - /// - /// RDLENGTH - an unsigned 16 bit integer that specifies the length in - /// octets of the RDATA field. - /// - //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 - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/CNameRecord.cs b/MinecraftClient/Protocol/Dns/Records/CNameRecord.cs deleted file mode 100644 index c7342371..00000000 --- a/MinecraftClient/Protocol/Dns/Records/CNameRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/HInfoRecord.cs b/MinecraftClient/Protocol/Dns/Records/HInfoRecord.cs deleted file mode 100644 index 24a18533..00000000 --- a/MinecraftClient/Protocol/Dns/Records/HInfoRecord.cs +++ /dev/null @@ -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; - } - } - -} diff --git a/MinecraftClient/Protocol/Dns/Records/IDnsRecord.cs b/MinecraftClient/Protocol/Dns/Records/IDnsRecord.cs deleted file mode 100644 index 7b979058..00000000 --- a/MinecraftClient/Protocol/Dns/Records/IDnsRecord.cs +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/MinecraftClient/Protocol/Dns/Records/IsdnRecord.cs b/MinecraftClient/Protocol/Dns/Records/IsdnRecord.cs deleted file mode 100644 index e5c46a9d..00000000 --- a/MinecraftClient/Protocol/Dns/Records/IsdnRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/LocRecord.cs b/MinecraftClient/Protocol/Dns/Records/LocRecord.cs deleted file mode 100644 index a8a0c2bd..00000000 --- a/MinecraftClient/Protocol/Dns/Records/LocRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/MInfoRecord.cs b/MinecraftClient/Protocol/Dns/Records/MInfoRecord.cs deleted file mode 100644 index 7ad5cab2..00000000 --- a/MinecraftClient/Protocol/Dns/Records/MInfoRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/MbRecord.cs b/MinecraftClient/Protocol/Dns/Records/MbRecord.cs deleted file mode 100644 index 80c0aba5..00000000 --- a/MinecraftClient/Protocol/Dns/Records/MbRecord.cs +++ /dev/null @@ -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); - //} - } - -} diff --git a/MinecraftClient/Protocol/Dns/Records/MgRecord.cs b/MinecraftClient/Protocol/Dns/Records/MgRecord.cs deleted file mode 100644 index 9b1b78a9..00000000 --- a/MinecraftClient/Protocol/Dns/Records/MgRecord.cs +++ /dev/null @@ -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); - //} - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/MrRecord.cs b/MinecraftClient/Protocol/Dns/Records/MrRecord.cs deleted file mode 100644 index 38ad481f..00000000 --- a/MinecraftClient/Protocol/Dns/Records/MrRecord.cs +++ /dev/null @@ -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); - //} - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/MxRecord.cs b/MinecraftClient/Protocol/Dns/Records/MxRecord.cs deleted file mode 100644 index 8eaae837..00000000 --- a/MinecraftClient/Protocol/Dns/Records/MxRecord.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordA6.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordA6.cs new file mode 100644 index 00000000..892598ac --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordA6.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordAPL.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordAPL.cs new file mode 100644 index 00000000..dfa4f208 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordAPL.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordATMA.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordATMA.cs new file mode 100644 index 00000000..5aca6669 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordATMA.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordCERT.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordCERT.cs new file mode 100644 index 00000000..0a0630a7 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordCERT.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordDHCID.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordDHCID.cs new file mode 100644 index 00000000..b7ba4922 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordDHCID.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordDNSKEY.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordDNSKEY.cs new file mode 100644 index 00000000..bbfe45e8 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordDNSKEY.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordEID.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordEID.cs new file mode 100644 index 00000000..e76bcb43 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordEID.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordGID.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordGID.cs new file mode 100644 index 00000000..bfe310a0 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordGID.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordHIP.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordHIP.cs new file mode 100644 index 00000000..24eec2df --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordHIP.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordIPSECKEY.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordIPSECKEY.cs new file mode 100644 index 00000000..17d8f1a4 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordIPSECKEY.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNIMLOC.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNIMLOC.cs new file mode 100644 index 00000000..46f93adc --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNIMLOC.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC.cs new file mode 100644 index 00000000..ad2f00c2 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC3.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC3.cs new file mode 100644 index 00000000..2da2e807 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC3.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC3PARAM.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC3PARAM.cs new file mode 100644 index 00000000..a761c39b --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordNSEC3PARAM.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordOPT.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordOPT.cs new file mode 100644 index 00000000..55f3d96d --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordOPT.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordRRSIG.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordRRSIG.cs new file mode 100644 index 00000000..ce001ace --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordRRSIG.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSINK.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSINK.cs new file mode 100644 index 00000000..c56c0f55 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSINK.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSPF.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSPF.cs new file mode 100644 index 00000000..655cb54b --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSPF.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSSHFP.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSSHFP.cs new file mode 100644 index 00000000..0e8a2678 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordSSHFP.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUID.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUID.cs new file mode 100644 index 00000000..00011aed --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUID.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUINFO.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUINFO.cs new file mode 100644 index 00000000..b75b7850 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUINFO.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUNSPEC.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUNSPEC.cs new file mode 100644 index 00000000..6afb8e1a --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUNSPEC.cs @@ -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"); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUnknown.cs b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUnknown.cs new file mode 100644 index 00000000..235c131e --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/NotUsed/RecordUnknown.cs @@ -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); + } + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/NsRecord.cs b/MinecraftClient/Protocol/Dns/Records/NsRecord.cs deleted file mode 100644 index 801d882d..00000000 --- a/MinecraftClient/Protocol/Dns/Records/NsRecord.cs +++ /dev/null @@ -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); - //} - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordGPOS.cs b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordGPOS.cs new file mode 100644 index 00000000..e300be88 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordGPOS.cs @@ -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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordMD.cs b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordMD.cs new file mode 100644 index 00000000..fe2979f6 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordMD.cs @@ -0,0 +1,41 @@ +using System; +/* +3.3.4. MD RDATA format (Obsolete) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / MADNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +MADNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordMF.cs b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordMF.cs new file mode 100644 index 00000000..fb2697c7 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordMF.cs @@ -0,0 +1,41 @@ +using System; +/* + * +3.3.5. MF RDATA format (Obsolete) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / MADNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +MADNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordNSAPPTR.cs b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordNSAPPTR.cs new file mode 100644 index 00000000..9025dd1c --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordNSAPPTR.cs @@ -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-PTR + + All fields are required. + + enumerates the actual octet values assigned by the + assigning authority for the LOCAL network. Its format in master + files is a 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 . + + */ + +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); + } + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordNXT.cs b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordNXT.cs new file mode 100644 index 00000000..bb98cf24 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/Obsolete/RecordNXT.cs @@ -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()); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/PtrRecord.cs b/MinecraftClient/Protocol/Dns/Records/PtrRecord.cs deleted file mode 100644 index 0cacbc48..00000000 --- a/MinecraftClient/Protocol/Dns/Records/PtrRecord.cs +++ /dev/null @@ -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); - //} - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/Record.cs b/MinecraftClient/Protocol/Dns/Records/Record.cs new file mode 100644 index 00000000..6e236388 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/Record.cs @@ -0,0 +1,12 @@ +// Stuff records are made of + +namespace Heijden.DNS +{ + public abstract class Record + { + /// + /// The Resource Record this RDATA record belongs to + /// + public RR RR; + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordA.cs b/MinecraftClient/Protocol/Dns/Records/RecordA.cs new file mode 100644 index 00000000..5eff6ba3 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordA.cs @@ -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(); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordAAAA.cs b/MinecraftClient/Protocol/Dns/Records/RecordAAAA.cs new file mode 100644 index 00000000..033ec038 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordAAAA.cs @@ -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(); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordAFSDB.cs b/MinecraftClient/Protocol/Dns/Records/RecordAFSDB.cs new file mode 100644 index 00000000..7bf16ed5 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordAFSDB.cs @@ -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: + + AFSDB + + Both RDATA fields are required in all AFSDB RRs. The field + is a 16 bit integer. The 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordCNAME.cs b/MinecraftClient/Protocol/Dns/Records/RecordCNAME.cs new file mode 100644 index 00000000..e791c38a --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordCNAME.cs @@ -0,0 +1,39 @@ +using System; +/* + * +3.3.1. CNAME RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / CNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +CNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordDNAME.cs b/MinecraftClient/Protocol/Dns/Records/RecordDNAME.cs new file mode 100644 index 00000000..cf4bb970 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordDNAME.cs @@ -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: + + DNAME + + The format is not class-sensitive. All fields are required. The + RDATA field is a [DNSIS]. + + * + */ +namespace Heijden.DNS +{ + public class RecordDNAME : Record + { + public string TARGET; + + public RecordDNAME(RecordReader rr) + { + TARGET = rr.ReadDomainName(); + } + + public override string ToString() + { + return TARGET; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordDS.cs b/MinecraftClient/Protocol/Dns/Records/RecordDS.cs new file mode 100644 index 00000000..1438b7c3 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordDS.cs @@ -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()); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordFactory.cs b/MinecraftClient/Protocol/Dns/Records/RecordFactory.cs deleted file mode 100644 index 75a9f269..00000000 --- a/MinecraftClient/Protocol/Dns/Records/RecordFactory.cs +++ /dev/null @@ -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; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordHINFO.cs b/MinecraftClient/Protocol/Dns/Records/RecordHINFO.cs new file mode 100644 index 00000000..0722bf1b --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordHINFO.cs @@ -0,0 +1,45 @@ +using System; + +/* + 3.3.2. HINFO RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / CPU / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / OS / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +CPU A which specifies the CPU type. + +OS A 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordHeader.cs b/MinecraftClient/Protocol/Dns/Records/RecordHeader.cs deleted file mode 100644 index 7c5c2c63..00000000 --- a/MinecraftClient/Protocol/Dns/Records/RecordHeader.cs +++ /dev/null @@ -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 -{ - /// - /// 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. - /// - /// - 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; - - /// - /// Initalise the - /// - /// The header name - /// The resource type - /// The class type - /// The time to live - public RecordHeader(string name, NsType nsType, NsClass nsClass, int timeToLive) - { - _name = name; - _nsType = nsType; - _nsClass = nsClass; - _timeToLive = timeToLive; - } - - public RecordHeader() - { - } - - #endregion - - #region Properties - /// - /// NAME - an owner name, i.e., the name of the node to which this - /// resource record pertains. - /// - public string Name - { - get { return _name; } - } - - /// - /// TYPE two octets containing one of the RR TYPE codes. - /// - public NsType NsType - { - get { return _nsType; } - } - - /// - /// CLASS - two octets containing one of the RR CLASS codes. - /// - public NsClass NsClass - { - get { return _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. - /// - public int TimeToLive - { - get { return _timeToLive; } - } - - /// - /// RDLENGTH - an unsigned 16 bit integer that specifies the length in - /// octets of the RDATA field. - /// - public short DataLength - { - get { return _dataLength; } - } - #endregion - - /// - /// - /// - /// - 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(); - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordISDN.cs b/MinecraftClient/Protocol/Dns/Records/RecordISDN.cs new file mode 100644 index 00000000..df4a1166 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordISDN.cs @@ -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: + + ISDN + + The field is required; is optional. + + identifies the ISDN number of 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 syntactically + identical to that used in TXT and HINFO. + + specifies the subaddress (SA). The format of in master + files is a syntactically identical to that used in + TXT and HINFO. + + The format of ISDN is class insensitive. ISDN RRs cause no + additional section processing. + + The 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 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 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordKEY.cs b/MinecraftClient/Protocol/Dns/Records/RecordKEY.cs new file mode 100644 index 00000000..8e0fc4b8 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordKEY.cs @@ -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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordKX.cs b/MinecraftClient/Protocol/Dns/Records/RecordKX.cs new file mode 100644 index 00000000..35de980b --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordKX.cs @@ -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 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordLOC.cs b/MinecraftClient/Protocol/Dns/Records/RecordLOC.cs new file mode 100644 index 00000000..801b9203 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordLOC.cs @@ -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)); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordMB.cs b/MinecraftClient/Protocol/Dns/Records/RecordMB.cs new file mode 100644 index 00000000..a19e9163 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordMB.cs @@ -0,0 +1,35 @@ +using System; +/* +3.3.3. MB RDATA format (EXPERIMENTAL) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / MADNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +MADNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordMG.cs b/MinecraftClient/Protocol/Dns/Records/RecordMG.cs new file mode 100644 index 00000000..8e16d764 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordMG.cs @@ -0,0 +1,34 @@ +using System; +/* +3.3.6. MG RDATA format (EXPERIMENTAL) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / MGMNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +MGMNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordMINFO.cs b/MinecraftClient/Protocol/Dns/Records/RecordMINFO.cs new file mode 100644 index 00000000..79efc9e0 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordMINFO.cs @@ -0,0 +1,52 @@ +using System; +/* + 3.3.7. MINFO RDATA format (EXPERIMENTAL) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / RMAILBX / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / EMAILBX / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +RMAILBX A 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 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordMR.cs b/MinecraftClient/Protocol/Dns/Records/RecordMR.cs new file mode 100644 index 00000000..10f7dc6a --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordMR.cs @@ -0,0 +1,36 @@ +using System; +/* +3.3.8. MR RDATA format (EXPERIMENTAL) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / NEWNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +NEWNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordMX.cs b/MinecraftClient/Protocol/Dns/Records/RecordMX.cs new file mode 100644 index 00000000..9fc62505 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordMX.cs @@ -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 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordNAPTR.cs b/MinecraftClient/Protocol/Dns/Records/RecordNAPTR.cs new file mode 100644 index 00000000..d30982da --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordNAPTR.cs @@ -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 which contains various flags. + + SERVICES A which contains protocol and service + identifiers. + + REGEXP A which contains a regular expression. + + REPLACEMENT A which specifies the new value in the + case where the regular expression is a simple replacement + operation. + + and 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordNS.cs b/MinecraftClient/Protocol/Dns/Records/RecordNS.cs new file mode 100644 index 00000000..6eb59d3e --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordNS.cs @@ -0,0 +1,43 @@ +using System; +/* + 3.3.11. NS RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / NSDNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +NSDNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordNSAP.cs b/MinecraftClient/Protocol/Dns/Records/RecordNSAP.cs new file mode 100644 index 00000000..11be4fd9 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordNSAP.cs @@ -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]); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordNULL.cs b/MinecraftClient/Protocol/Dns/Records/RecordNULL.cs new file mode 100644 index 00000000..3737959d --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordNULL.cs @@ -0,0 +1,38 @@ +using System; +/* +3.3.10. NULL RDATA format (EXPERIMENTAL) + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordPTR.cs b/MinecraftClient/Protocol/Dns/Records/RecordPTR.cs new file mode 100644 index 00000000..685831e4 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordPTR.cs @@ -0,0 +1,38 @@ +using System; +/* + 3.3.12. PTR RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / PTRDNAME / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +PTRDNAME A 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; + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordPX.cs b/MinecraftClient/Protocol/Dns/Records/RecordPX.cs new file mode 100644 index 00000000..5260ec2c --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordPX.cs @@ -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 element containing , the + RFC822 part of the MCGAM; + + MAPX400 A element containing the value of + 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: + + [] [] + + When we store in DNS a 'table1' or a 'gate1' entry, then 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, 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 , + MAP822 and MAPX400, as 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordRP.cs b/MinecraftClient/Protocol/Dns/Records/RecordRP.cs new file mode 100644 index 00000000..3264a676 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordRP.cs @@ -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: + + RP + + Both RDATA fields are required in all RP RRs. + + The first field, , 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 to indicate that no mailbox is + available. + + The second field, , is a domain name for which TXT RR's + exist. A subsequent query can be performed to retrieve the + associated TXT resource records at . 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 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordRT.cs b/MinecraftClient/Protocol/Dns/Records/RecordRT.cs new file mode 100644 index 00000000..291a3cf1 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordRT.cs @@ -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: + + RT + + Both RDATA fields are required in all RT RRs. + + The first field, , is a 16 bit integer, representing the + preference of the route. Smaller numbers indicate more preferred + routes. + + is the domain name of a host which will serve as + an intermediate in reaching the host specified by . The DNS + RRs associated with 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 . + + 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordSIG.cs b/MinecraftClient/Protocol/Dns/Records/RecordSIG.cs new file mode 100644 index 00000000..81179fd0 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordSIG.cs @@ -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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordSOA.cs b/MinecraftClient/Protocol/Dns/Records/RecordSOA.cs new file mode 100644 index 00000000..7b1dc935 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordSOA.cs @@ -0,0 +1,105 @@ +using System; + +/* +3.3.13. SOA RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / MNAME / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / RNAME / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | SERIAL | + | | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | REFRESH | + | | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | RETRY | + | | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | EXPIRE | + | | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | MINIMUM | + | | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +MNAME The of the name server that was the + original or primary source of data for this zone. + +RNAME A 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); + } + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordSRV.cs b/MinecraftClient/Protocol/Dns/Records/RecordSRV.cs new file mode 100644 index 00000000..ce8bb4f8 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordSRV.cs @@ -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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordTKEY.cs b/MinecraftClient/Protocol/Dns/Records/RecordTKEY.cs new file mode 100644 index 00000000..1d850c47 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordTKEY.cs @@ -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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordTSIG.cs b/MinecraftClient/Protocol/Dns/Records/RecordTSIG.cs new file mode 100644 index 00000000..52ea9af9 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordTSIG.cs @@ -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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordTXT.cs b/MinecraftClient/Protocol/Dns/Records/RecordTXT.cs new file mode 100644 index 00000000..f87a64ac --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordTXT.cs @@ -0,0 +1,38 @@ +using System; + +#region Rfc info +/* +3.3.14. TXT RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + / TXT-DATA / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +TXT-DATA One or more 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordWKS.cs b/MinecraftClient/Protocol/Dns/Records/RecordWKS.cs new file mode 100644 index 00000000..219c5409 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordWKS.cs @@ -0,0 +1,75 @@ +using System; +/* + * 3.4.2. WKS RDATA format + + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | ADDRESS | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | PROTOCOL | | + +--+--+--+--+--+--+--+--+ | + | | + / / + / / + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +where: + +ADDRESS An 32 bit Internet address + +PROTOCOL An 8 bit IP protocol number + + 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RecordX25.cs b/MinecraftClient/Protocol/Dns/Records/RecordX25.cs new file mode 100644 index 00000000..7f46d4a3 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/RecordX25.cs @@ -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: + + X25 + + is required in all X25 RRs. + + identifies the PSDN (Public Switched Data Network) + address in the X.121 [10] numbering plan associated with . + Its format in master files is a syntactically + identical to that used in TXT and HINFO. + + The format of X25 is class insensitive. X25 RRs cause no additional + section processing. + + The 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); + } + + } +} diff --git a/MinecraftClient/Protocol/Dns/Records/RpRecord.cs b/MinecraftClient/Protocol/Dns/Records/RpRecord.cs deleted file mode 100644 index bd47d41a..00000000 --- a/MinecraftClient/Protocol/Dns/Records/RpRecord.cs +++ /dev/null @@ -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; - } - } - -} diff --git a/MinecraftClient/Protocol/Dns/Records/RtRecord.cs b/MinecraftClient/Protocol/Dns/Records/RtRecord.cs deleted file mode 100644 index 627aafd7..00000000 --- a/MinecraftClient/Protocol/Dns/Records/RtRecord.cs +++ /dev/null @@ -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; - } - } - -} diff --git a/MinecraftClient/Protocol/Dns/Records/SoaRecord.cs b/MinecraftClient/Protocol/Dns/Records/SoaRecord.cs deleted file mode 100644 index 1a671bbf..00000000 --- a/MinecraftClient/Protocol/Dns/Records/SoaRecord.cs +++ /dev/null @@ -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(); - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/SrvRecord.cs b/MinecraftClient/Protocol/Dns/Records/SrvRecord.cs deleted file mode 100644 index f306a0ef..00000000 --- a/MinecraftClient/Protocol/Dns/Records/SrvRecord.cs +++ /dev/null @@ -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"; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/TSigRecord.cs b/MinecraftClient/Protocol/Dns/Records/TSigRecord.cs deleted file mode 100644 index f7f2638b..00000000 --- a/MinecraftClient/Protocol/Dns/Records/TSigRecord.cs +++ /dev/null @@ -1,235 +0,0 @@ -using System; -using System.IO; -using System.Net; -using System.Text; -using DnDns.Enums; - -namespace DnDns.Records -{ - /// - /// Implementation of a TSIG record structure as per RFC 2845 - /// - 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(""); - } - 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(""); - } - } - else - { - sb.Append("<"); - sb.Append(Convert.ToBase64String(_otherData)); - sb.Append(">"); - } - } - - return sb.ToString(); - } - } -} \ No newline at end of file diff --git a/MinecraftClient/Protocol/Dns/Records/TxtRecord.cs b/MinecraftClient/Protocol/Dns/Records/TxtRecord.cs deleted file mode 100644 index 13393e92..00000000 --- a/MinecraftClient/Protocol/Dns/Records/TxtRecord.cs +++ /dev/null @@ -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 -{ - /// - /// - /// - 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; - } - } - -} diff --git a/MinecraftClient/Protocol/Dns/Records/UnknownRecord.cs b/MinecraftClient/Protocol/Dns/Records/UnknownRecord.cs deleted file mode 100644 index b48431dc..00000000 --- a/MinecraftClient/Protocol/Dns/Records/UnknownRecord.cs +++ /dev/null @@ -1,69 +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 -{ - class UnknownRecord : DnsRecordBase - { - public UnknownRecord(RecordHeader dnsHeader) : base(dnsHeader) { } - - public override void ParseRecord(ref MemoryStream ms) - { - // Type not implemented so we read it into a buffer and print out the data. - StringBuilder sb = new StringBuilder(this.DnsHeader.DataLength); - byte[] b = new byte[1]; - // Loop over data, if char is easily converted to ASCII, convert it. - // Otherwise print a '.' - for (int i = 0; i < this.DnsHeader.DataLength; i++) - { - ms.Read(b, 0, 1); - if ((b[0] > 0x20) && (b[0] < 0x7e)) - { - sb.Append(Encoding.ASCII.GetString(b)); - } - else - { - sb.Append('.'); - } - } - _answer = sb.ToString(); - _errorMsg = "Type " + this.DnsHeader.NsType + " not implemented."; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/WksRecord.cs b/MinecraftClient/Protocol/Dns/Records/WksRecord.cs deleted file mode 100644 index 9039c136..00000000 --- a/MinecraftClient/Protocol/Dns/Records/WksRecord.cs +++ /dev/null @@ -1,115 +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.Net.Sockets; - -namespace DnDns.Records -{ - public sealed class WksRecord : DnsRecordBase - { - private ProtocolType _protocolType; - private IPAddress _ipAddress; - private short[] _ports; - - public ProtocolType ProtocolType - { - get { return _protocolType; } - set { _protocolType = value; } - } - - public IPAddress IpAddress - { - get { return _ipAddress; } - set { _ipAddress = value; } - } - - public short[] Ports - { - get { return _ports; } - set { _ports = value; } - } - - internal WksRecord(RecordHeader dnsHeader) : base(dnsHeader) { } - - public override void ParseRecord(ref MemoryStream ms) - { - // Bit map is the data length minus the IpAddress (4 bytes) and the Protocol (1 byte), 5 bytes total. - int bitMapLen = this.DnsHeader.DataLength - 4 - 1; - byte[] ipAddr = new byte[4]; - byte[] BitMap = new byte[bitMapLen]; - - ms.Read(ipAddr, 0, 4); - // _ipAddress = new IPAddress(Tools.ToUInt32(ipAddr, 0)); - _ipAddress = new IPAddress((uint)IPAddress.NetworkToHostOrder(BitConverter.ToUInt32(ipAddr, 0))); - _protocolType = (ProtocolType)ms.ReadByte(); - ms.Read(BitMap, 0, BitMap.Length); - _ports = GetKnownServices(BitMap); - _answer = _protocolType + ": " + Tools.GetServByPort(_ports, _protocolType); - } - - private short[] GetKnownServices(byte[] BitMap) - { - short[] tempPortArr = new short[1024]; - int portCount = 0; - // mask to isolate left most bit - const byte mask = 0x80; - // Iterate through each byte - for (int i = 0; i < BitMap.Length; i++) - { - byte currentByte = BitMap[i]; - int count = 0; - // iterate through each bit - for (byte j = 0x07; j != 0xFF; j--) - { - int port = (((i * 8) + count++) + 1); - currentByte = (byte)(currentByte << 1); - // is the flag set? - if ((mask & currentByte) == 0x80) - { - tempPortArr[portCount] = (short)port; - portCount++; - } - } - } - short[] portArr = new short[portCount]; - Array.Copy(tempPortArr, 0, portArr, 0, portCount); - return portArr; - } - } -} diff --git a/MinecraftClient/Protocol/Dns/Records/X25Record.cs b/MinecraftClient/Protocol/Dns/Records/X25Record.cs deleted file mode 100644 index 886efccb..00000000 --- a/MinecraftClient/Protocol/Dns/Records/X25Record.cs +++ /dev/null @@ -1,60 +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 X25Record : DnsRecordBase - { - private string _x25Address; - - public string X25Address - { - get { return _x25Address; } - } - - internal X25Record(RecordHeader dnsHeader) : base(dnsHeader) { } - - public override void ParseRecord(ref MemoryStream ms) - { - _x25Address = base.ParseText(ref ms); - _answer = "X.25 X.121 Address: " + _x25Address; - } - } - -} diff --git a/MinecraftClient/Protocol/Dns/Records/totla.txt b/MinecraftClient/Protocol/Dns/Records/totla.txt new file mode 100644 index 00000000..bc195f3e --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Records/totla.txt @@ -0,0 +1,21 @@ +Record.cs +RecordA.cs +RecordAAAA.cs +RecordCNAME.cs +RecordHINFO.cs +RecordMB.cs +RecordMD.cs +RecordMF.cs +RecordMG.cs +RecordMINFO.cs +RecordMR.cs +RecordMX.cs +RecordNS.cs +RecordNULL.cs +RecordPTR.cs +RecordReader.cs +RecordSOA.cs +RecordTXT.cs +RecordUnknown.cs +RecordWKS.cs +totla.txt diff --git a/MinecraftClient/Protocol/Dns/Request.cs b/MinecraftClient/Protocol/Dns/Request.cs new file mode 100644 index 00000000..c621443b --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Request.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Heijden.DNS +{ + public class Request + { + public Header header; + + private List questions; + + public Request() + { + header = new Header(); + header.OPCODE = OPCode.Query; + header.QDCOUNT = 0; + + questions = new List(); + } + + public void AddQuestion(Question question) + { + questions.Add(question); + } + + public byte[] Data + { + get + { + List data = new List(); + header.QDCOUNT = (ushort)questions.Count; + data.AddRange(header.Data); + foreach (Question q in questions) + data.AddRange(q.Data); + return data.ToArray(); + } + } + } +} diff --git a/MinecraftClient/Protocol/Dns/Resolver.cs b/MinecraftClient/Protocol/Dns/Resolver.cs new file mode 100644 index 00000000..6f1086e1 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Resolver.cs @@ -0,0 +1,987 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Net; +using System.Text; +using System.Net.Sockets; + +using System.Net.NetworkInformation; + +using System.Diagnostics; +using System.Runtime.Remoting.Messaging; + + +/* + * Network Working Group P. Mockapetris + * Request for Comments: 1035 ISI + * November 1987 + * + * DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION + * + */ + +namespace Heijden.DNS +{ + /// + /// Resolver is the main class to do DNS query lookups + /// + public class Resolver + { + /// + /// Version of this set of routines, when not in a library + /// + public string Version + { + get + { + return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + } + } + + /// + /// Default DNS port + /// + public const int DefaultPort = 53; + + /// + /// Gets list of OPENDNS servers + /// + public static readonly IPEndPoint[] DefaultDnsServers = + { + new IPEndPoint(IPAddress.Parse("208.67.222.222"), DefaultPort), + new IPEndPoint(IPAddress.Parse("208.67.220.220"), DefaultPort) + }; + + private ushort m_Unique; + private bool m_UseCache; + private bool m_Recursion; + private int m_Retries; + private int m_Timeout; + private TransportType m_TransportType; + + private List m_DnsServers; + + private Dictionary m_ResponseCache; + + /// + /// Constructor of Resolver using DNS servers specified. + /// + /// Set of DNS servers + public Resolver(IPEndPoint[] DnsServers) + { + m_ResponseCache = new Dictionary(); + m_DnsServers = new List(); + m_DnsServers.AddRange(DnsServers); + + m_Unique = (ushort)(new Random()).Next(); + m_Retries = 3; + m_Timeout = 1; + m_Recursion = true; + m_UseCache = true; + m_TransportType = TransportType.Udp; + } + + /// + /// Constructor of Resolver using DNS server specified. + /// + /// DNS server to use + public Resolver(IPEndPoint DnsServer) + : this(new IPEndPoint[] { DnsServer }) + { + } + + /// + /// Constructor of Resolver using DNS server and port specified. + /// + /// DNS server to use + /// DNS port to use + public Resolver(IPAddress ServerIpAddress, int ServerPortNumber) + : this(new IPEndPoint(ServerIpAddress,ServerPortNumber)) + { + } + + /// + /// Constructor of Resolver using DNS address and port specified. + /// + /// DNS server address to use + /// DNS port to use + public Resolver(string ServerIpAddress, int ServerPortNumber) + : this(IPAddress.Parse(ServerIpAddress), ServerPortNumber) + { + } + + /// + /// Constructor of Resolver using DNS address. + /// + /// DNS server address to use + public Resolver(string ServerIpAddress) + : this(IPAddress.Parse(ServerIpAddress), DefaultPort) + { + } + + /// + /// Resolver constructor, using DNS servers specified by Windows + /// + public Resolver() + : this(GetDnsServers()) + { + } + + public class VerboseOutputEventArgs : EventArgs + { + public string Message; + public VerboseOutputEventArgs(string Message) + { + this.Message = Message; + } + } + + private void Verbose(string format, params object[] args) + { + if (OnVerbose != null) + OnVerbose(this, new VerboseEventArgs(string.Format(format, args))); + } + + /// + /// Verbose messages from internal operations + /// + public event VerboseEventHandler OnVerbose; + public delegate void VerboseEventHandler(object sender, VerboseEventArgs e); + + public class VerboseEventArgs : EventArgs + { + public string Message; + public VerboseEventArgs(string Message) + { + this.Message = Message; + } + } + + + /// + /// Gets or sets timeout in milliseconds + /// + public int TimeOut + { + get + { + return m_Timeout; + } + set + { + m_Timeout = value; + } + } + + /// + /// Gets or sets number of retries before giving up + /// + public int Retries + { + get + { + return m_Retries; + } + set + { + if(value>=1) + m_Retries = value; + } + } + + /// + /// Gets or set recursion for doing queries + /// + public bool Recursion + { + get + { + return m_Recursion; + } + set + { + m_Recursion = value; + } + } + + /// + /// Gets or sets protocol to use + /// + public TransportType TransportType + { + get + { + return m_TransportType; + } + set + { + m_TransportType = value; + } + } + + /// + /// Gets or sets list of DNS servers to use + /// + public IPEndPoint[] DnsServers + { + get + { + return m_DnsServers.ToArray(); + } + set + { + m_DnsServers.Clear(); + m_DnsServers.AddRange(value); + } + } + + /// + /// Gets first DNS server address or sets single DNS server to use + /// + public string DnsServer + { + get + { + return m_DnsServers[0].Address.ToString(); + } + set + { + IPAddress ip; + if (IPAddress.TryParse(value, out ip)) + { + m_DnsServers.Clear(); + m_DnsServers.Add(new IPEndPoint(ip, DefaultPort)); + return; + } + Response response = Query(value, QType.A); + if (response.RecordsA.Length > 0) + { + m_DnsServers.Clear(); + m_DnsServers.Add(new IPEndPoint(response.RecordsA[0].Address, DefaultPort)); + } + } + } + + + public bool UseCache + { + get + { + return m_UseCache; + } + set + { + m_UseCache = value; + if (!m_UseCache) + m_ResponseCache.Clear(); + } + } + + /// + /// Clear the resolver cache + /// + public void ClearCache() + { + m_ResponseCache.Clear(); + } + + private Response SearchInCache(Question question) + { + if (!m_UseCache) + return null; + + string strKey = question.QClass + "-" + question.QType + "-" + question.QName; + + Response response = null; + + lock (m_ResponseCache) + { + if (!m_ResponseCache.ContainsKey(strKey)) + return null; + + response = m_ResponseCache[strKey]; + } + + int TimeLived = (int)((DateTime.Now.Ticks - response.TimeStamp.Ticks) / TimeSpan.TicksPerSecond); + foreach (RR rr in response.RecordsRR) + { + rr.TimeLived = TimeLived; + // The TTL property calculates its actual time to live + if (rr.TTL == 0) + return null; // out of date + } + return response; + } + + private void AddToCache(Response response) + { + if (!m_UseCache) + return; + + // No question, no caching + if (response.Questions.Count == 0) + return; + + // Only cached non-error responses + if (response.header.RCODE != RCode.NoError) + return; + + Question question = response.Questions[0]; + + string strKey = question.QClass + "-" + question.QType + "-" + question.QName; + + lock (m_ResponseCache) + { + if (m_ResponseCache.ContainsKey(strKey)) + m_ResponseCache.Remove(strKey); + + m_ResponseCache.Add(strKey, response); + } + } + + private Response UdpRequest(Request request) + { + // RFC1035 max. size of a UDP datagram is 512 bytes + byte[] responseMessage = new byte[512]; + + for (int intAttempts = 0; intAttempts < m_Retries; intAttempts++) + { + for (int intDnsServer = 0; intDnsServer < m_DnsServers.Count; intDnsServer++) + { + Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, m_Timeout * 1000); + + try + { + socket.SendTo(request.Data, m_DnsServers[intDnsServer]); + int intReceived = socket.Receive(responseMessage); + byte[] data = new byte[intReceived]; + Array.Copy(responseMessage, data, intReceived); + Response response = new Response(m_DnsServers[intDnsServer], data); + AddToCache(response); + return response; + } + catch (SocketException) + { + Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1))); + continue; // next try + } + finally + { + m_Unique++; + + // close the socket + socket.Close(); + } + } + } + Response responseTimeout = new Response(); + responseTimeout.Error = "Timeout Error"; + return responseTimeout; + } + + private Response TcpRequest(Request request) + { + //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); + //sw.Start(); + + byte[] responseMessage = new byte[512]; + + for (int intAttempts = 0; intAttempts < m_Retries; intAttempts++) + { + for (int intDnsServer = 0; intDnsServer < m_DnsServers.Count; intDnsServer++) + { + TcpClient tcpClient = new TcpClient(); + tcpClient.ReceiveTimeout = m_Timeout * 1000; + + try + { + IAsyncResult result = tcpClient.BeginConnect(m_DnsServers[intDnsServer].Address, m_DnsServers[intDnsServer].Port, null, null); + + bool success = result.AsyncWaitHandle.WaitOne(m_Timeout*1000, true); + + if (!success || !tcpClient.Connected) + { + tcpClient.Close(); + Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1))); + continue; + } + + BufferedStream bs = new BufferedStream(tcpClient.GetStream()); + + byte[] data = request.Data; + bs.WriteByte((byte)((data.Length >> 8) & 0xff)); + bs.WriteByte((byte)(data.Length & 0xff)); + bs.Write(data, 0, data.Length); + bs.Flush(); + + Response TransferResponse = new Response(); + int intSoa = 0; + int intMessageSize = 0; + + //Debug.WriteLine("Sending "+ (request.Length+2) + " bytes in "+ sw.ElapsedMilliseconds+" mS"); + + while (true) + { + int intLength = bs.ReadByte() << 8 | bs.ReadByte(); + if (intLength <= 0) + { + tcpClient.Close(); + Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1))); + throw new SocketException(); // next try + } + + intMessageSize += intLength; + + data = new byte[intLength]; + bs.Read(data, 0, intLength); + Response response = new Response(m_DnsServers[intDnsServer], data); + + //Debug.WriteLine("Received "+ (intLength+2)+" bytes in "+sw.ElapsedMilliseconds +" mS"); + + if (response.header.RCODE != RCode.NoError) + return response; + + if (response.Questions[0].QType != QType.AXFR) + { + AddToCache(response); + return response; + } + + // Zone transfer!! + + if(TransferResponse.Questions.Count==0) + TransferResponse.Questions.AddRange(response.Questions); + TransferResponse.Answers.AddRange(response.Answers); + TransferResponse.Authorities.AddRange(response.Authorities); + TransferResponse.Additionals.AddRange(response.Additionals); + + if (response.Answers[0].Type == Type.SOA) + intSoa++; + + if (intSoa == 2) + { + TransferResponse.header.QDCOUNT = (ushort)TransferResponse.Questions.Count; + TransferResponse.header.ANCOUNT = (ushort)TransferResponse.Answers.Count; + TransferResponse.header.NSCOUNT = (ushort)TransferResponse.Authorities.Count; + TransferResponse.header.ARCOUNT = (ushort)TransferResponse.Additionals.Count; + TransferResponse.MessageSize = intMessageSize; + return TransferResponse; + } + } + } // try + catch (SocketException) + { + continue; // next try + } + finally + { + m_Unique++; + + // close the socket + tcpClient.Close(); + } + } + } + Response responseTimeout = new Response(); + responseTimeout.Error = "Timeout Error"; + return responseTimeout; + } + + /// + /// Do Query on specified DNS servers + /// + /// Name to query + /// Question type + /// Class type + /// Response of the query + public Response Query(string name, QType qtype, QClass qclass) + { + Question question = new Question(name, qtype, qclass); + Response response = SearchInCache(question); + if (response != null) + return response; + + Request request = new Request(); + request.AddQuestion(question); + return GetResponse(request); + } + + /// + /// Do an QClass=IN Query on specified DNS servers + /// + /// Name to query + /// Question type + /// Response of the query + public Response Query(string name, QType qtype) + { + Question question = new Question(name, qtype, QClass.IN); + Response response = SearchInCache(question); + if (response != null) + return response; + + Request request = new Request(); + request.AddQuestion(question); + return GetResponse(request); + } + + private Response GetResponse(Request request) + { + request.header.ID = m_Unique; + request.header.RD = m_Recursion; + + if (m_TransportType == TransportType.Udp) + return UdpRequest(request); + + if (m_TransportType == TransportType.Tcp) + return TcpRequest(request); + + Response response = new Response(); + response.Error = "Unknown TransportType"; + return response; + } + + /// + /// Gets a list of default DNS servers used on the Windows machine. + /// + /// + public static IPEndPoint[] GetDnsServers() + { + List list = new List(); + + NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); + foreach (NetworkInterface n in adapters) + { + if (n.OperationalStatus == OperationalStatus.Up) + { + IPInterfaceProperties ipProps = n.GetIPProperties(); + // thanks to Jon Webster on May 20, 2008 + foreach (IPAddress ipAddr in ipProps.DnsAddresses) + { + IPEndPoint entry = new IPEndPoint(ipAddr, DefaultPort); + if (!list.Contains(entry)) + list.Add(entry); + } + + } + } + return list.ToArray(); + } + + + // + + private IPHostEntry MakeEntry(string HostName) + { + IPHostEntry entry = new IPHostEntry(); + + entry.HostName = HostName; + + Response response = Query(HostName, QType.A, QClass.IN); + + // fill AddressList and aliases + List AddressList = new List(); + List Aliases = new List(); + foreach (AnswerRR answerRR in response.Answers) + { + if (answerRR.Type == Type.A) + { + // answerRR.RECORD.ToString() == (answerRR.RECORD as RecordA).Address + AddressList.Add(IPAddress.Parse((answerRR.RECORD.ToString()))); + entry.HostName = answerRR.NAME; + } + else + { + if (answerRR.Type == Type.CNAME) + Aliases.Add(answerRR.NAME); + } + } + entry.AddressList = AddressList.ToArray(); + entry.Aliases = Aliases.ToArray(); + + return entry; + } + + /// + /// Translates the IPV4 or IPV6 address into an arpa address + /// + /// IP address to get the arpa address form + /// The 'mirrored' IPV4 or IPV6 arpa address + public static string GetArpaFromIp(IPAddress ip) + { + if (ip.AddressFamily == AddressFamily.InterNetwork) + { + StringBuilder sb = new StringBuilder(); + sb.Append("in-addr.arpa."); + foreach (byte b in ip.GetAddressBytes()) + { + sb.Insert(0, string.Format("{0}.", b)); + } + return sb.ToString(); + } + if (ip.AddressFamily == AddressFamily.InterNetworkV6) + { + StringBuilder sb = new StringBuilder(); + sb.Append("ip6.arpa."); + foreach (byte b in ip.GetAddressBytes()) + { + sb.Insert(0, string.Format("{0:x}.", (b >> 4) & 0xf)); + sb.Insert(0, string.Format("{0:x}.", (b >> 0) & 0xf)); + } + return sb.ToString(); + } + return "?"; + } + + public static string GetArpaFromEnum(string strEnum) + { + StringBuilder sb = new StringBuilder(); + string Number = System.Text.RegularExpressions.Regex.Replace(strEnum, "[^0-9]", ""); + sb.Append("e164.arpa."); + foreach (char c in Number) + { + sb.Insert(0, string.Format("{0}.", c)); + } + return sb.ToString(); + } + + #region Deprecated methods in the original System.Net.DNS class + + /// + /// Returns the Internet Protocol (IP) addresses for the specified host. + /// + /// The host name or IP address to resolve. + /// + /// An array of type System.Net.IPAddress that holds the IP addresses for the + /// host that is specified by the hostNameOrAddress parameter. + /// + public IPAddress[] GetHostAddresses(string hostNameOrAddress) + { + IPHostEntry entry = GetHostEntry(hostNameOrAddress); + return entry.AddressList; + } + + private delegate IPAddress[] GetHostAddressesDelegate(string hostNameOrAddress); + + /// + /// Asynchronously returns the Internet Protocol (IP) addresses for the specified + /// host. + /// + /// The host name or IP address to resolve. + /// + /// An System.AsyncCallback delegate that references the method to invoke when + /// the operation is complete. + /// + /// + /// A user-defined object that contains information about the operation. This + /// object is passed to the requestCallback delegate when the operation is complete. + /// + /// An System.IAsyncResult instance that references the asynchronous request. + public IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, AsyncCallback requestCallback, object stateObject) + { + GetHostAddressesDelegate g = new GetHostAddressesDelegate(GetHostAddresses); + return g.BeginInvoke(hostNameOrAddress, requestCallback, stateObject); + } + + /// + /// Ends an asynchronous request for DNS information. + /// + /// + /// An System.IAsyncResult instance returned by a call to the Heijden.Dns.Resolver.BeginGetHostAddresses(System.String,System.AsyncCallback,System.Object) + /// method. + /// + /// + public IPAddress[] EndGetHostAddresses(IAsyncResult AsyncResult) + { + AsyncResult aResult = (AsyncResult)AsyncResult; + GetHostAddressesDelegate g = (GetHostAddressesDelegate)aResult.AsyncDelegate; + return g.EndInvoke(AsyncResult); + } + + /// + /// Creates an System.Net.IPHostEntry instance from the specified System.Net.IPAddress. + /// + /// An System.Net.IPAddress. + /// An System.Net.IPHostEntry. + public IPHostEntry GetHostByAddress(IPAddress ip) + { + return GetHostEntry(ip); + } + + /// + /// Creates an System.Net.IPHostEntry instance from an IP address. + /// + /// An IP address. + /// An System.Net.IPHostEntry instance. + public IPHostEntry GetHostByAddress(string address) + { + return GetHostEntry(address); + } + + /// + /// Gets the DNS information for the specified DNS host name. + /// + /// The DNS name of the host + /// An System.Net.IPHostEntry object that contains host information for the address specified in hostName. + public IPHostEntry GetHostByName(string hostName) + { + return MakeEntry(hostName); + } + + private delegate IPHostEntry GetHostByNameDelegate(string hostName); + + /// + /// Asynchronously resolves an IP address to an System.Net.IPHostEntry instance. + /// + /// The DNS name of the host + /// An System.AsyncCallback delegate that references the method to invoke when the operation is complete. + /// + /// A user-defined object that contains information about the operation. This + /// object is passed to the requestCallback delegate when the operation is complete. + /// + /// An System.IAsyncResult instance that references the asynchronous request. + public IAsyncResult BeginGetHostByName(string hostName, AsyncCallback requestCallback, object stateObject) + { + GetHostByNameDelegate g = new GetHostByNameDelegate(GetHostByName); + return g.BeginInvoke(hostName, requestCallback, stateObject); + } + + /// + /// Ends an asynchronous request for DNS information. + /// + /// + /// An System.IAsyncResult instance returned by a call to an + /// Heijden.Dns.Resolver.BeginGetHostByName method. + /// + /// + public IPHostEntry EndGetHostByName(IAsyncResult AsyncResult) + { + AsyncResult aResult = (AsyncResult)AsyncResult; + GetHostByNameDelegate g = (GetHostByNameDelegate)aResult.AsyncDelegate; + return g.EndInvoke(AsyncResult); + } + + /// + /// Resolves a host name or IP address to an System.Net.IPHostEntry instance. + /// + /// A DNS-style host name or IP address. + /// + //[Obsolete("no problem",false)] + public IPHostEntry Resolve(string hostName) + { + return MakeEntry(hostName); + } + + private delegate IPHostEntry ResolveDelegate(string hostName); + + /// + /// Begins an asynchronous request to resolve a DNS host name or IP address to + /// an System.Net.IPAddress instance. + /// + /// The DNS name of the host. + /// + /// An System.AsyncCallback delegate that references the method to invoke when + /// the operation is complete. + /// + /// + /// A user-defined object that contains information about the operation. This + /// object is passed to the requestCallback delegate when the operation is complete. + /// + /// An System.IAsyncResult instance that references the asynchronous request. + public IAsyncResult BeginResolve(string hostName, AsyncCallback requestCallback, object stateObject) + { + ResolveDelegate g = new ResolveDelegate(Resolve); + return g.BeginInvoke(hostName, requestCallback, stateObject); + } + + /// + /// Ends an asynchronous request for DNS information. + /// + /// + /// An System.IAsyncResult instance that is returned by a call to the System.Net.Dns.BeginResolve(System.String,System.AsyncCallback,System.Object) + /// method. + /// + /// An System.Net.IPHostEntry object that contains DNS information about a host. + public IPHostEntry EndResolve(IAsyncResult AsyncResult) + { + AsyncResult aResult = (AsyncResult)AsyncResult; + ResolveDelegate g = (ResolveDelegate)aResult.AsyncDelegate; + return g.EndInvoke(AsyncResult); + } + #endregion + + /// + /// Resolves an IP address to an System.Net.IPHostEntry instance. + /// + /// An IP address. + /// + /// An System.Net.IPHostEntry instance that contains address information about + /// the host specified in address. + /// + public IPHostEntry GetHostEntry(IPAddress ip) + { + Response response = Query(GetArpaFromIp(ip), QType.PTR, QClass.IN); + if (response.RecordsPTR.Length > 0) + return MakeEntry(response.RecordsPTR[0].PTRDNAME); + else + return new IPHostEntry(); + } + + /// + /// Resolves a host name or IP address to an System.Net.IPHostEntry instance. + /// + /// The host name or IP address to resolve. + /// + /// An System.Net.IPHostEntry instance that contains address information about + /// the host specified in hostNameOrAddress. + /// + public IPHostEntry GetHostEntry(string hostNameOrAddress) + { + IPAddress iPAddress; + if (IPAddress.TryParse(hostNameOrAddress, out iPAddress)) + return GetHostEntry(iPAddress); + else + return MakeEntry(hostNameOrAddress); + } + + private delegate IPHostEntry GetHostEntryViaIPDelegate(IPAddress ip); + private delegate IPHostEntry GetHostEntryDelegate(string hostNameOrAddress); + + /// + /// Asynchronously resolves a host name or IP address to an System.Net.IPHostEntry instance. + /// + /// The host name or IP address to resolve. + /// + /// An System.AsyncCallback delegate that references the method to invoke when + /// the operation is complete. + /// + /// + /// A user-defined object that contains information about the operation. This + /// object is passed to the requestCallback delegate when the operation is complete. + /// + /// An System.IAsyncResult instance that references the asynchronous request. + public IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCallback requestCallback, object stateObject) + { + GetHostEntryDelegate g = new GetHostEntryDelegate(GetHostEntry); + return g.BeginInvoke(hostNameOrAddress, requestCallback, stateObject); + } + + /// + /// Asynchronously resolves an IP address to an System.Net.IPHostEntry instance. + /// + /// The IP address to resolve. + /// + /// An System.AsyncCallback delegate that references the method to invoke when + /// the operation is complete. + /// + /// + /// A user-defined object that contains information about the operation. This + /// object is passed to the requestCallback delegate when the operation is complete. + /// + /// An System.IAsyncResult instance that references the asynchronous request. + public IAsyncResult BeginGetHostEntry(IPAddress ip, AsyncCallback requestCallback, object stateObject) + { + GetHostEntryViaIPDelegate g = new GetHostEntryViaIPDelegate(GetHostEntry); + return g.BeginInvoke(ip, requestCallback, stateObject); + } + + /// + /// Ends an asynchronous request for DNS information. + /// + /// + /// An System.IAsyncResult instance returned by a call to an + /// Overload:Heijden.Dns.Resolver.BeginGetHostEntry method. + /// + /// + /// An System.Net.IPHostEntry instance that contains address information about + /// the host. + /// + public IPHostEntry EndGetHostEntry(IAsyncResult AsyncResult) + { + AsyncResult aResult = (AsyncResult)AsyncResult; + if (aResult.AsyncDelegate is GetHostEntryDelegate) + { + GetHostEntryDelegate g = (GetHostEntryDelegate)aResult.AsyncDelegate; + return g.EndInvoke(AsyncResult); + } + if (aResult.AsyncDelegate is GetHostEntryViaIPDelegate) + { + GetHostEntryViaIPDelegate g = (GetHostEntryViaIPDelegate)aResult.AsyncDelegate; + return g.EndInvoke(AsyncResult); + } + return null; + } + + private enum RRRecordStatus + { + UNKNOWN, + NAME, + TTL, + CLASS, + TYPE, + VALUE + } + + public void LoadRootFile(string strPath) + { + StreamReader sr = new StreamReader(strPath); + while (!sr.EndOfStream) + { + string strLine = sr.ReadLine(); + if (strLine == null) + break; + int intI = strLine.IndexOf(';'); + if (intI >= 0) + strLine = strLine.Substring(0, intI); + strLine = strLine.Trim(); + if (strLine.Length == 0) + continue; + RRRecordStatus status = RRRecordStatus.NAME; + string Name=""; + string Ttl=""; + string Class=""; + string Type=""; + string Value=""; + string strW = ""; + for (intI = 0; intI < strLine.Length; intI++) + { + char C = strLine[intI]; + + if (C <= ' ' && strW!="") + { + switch (status) + { + case RRRecordStatus.NAME: + Name = strW; + status = RRRecordStatus.TTL; + break; + case RRRecordStatus.TTL: + Ttl = strW; + status = RRRecordStatus.CLASS; + break; + case RRRecordStatus.CLASS: + Class = strW; + status = RRRecordStatus.TYPE; + break; + case RRRecordStatus.TYPE: + Type = strW; + status = RRRecordStatus.VALUE; + break; + case RRRecordStatus.VALUE: + Value = strW; + status = RRRecordStatus.UNKNOWN; + break; + default: + break; + } + strW = ""; + } + if (C > ' ') + strW += C; + } + + } + sr.Close(); + } + } // class +} \ No newline at end of file diff --git a/MinecraftClient/Protocol/Dns/Response.cs b/MinecraftClient/Protocol/Dns/Response.cs new file mode 100644 index 00000000..e883d0df --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Response.cs @@ -0,0 +1,288 @@ +using System; +using System.IO; +using System.Net; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Heijden.DNS +{ + public class Response + { + /// + /// List of Question records + /// + public List Questions; + /// + /// List of AnswerRR records + /// + public List Answers; + /// + /// List of AuthorityRR records + /// + public List Authorities; + /// + /// List of AdditionalRR records + /// + public List Additionals; + + public Header header; + + /// + /// Error message, empty when no error + /// + public string Error; + + /// + /// The Size of the message + /// + public int MessageSize; + + /// + /// TimeStamp when cached + /// + public DateTime TimeStamp; + + /// + /// Server which delivered this response + /// + public IPEndPoint Server; + + public Response() + { + Questions = new List(); + Answers = new List(); + Authorities = new List(); + Additionals = new List(); + + Server = new IPEndPoint(0,0); + Error = ""; + MessageSize = 0; + TimeStamp = DateTime.Now; + header = new Header(); + } + + public Response(IPEndPoint iPEndPoint, byte[] data) + { + Error = ""; + Server = iPEndPoint; + TimeStamp = DateTime.Now; + MessageSize = data.Length; + RecordReader rr = new RecordReader(data); + + Questions = new List(); + Answers = new List(); + Authorities = new List(); + Additionals = new List(); + + header = new Header(rr); + + for (int intI = 0; intI < header.QDCOUNT; intI++) + { + Questions.Add(new Question(rr)); + } + + for (int intI = 0; intI < header.ANCOUNT; intI++) + { + Answers.Add(new AnswerRR(rr)); + } + + for (int intI = 0; intI < header.NSCOUNT; intI++) + { + Authorities.Add(new AuthorityRR(rr)); + } + for (int intI = 0; intI < header.ARCOUNT; intI++) + { + Additionals.Add(new AdditionalRR(rr)); + } + } + + /// + /// List of RecordMX in Response.Answers + /// + public RecordMX[] RecordsMX + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordMX record = answerRR.RECORD as RecordMX; + if(record!=null) + list.Add(record); + } + list.Sort(); + return list.ToArray(); + } + } + + /// + /// List of RecordTXT in Response.Answers + /// + public RecordTXT[] RecordsTXT + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordTXT record = answerRR.RECORD as RecordTXT; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordA in Response.Answers + /// + public RecordA[] RecordsA + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordA record = answerRR.RECORD as RecordA; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordPTR in Response.Answers + /// + public RecordPTR[] RecordsPTR + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordPTR record = answerRR.RECORD as RecordPTR; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordCNAME in Response.Answers + /// + public RecordCNAME[] RecordsCNAME + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordCNAME record = answerRR.RECORD as RecordCNAME; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordAAAA in Response.Answers + /// + public RecordAAAA[] RecordsAAAA + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordAAAA record = answerRR.RECORD as RecordAAAA; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordNS in Response.Answers + /// + public RecordNS[] RecordsNS + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordNS record = answerRR.RECORD as RecordNS; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordSOA in Response.Answers + /// + public RecordSOA[] RecordsSOA + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordSOA record = answerRR.RECORD as RecordSOA; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + /// + /// List of RecordSRV in Response.Answers + /// + public RecordSRV[] RecordsSRV + { + get + { + List list = new List(); + foreach (AnswerRR answerRR in this.Answers) + { + RecordSRV record = answerRR.RECORD as RecordSRV; + if (record != null) + list.Add(record); + } + return list.ToArray(); + } + } + + public RR[] RecordsRR + { + get + { + List list = new List(); + foreach (RR rr in this.Answers) + { + list.Add(rr); + } + foreach (RR rr in this.Answers) + { + list.Add(rr); + } + foreach (RR rr in this.Authorities) + { + list.Add(rr); + } + foreach (RR rr in this.Additionals) + { + list.Add(rr); + } + return list.ToArray(); + } + } + } +} diff --git a/MinecraftClient/Protocol/Dns/Security/IMessageSecurityProvider.cs b/MinecraftClient/Protocol/Dns/Security/IMessageSecurityProvider.cs deleted file mode 100644 index 03320007..00000000 --- a/MinecraftClient/Protocol/Dns/Security/IMessageSecurityProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using DnDns.Query; - -namespace DnDns.Security -{ - public interface IMessageSecurityProvider - { - DnsQueryRequest SecureMessage(DnsQueryRequest dnsQueryRequest); - } -} diff --git a/MinecraftClient/Protocol/Dns/Security/TsigMessageSecurityProvider.cs b/MinecraftClient/Protocol/Dns/Security/TsigMessageSecurityProvider.cs deleted file mode 100644 index bbd94718..00000000 --- a/MinecraftClient/Protocol/Dns/Security/TsigMessageSecurityProvider.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Security.Cryptography; -using DnDns.Enums; -using DnDns.Query; -using DnDns.Records; - -namespace DnDns.Security -{ - /// - /// Implements TSIG signing of DNS messages as per RFC2845 - /// - /// This class only supports the one hashing algorithim, hmac-sha256. - /// It would be trivial to add more. - public class TsigMessageSecurityProvider : IMessageSecurityProvider - { - private const string Hmacsha1String = "hmac-sha256."; - - private readonly string _name; - private readonly string _algorithimName; - private readonly ushort _fudge; - private readonly byte[] _sharedKey; - private readonly HMACSHA256 _hmac; - - /// - /// Initalise the - /// - /// The name of the shared key - /// The shared key in base64 string format - /// The signing time fudge value - public TsigMessageSecurityProvider(string name, string sharedKey, ushort fudge) - { - _name = name; - _fudge = fudge; - _sharedKey = Convert.FromBase64String(sharedKey); - - if (_sharedKey == null) - { - throw new ArgumentException("Argument is not a valid base64 string", "sharedKey"); - } - - _hmac = new HMACSHA256(_sharedKey); - - _algorithimName = Hmacsha1String; - } - - #region IMessageSecurityProvider Members - /// - /// Apply a TSIG record to the request message. - /// - /// The to add the security headers too. - /// A instance with additional security attributes assigned. - public DnsQueryRequest SecureMessage(DnsQueryRequest dnsQueryRequest) - { - DateTime signDateTime = DateTime.Now; - int timeHigh; - long timeLow; - - byte[] messageBytes = dnsQueryRequest.GetMessageBytes(); - Trace.WriteLine(String.Format("Message Header Bytes: {0}", DnsHelpers.DumpArrayToString(messageBytes))); - - MemoryStream memoryStream = new MemoryStream(); - memoryStream.Write(messageBytes, 0, messageBytes.Length); - - // the shared key name - byte[] data = DnsHelpers.CanonicaliseDnsName(_name, false); - memoryStream.Write(data, 0, data.Length); - data = BitConverter.GetBytes((ushort) (IPAddress.HostToNetworkOrder((ushort) NsClass.ANY) >> 16)); - memoryStream.Write(data, 0, data.Length); - // the TTL value - data = BitConverter.GetBytes((uint) (IPAddress.HostToNetworkOrder((uint) 0) >> 32)); - memoryStream.Write(data, 0, data.Length); - // the algorithim name - data = DnsHelpers.CanonicaliseDnsName(_algorithimName, true); - memoryStream.Write(data, 0, data.Length); - - DnsHelpers.ConvertToDnsTime(signDateTime.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((ushort) RCode.NoError) >> 16)); - memoryStream.Write(data, 0, data.Length); - - // no other data - data = BitConverter.GetBytes((ushort) (IPAddress.HostToNetworkOrder((ushort) 0) >> 16)); - memoryStream.Write(data, 0, data.Length); - - byte[] dataToHash = memoryStream.ToArray(); - Trace.WriteLine(String.Format("Data to hash: {0}", DnsHelpers.DumpArrayToString(dataToHash))); - byte[] mac = _hmac.ComputeHash(dataToHash); - Trace.WriteLine(String.Format("hash: {0}", DnsHelpers.DumpArrayToString(mac))); - - dnsQueryRequest.AdditionalRRecords.Add(new TSigRecord(_name, _algorithimName, RCode.NoError, _fudge, dnsQueryRequest.TransactionID, new byte[] { }, mac, signDateTime)); - - return dnsQueryRequest; - } - - #endregion - } -} \ No newline at end of file diff --git a/MinecraftClient/Protocol/Dns/Structs.cs b/MinecraftClient/Protocol/Dns/Structs.cs new file mode 100644 index 00000000..0a5b3632 --- /dev/null +++ b/MinecraftClient/Protocol/Dns/Structs.cs @@ -0,0 +1,331 @@ +/* + * http://www.iana.org/assignments/dns-parameters + * + * + * + */ + + +namespace Heijden.DNS +{ + /* + * 3.2.2. TYPE values + * + * TYPE fields are used in resource records. + * Note that these types are a subset of QTYPEs. + * + * TYPE value meaning + */ + public enum Type : ushort + { + A = 1, // a IPV4 host address + NS = 2, // an authoritative name server + MD = 3, // a mail destination (Obsolete - use MX) + MF = 4, // a mail forwarder (Obsolete - use MX) + CNAME = 5, // the canonical name for an alias + SOA = 6, // marks the start of a zone of authority + MB = 7, // a mailbox domain name (EXPERIMENTAL) + MG = 8, // a mail group member (EXPERIMENTAL) + MR = 9, // a mail rename domain name (EXPERIMENTAL) + NULL = 10, // a null RR (EXPERIMENTAL) + 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 + + RP = 17, // The Responsible Person rfc1183 + AFSDB = 18, // AFS Data Base location + X25 = 19, // X.25 address rfc1183 + ISDN = 20, // ISDN address rfc1183 + RT = 21, // The Route Through rfc1183 + + NSAP = 22, // Network service access point address rfc1706 + NSAPPTR = 23, // Obsolete, rfc1348 + + SIG = 24, // Cryptographic public key signature rfc2931 / rfc2535 + KEY = 25, // Public key as used in DNSSEC rfc2535 + + PX = 26, // Pointer to X.400/RFC822 mail mapping information rfc2163 + + GPOS = 27, // Geographical position rfc1712 (obsolete) + + AAAA = 28, // a IPV6 host address, rfc3596 + + LOC = 29, // Location information rfc1876 + + NXT = 30, // Next Domain, Obsolete rfc2065 / rfc2535 + + EID = 31, // *** Endpoint Identifier (Patton) + NIMLOC = 32, // *** Nimrod Locator (Patton) + + SRV = 33, // Location of services rfc2782 + + ATMA = 34, // *** ATM Address (Dobrowski) + + NAPTR = 35, // The Naming Authority Pointer rfc3403 + + KX = 36, // Key Exchange Delegation Record rfc2230 + + CERT = 37, // *** CERT RFC2538 + + A6 = 38, // IPv6 address rfc3363 (rfc2874 rfc3226) + DNAME = 39, // A way to provide aliases for a whole domain, not just a single domain name as with CNAME. rfc2672 + + SINK = 40, // *** SINK Eastlake + OPT = 41, // *** OPT RFC2671 + + APL = 42, // *** APL [RFC3123] + + DS = 43, // Delegation Signer rfc3658 + + SSHFP = 44, // SSH Key Fingerprint rfc4255 + IPSECKEY = 45, // IPSECKEY rfc4025 + RRSIG = 46, // RRSIG rfc3755 + NSEC = 47, // NSEC rfc3755 + DNSKEY = 48, // DNSKEY 3755 + DHCID = 49, // DHCID rfc4701 + + NSEC3 = 50, // NSEC3 rfc5155 + NSEC3PARAM = 51, // NSEC3PARAM rfc5155 + + HIP = 55, // Host Identity Protocol [RFC-ietf-hip-dns-09.txt] + + SPF = 99, // SPF rfc4408 + + UINFO = 100, // *** IANA-Reserved + UID = 101, // *** IANA-Reserved + GID = 102, // *** IANA-Reserved + UNSPEC = 103, // *** IANA-Reserved + + TKEY = 249, // Transaction key rfc2930 + TSIG = 250, // Transaction signature rfc2845 + + TA=32768, // DNSSEC Trust Authorities [Weiler] 13 December 2005 + DLV=32769 // DNSSEC Lookaside Validation [RFC4431] + } + + /* + * 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: + * + * QTYPE value meaning + */ + public enum QType : ushort + { + A = Type.A, // a IPV4 host address + NS = Type.NS, // an authoritative name server + MD = Type.MD, // a mail destination (Obsolete - use MX) + MF = Type.MF, // a mail forwarder (Obsolete - use MX) + CNAME = Type.CNAME, // the canonical name for an alias + SOA = Type.SOA, // marks the start of a zone of authority + MB = Type.MB, // a mailbox domain name (EXPERIMENTAL) + MG = Type.MG, // a mail group member (EXPERIMENTAL) + MR = Type.MR, // a mail rename domain name (EXPERIMENTAL) + NULL = Type.NULL, // a null RR (EXPERIMENTAL) + WKS = Type.WKS, // a well known service description + PTR = Type.PTR, // a domain name pointer + HINFO = Type.HINFO, // host information + MINFO = Type.MINFO, // mailbox or mail list information + MX = Type.MX, // mail exchange + TXT = Type.TXT, // text strings + + RP = Type.RP, // The Responsible Person rfc1183 + AFSDB = Type.AFSDB, // AFS Data Base location + X25 = Type.X25, // X.25 address rfc1183 + ISDN = Type.ISDN, // ISDN address rfc1183 + RT = Type.RT, // The Route Through rfc1183 + + NSAP = Type.NSAP, // Network service access point address rfc1706 + NSAP_PTR = Type.NSAPPTR, // Obsolete, rfc1348 + + SIG = Type.SIG, // Cryptographic public key signature rfc2931 / rfc2535 + KEY = Type.KEY, // Public key as used in DNSSEC rfc2535 + + PX = Type.PX, // Pointer to X.400/RFC822 mail mapping information rfc2163 + + GPOS = Type.GPOS, // Geographical position rfc1712 (obsolete) + + AAAA = Type.AAAA, // a IPV6 host address + + LOC = Type.LOC, // Location information rfc1876 + + NXT = Type.NXT, // Obsolete rfc2065 / rfc2535 + + EID = Type.EID, // *** Endpoint Identifier (Patton) + NIMLOC = Type.NIMLOC,// *** Nimrod Locator (Patton) + + SRV = Type.SRV, // Location of services rfc2782 + + ATMA = Type.ATMA, // *** ATM Address (Dobrowski) + + NAPTR = Type.NAPTR, // The Naming Authority Pointer rfc3403 + + KX = Type.KX, // Key Exchange Delegation Record rfc2230 + + CERT = Type.CERT, // *** CERT RFC2538 + + A6 = Type.A6, // IPv6 address rfc3363 + DNAME = Type.DNAME, // A way to provide aliases for a whole domain, not just a single domain name as with CNAME. rfc2672 + + SINK = Type.SINK, // *** SINK Eastlake + OPT = Type.OPT, // *** OPT RFC2671 + + APL = Type.APL, // *** APL [RFC3123] + + DS = Type.DS, // Delegation Signer rfc3658 + + SSHFP = Type.SSHFP, // *** SSH Key Fingerprint RFC-ietf-secsh-dns + IPSECKEY = Type.IPSECKEY, // rfc4025 + RRSIG = Type.RRSIG, // *** RRSIG RFC-ietf-dnsext-dnssec-2535 + NSEC = Type.NSEC, // *** NSEC RFC-ietf-dnsext-dnssec-2535 + DNSKEY = Type.DNSKEY,// *** DNSKEY RFC-ietf-dnsext-dnssec-2535 + DHCID = Type.DHCID, // rfc4701 + + NSEC3 = Type.NSEC3, // RFC5155 + NSEC3PARAM = Type.NSEC3PARAM, // RFC5155 + + HIP = Type.HIP, // RFC-ietf-hip-dns-09.txt + + SPF = Type.SPF, // RFC4408 + UINFO = Type.UINFO, // *** IANA-Reserved + UID = Type.UID, // *** IANA-Reserved + GID = Type.GID, // *** IANA-Reserved + UNSPEC = Type.UNSPEC,// *** IANA-Reserved + + TKEY = Type.TKEY, // Transaction key rfc2930 + TSIG = Type.TSIG, // Transaction signature rfc2845 + + IXFR = 251, // incremental transfer [RFC1995] + AXFR = 252, // transfer of an entire zone [RFC1035] + MAILB = 253, // mailbox-related RRs (MB, MG or MR) [RFC1035] + MAILA = 254, // mail agent RRs (Obsolete - see MX) [RFC1035] + ANY = 255, // A request for all records [RFC1035] + + TA = Type.TA, // DNSSEC Trust Authorities [Weiler] 13 December 2005 + DLV = Type.DLV // DNSSEC Lookaside Validation [RFC4431] + } + /* + * 3.2.4. CLASS values + * + * CLASS fields appear in resource records. The following CLASS mnemonics + *and values are defined: + * + * CLASS value meaning + */ + public enum Class : ushort + { + 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: + * + * QCLASS value meaning + */ + public enum QClass : ushort + { + IN = Class.IN, // the Internet + CS = Class.CS, // the CSNET class (Obsolete - used only for examples in some obsolete RFCs) + CH = Class.CH, // the CHAOS class + HS = Class.HS, // Hesiod [Dyer 87] + + ANY = 255 // any class + } + + /* +RCODE Response code - this 4 bit field is set as part of + responses. The values have the following + interpretation: + */ + public enum RCode + { + NoError = 0, // No Error [RFC1035] + FormErr = 1, // Format Error [RFC1035] + ServFail = 2, // Server Failure [RFC1035] + NXDomain = 3, // Non-Existent Domain [RFC1035] + NotImp = 4, // Not Implemented [RFC1035] + Refused = 5, // Query Refused [RFC1035] + YXDomain = 6, // Name Exists when it should not [RFC2136] + YXRRSet = 7, // RR Set Exists when it should not [RFC2136] + NXRRSet = 8, // RR Set that should exist does not [RFC2136] + NotAuth = 9, // Server Not Authoritative for zone [RFC2136] + NotZone = 10, // Name not contained in zone [RFC2136] + + RESERVED11 = 11, // Reserved + RESERVED12 = 12, // Reserved + RESERVED13 = 13, // Reserved + RESERVED14 = 14, // Reserved + RESERVED15 = 15, // Reserved + + BADVERSSIG = 16, // Bad OPT Version [RFC2671] + // TSIG Signature Failure [RFC2845] + BADKEY = 17, // Key not recognized [RFC2845] + BADTIME = 18, // Signature out of time window [RFC2845] + BADMODE = 19, // Bad TKEY Mode [RFC2930] + BADNAME = 20, // Duplicate key name [RFC2930] + BADALG = 21, // Algorithm not supported [RFC2930] + BADTRUNC = 22 // Bad Truncation [RFC4635] + /* + 23-3840 available for assignment + 0x0016-0x0F00 + 3841-4095 Private Use + 0x0F01-0x0FFF + 4096-65535 available for assignment + 0x1000-0xFFFF + */ + + } + + /* +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 + */ + public enum OPCode + { + Query = 0, // a standard query (QUERY) + IQUERY = 1, // OpCode Retired (previously IQUERY - No further [RFC3425] + // assignment of this code available) + Status = 2, // a server status request (STATUS) RFC1035 + RESERVED3 = 3, // IANA + + Notify = 4, // RFC1996 + Update = 5, // RFC2136 + + RESERVED6 = 6, + RESERVED7 = 7, + RESERVED8 = 8, + RESERVED9 = 9, + RESERVED10 = 10, + RESERVED11 = 11, + RESERVED12 = 12, + RESERVED13 = 13, + RESERVED14 = 14, + RESERVED15 = 15, + } + + public enum TransportType + { + Udp, + Tcp + } +} diff --git a/MinecraftClient/Protocol/Dns/Tools.cs b/MinecraftClient/Protocol/Dns/Tools.cs deleted file mode 100644 index 006e2abd..00000000 --- a/MinecraftClient/Protocol/Dns/Tools.cs +++ /dev/null @@ -1,221 +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.Text; -using System.Net; -using System.Net.NetworkInformation; -using System.Net.Sockets; - -using DnDns.Enums; - -namespace DnDns -{ - public class Tools - { - /// - /// Look up the port names for the given array of port numbers. - /// - /// An array of port numbers. - /// The protocol type. (TCP or UPD) - /// The name of the port. - public static string GetServByPort(short[] port, ProtocolType proto) - { - StringBuilder sb = new StringBuilder(); - for (int i=0; i < port.Length; i++) - { - sb.Append(GetServByPort(port[i], proto)); - sb.Append(", "); - } - sb.Remove(sb.Length-2,2); - return sb.ToString(); - } - - /// - /// Tests to see if this is running on a Linux or Unix Platform - /// - /// true if unix or linux is detected - public static bool IsPlatformLinuxUnix() - { - int p = (int)Environment.OSVersion.Platform; - - // Test for Unix/Linux OS - if (p == 4 || p == 128) - { - return true; - } - else - { - return false; - } - } - - /// - /// Look up the port name for any given port number. - /// - /// The port number. - /// The protocol type. (TCP or UPD) - /// The name of the port. - public static string GetServByPort(short port, ProtocolType proto) - { - StringBuilder ans = new StringBuilder(); - - switch (proto) - { - case ProtocolType.Tcp: - { - TcpServices tcps; - tcps = (TcpServices)port; - ans.Append(tcps); - ans.Append("("); - ans.Append(port); - ans.Append(")"); - break; - } - case ProtocolType.Udp: - { - UdpServices udps; - udps = (UdpServices)port; - ans.Append(udps); - ans.Append("("); - ans.Append(port); - ans.Append(")"); - break; - } - default: - { - ans.Append("("); - ans.Append(port); - ans.Append(")"); - break; - } - } - return ans.ToString(); - } - - public static string DiscoverUnixDnsServerAddress() - { - if (System.IO.File.Exists("/etc/resolv.conf")) - { - using (System.IO.StreamReader sr = new System.IO.StreamReader("/etc/resolv.conf")) - { - while (!sr.EndOfStream) - { - string line = sr.ReadLine().TrimStart(); - - if (line.StartsWith("nameserver") && line.Length > 11) - { - line = line.Substring(10).Trim(); - if (!string.IsNullOrEmpty(line)) - { - sr.Close(); - return line; - } - } - } - sr.Close(); - } - } - return string.Empty; - } - - public static IPAddressCollection DiscoverDnsServerAddresses() - { - NetworkInterface[] arrNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); - - foreach (NetworkInterface objNetworkInterface in arrNetworkInterfaces) - { - if ( - (objNetworkInterface.OperationalStatus == OperationalStatus.Up) && - (objNetworkInterface.Speed > 0) && - (objNetworkInterface.NetworkInterfaceType != NetworkInterfaceType.Loopback) && - (objNetworkInterface.NetworkInterfaceType != NetworkInterfaceType.Tunnel) - ) - { - IPAddressCollection candidate = objNetworkInterface.GetIPProperties().DnsAddresses; - bool found = false; - foreach (IPAddress addr in candidate) - { - // Make this collection contains IPv4 addresses only - if (addr.AddressFamily == AddressFamily.InterNetwork) - found = true; - } - - if (found) - return candidate; - } - } - - return null; - } - - //public static uint ByteToUInt(byte[] theByte) - //{ - // uint l = 0; - - // for (int i = 0; i < theByte.Length; i++) - // { - // l += (uint)theByte[(theByte.Length - i) - 1] << i * 8; - // } - - // return l; - //} - - // Use BitConverter.GetBytes() - //public static byte[] IntToByteArray(uint theInt) - //{ - // byte[] byteArray = new byte[4]; - // int i; - // int shift; - - // for (i = 0, shift = 24; i < 4; i++, shift -= 8) - // byteArray[i] = (byte)(0xFF & (theInt >> shift)); - - // return byteArray; - //} - - // use BitConverter.GetBytes() - //public static byte[] UshortToByteArray(ushort theShort) - //{ - // byte[] byteArray = new byte[2]; - // int i; - // int shift; - - // for (i = 0, shift = 16; i < 2; i++, shift -= 8) - // byteArray[i] = (byte)(0xFF & (theShort >> shift)); - - // return byteArray; - //} - } -} \ No newline at end of file diff --git a/MinecraftClient/config/README.txt b/MinecraftClient/config/README.txt index cac53012..c763b597 100644 --- a/MinecraftClient/config/README.txt +++ b/MinecraftClient/config/README.txt @@ -277,14 +277,14 @@ Libraries Minecraft Console Client also borrows code from the following libraries: - -------------------------------------------------------------- - Name Purpose Author License - -------------------------------------------------------------- - Biko Proxy handling Benton Stark MIT - BouncyCastle CFB-8 AES on Mono The Legion MIT - DnDns DNS SRV Lookup J. Montgomery MIT - DotNetZip Zlib compression Dino Chiesa MS-PL - -------------------------------------------------------------- + ----------------------------------------------------------------- + Name Purpose Author License + ----------------------------------------------------------------- + Biko Proxy handling Benton Stark MIT + BouncyCastle CFB-8 AES on Mono The Legion MIT + Heijden.Dns DNS SRV Lookup Geoffrey Huntley MIT + DotNetZip Zlib compression Dino Chiesa MS-PL + ----------------------------------------------------------------- ========= Support