MailSharp / MailSharp.DNS / Records / RecordKX.cs
Code · 46 lines · 1646 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46/*
 * http://tools.ietf.org/rfc/rfc2230.txt
 * 
 * 3.1 KX RDATA format

   The KX DNS record has the following RDATA format:

    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                  PREFERENCE                   |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    /                   EXCHANGER                   /
    /                                               /
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

   where:

   PREFERENCE      A 16 bit non-negative integer which specifies the
                   preference given to this RR among other KX records
                   at the same owner.  Lower values are preferred.

   EXCHANGER       A <domain-name> which specifies a host willing to
                   act as a mail exchange for the owner name.

   KX records MUST cause type A additional section processing for the
   host specified by EXCHANGER.  In the event that the host processing
   the DNS transaction supports IPv6, KX records MUST also cause type
   AAAA additional section processing.

   The KX RDATA field MUST NOT be compressed.

 */
using MailSharp.DNS.Records;

namespace MailSharp.DNS.Records;

public record RecordKX(RecordReader rr) : DnsRecord(rr), IComparable<RecordKX>
{
	public ushort Preference { get; } = rr.ReadUInt16();
	public string Exchange { get; } = rr.ReadDomainName();

	public override string ToString() => $"{Preference} {Exchange}";
	public int CompareTo(RecordKX? other) =>
		other is null ? 1 :
		Preference != other.Preference ? Preference.CompareTo(other.Preference) :
		string.Compare(Exchange, other.Exchange, StringComparison.OrdinalIgnoreCase);
}