1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright (c) 2003-2012 by AG-Software * 3 * All Rights Reserved. * 4 * Contact information for AG-Software is available at http://www.ag-software.de * 5 * * 6 * Licence: * 7 * The agsXMPP SDK is released under a dual licence * 8 * agsXMPP can be used under either of two licences * 9 * * 10 * A commercial licence which is probably the most appropriate for commercial * 11 * corporate use and closed source projects. * 12 * * 13 * The GNU Public License (GPL) is probably most appropriate for inclusion in * 14 * other open source projects. * 15 * * 16 * See README.html for details. * 17 * * 18 * For general enquiries visit our website at: * 19 * http://www.ag-software.de * 20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 21 22 // 23 // Bdev.Net.Dns by Rob Philpott, Big Developments Ltd. Please send all bugs/enhancements to 24 // rob@bigdevelopments.co.uk This file and the code contained within is freeware and may be 25 // distributed and edited without restriction. 26 // 27 28 using System; 29 30 namespace agsXMPP.Net.Dns 31 { 32 /// <summary> 33 /// Represents a Resource Record as detailed in RFC1035 4.1.3 34 /// </summary> 35 public class ResourceRecord 36 { 37 // private, constructor initialised fields 38 private readonly string _domain; 39 private readonly DnsType _dnsType; 40 private readonly DnsClass _dnsClass; 41 private readonly int _Ttl; 42 private readonly RecordBase _record; 43 44 // read only properties applicable for all records 45 public string Domain 46 { 47 get { return _domain; } 48 } 49 50 public DnsType Type 51 { 52 get { return _dnsType; } 53 } 54 55 public DnsClass Class 56 { 57 get { return _dnsClass; } 58 } 59 60 public int Ttl 61 { 62 get { return _Ttl; } 63 } 64 65 public RecordBase Record 66 { 67 get { return _record; } 68 } 69 70 /// <summary> 71 /// Construct a resource record from a pointer to a byte array 72 /// </summary> 73 /// <param name="pointer">the position in the byte array of the record</param> ResourceRecord(Pointer pointer)74 internal ResourceRecord(Pointer pointer) 75 { 76 // extract the domain, question type, question class and Ttl 77 _domain = pointer.ReadDomain(); 78 _dnsType = (DnsType) pointer.ReadShort(); 79 _dnsClass = (DnsClass) pointer.ReadShort(); 80 _Ttl = pointer.ReadInt(); 81 82 // the next short is the record length, we only use it for unrecognised record types 83 int recordLength = pointer.ReadShort(); 84 85 // and create the appropriate RDATA record based on the dnsType 86 switch (_dnsType) 87 { 88 case DnsType.SRV: 89 _record = new SRVRecord(pointer); 90 break; 91 92 default: 93 { 94 // move the pointer over this unrecognised record 95 pointer.Position += recordLength; 96 break; 97 } 98 } 99 } 100 } 101 102 // Answers, Name Servers and Additional Records all share the same RR format 103 public class Answer : ResourceRecord 104 { Answer(Pointer pointer)105 internal Answer(Pointer pointer) : base(pointer) {} 106 } 107 108 public class NameServer : ResourceRecord 109 { NameServer(Pointer pointer)110 internal NameServer(Pointer pointer) : base(pointer) {} 111 } 112 113 public class AdditionalRecord : ResourceRecord 114 { AdditionalRecord(Pointer pointer)115 internal AdditionalRecord(Pointer pointer) : base(pointer) {} 116 } 117 }