package dns

import (
	
	
	
	
	
	
)

type (
	// Type is a DNS type.
	Type uint16
	// Class is a DNS class.
	Class uint16
	// Name is a DNS domain name.
	Name string
)

// Packet formats

// Wire constants and supported types.
const (
	// valid RR_Header.Rrtype and Question.qtype

	TypeNone       uint16 = 0
	TypeA          uint16 = 1
	TypeNS         uint16 = 2
	TypeMD         uint16 = 3
	TypeMF         uint16 = 4
	TypeCNAME      uint16 = 5
	TypeSOA        uint16 = 6
	TypeMB         uint16 = 7
	TypeMG         uint16 = 8
	TypeMR         uint16 = 9
	TypeNULL       uint16 = 10
	TypePTR        uint16 = 12
	TypeHINFO      uint16 = 13
	TypeMINFO      uint16 = 14
	TypeMX         uint16 = 15
	TypeTXT        uint16 = 16
	TypeRP         uint16 = 17
	TypeAFSDB      uint16 = 18
	TypeX25        uint16 = 19
	TypeISDN       uint16 = 20
	TypeRT         uint16 = 21
	TypeNSAPPTR    uint16 = 23
	TypeSIG        uint16 = 24
	TypeKEY        uint16 = 25
	TypePX         uint16 = 26
	TypeGPOS       uint16 = 27
	TypeAAAA       uint16 = 28
	TypeLOC        uint16 = 29
	TypeNXT        uint16 = 30
	TypeEID        uint16 = 31
	TypeNIMLOC     uint16 = 32
	TypeSRV        uint16 = 33
	TypeATMA       uint16 = 34
	TypeNAPTR      uint16 = 35
	TypeKX         uint16 = 36
	TypeCERT       uint16 = 37
	TypeDNAME      uint16 = 39
	TypeOPT        uint16 = 41 // EDNS
	TypeAPL        uint16 = 42
	TypeDS         uint16 = 43
	TypeSSHFP      uint16 = 44
	TypeIPSECKEY   uint16 = 45
	TypeRRSIG      uint16 = 46
	TypeNSEC       uint16 = 47
	TypeDNSKEY     uint16 = 48
	TypeDHCID      uint16 = 49
	TypeNSEC3      uint16 = 50
	TypeNSEC3PARAM uint16 = 51
	TypeTLSA       uint16 = 52
	TypeSMIMEA     uint16 = 53
	TypeHIP        uint16 = 55
	TypeNINFO      uint16 = 56
	TypeRKEY       uint16 = 57
	TypeTALINK     uint16 = 58
	TypeCDS        uint16 = 59
	TypeCDNSKEY    uint16 = 60
	TypeOPENPGPKEY uint16 = 61
	TypeCSYNC      uint16 = 62
	TypeZONEMD     uint16 = 63
	TypeSVCB       uint16 = 64
	TypeHTTPS      uint16 = 65
	TypeSPF        uint16 = 99
	TypeUINFO      uint16 = 100
	TypeUID        uint16 = 101
	TypeGID        uint16 = 102
	TypeUNSPEC     uint16 = 103
	TypeNID        uint16 = 104
	TypeL32        uint16 = 105
	TypeL64        uint16 = 106
	TypeLP         uint16 = 107
	TypeEUI48      uint16 = 108
	TypeEUI64      uint16 = 109
	TypeNXNAME     uint16 = 128
	TypeURI        uint16 = 256
	TypeCAA        uint16 = 257
	TypeAVC        uint16 = 258
	TypeAMTRELAY   uint16 = 260
	TypeRESINFO    uint16 = 261

	TypeTKEY uint16 = 249
	TypeTSIG uint16 = 250

	// valid Question.Qtype only
	TypeIXFR  uint16 = 251
	TypeAXFR  uint16 = 252
	TypeMAILB uint16 = 253
	TypeMAILA uint16 = 254
	TypeANY   uint16 = 255

	TypeTA       uint16 = 32768
	TypeDLV      uint16 = 32769
	TypeReserved uint16 = 65535

	// valid Question.Qclass
	ClassINET   = 1
	ClassCSNET  = 2
	ClassCHAOS  = 3
	ClassHESIOD = 4
	ClassNONE   = 254
	ClassANY    = 255

	// Message Response Codes, see https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
	RcodeSuccess                    = 0  // NoError   - No Error                          [DNS]
	RcodeFormatError                = 1  // FormErr   - Format Error                      [DNS]
	RcodeServerFailure              = 2  // ServFail  - Server Failure                    [DNS]
	RcodeNameError                  = 3  // NXDomain  - Non-Existent Domain               [DNS]
	RcodeNotImplemented             = 4  // NotImp    - Not Implemented                   [DNS]
	RcodeRefused                    = 5  // Refused   - Query Refused                     [DNS]
	RcodeYXDomain                   = 6  // YXDomain  - Name Exists when it should not    [DNS Update]
	RcodeYXRrset                    = 7  // YXRRSet   - RR Set Exists when it should not  [DNS Update]
	RcodeNXRrset                    = 8  // NXRRSet   - RR Set that should exist does not [DNS Update]
	RcodeNotAuth                    = 9  // NotAuth   - Server Not Authoritative for zone [DNS Update]
	RcodeNotZone                    = 10 // NotZone   - Name not contained in zone        [DNS Update/TSIG]
	RcodeStatefulTypeNotImplemented = 11 // DSOTypeNI - DSO-TYPE not implemented          [DNS Stateful Operations] https://www.rfc-editor.org/rfc/rfc8490.html#section-10.2
	RcodeBadSig                     = 16 // BADSIG    - TSIG Signature Failure            [TSIG]  https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3
	RcodeBadVers                    = 16 // BADVERS   - Bad OPT Version                   [EDNS0] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3
	RcodeBadKey                     = 17 // BADKEY    - Key not recognized                [TSIG]
	RcodeBadTime                    = 18 // BADTIME   - Signature out of time window      [TSIG]
	RcodeBadMode                    = 19 // BADMODE   - Bad TKEY Mode                     [TKEY]
	RcodeBadName                    = 20 // BADNAME   - Duplicate key name                [TKEY]
	RcodeBadAlg                     = 21 // BADALG    - Algorithm not supported           [TKEY]
	RcodeBadTrunc                   = 22 // BADTRUNC  - Bad Truncation                    [TSIG]
	RcodeBadCookie                  = 23 // BADCOOKIE - Bad/missing Server Cookie         [DNS Cookies]

	// Message Opcodes. There is no 3.
	OpcodeQuery    = 0
	OpcodeIQuery   = 1
	OpcodeStatus   = 2
	OpcodeNotify   = 4
	OpcodeUpdate   = 5
	OpcodeStateful = 6
)

// Used in ZONEMD https://tools.ietf.org/html/rfc8976
const (
	ZoneMDSchemeSimple = 1

	ZoneMDHashAlgSHA384 = 1
	ZoneMDHashAlgSHA512 = 2
)

// Used in IPSEC https://datatracker.ietf.org/doc/html/rfc4025#section-2.3
const (
	IPSECGatewayNone uint8 = iota
	IPSECGatewayIPv4
	IPSECGatewayIPv6
	IPSECGatewayHost
)

// Used in AMTRELAY https://datatracker.ietf.org/doc/html/rfc8777#section-4.2.3
const (
	AMTRELAYNone = IPSECGatewayNone
	AMTRELAYIPv4 = IPSECGatewayIPv4
	AMTRELAYIPv6 = IPSECGatewayIPv6
	AMTRELAYHost = IPSECGatewayHost
)

// Stateful types as defined in RFC 8490.
const (
	StatefulTypeKeepAlive uint16 = iota + 1
	StatefulTypeRetryDelay
	StatefulTypeEncryptionPadding
)

var StatefulTypeToString = map[uint16]string{
	StatefulTypeKeepAlive:         "KeepAlive",
	StatefulTypeRetryDelay:        "RetryDelay",
	StatefulTypeEncryptionPadding: "EncryptionPadding",
}

// Header is the wire format for the DNS packet header.
type Header struct {
	Id                                 uint16
	Bits                               uint16
	Qdcount, Ancount, Nscount, Arcount uint16
}

const (
	headerSize = 12

	// Header.Bits
	_QR = 1 << 15 // query/response (response=1)
	_AA = 1 << 10 // authoritative
	_TC = 1 << 9  // truncated
	_RD = 1 << 8  // recursion desired
	_RA = 1 << 7  // recursion available
	_Z  = 1 << 6  // Z
	_AD = 1 << 5  // authenticated data
	_CD = 1 << 4  // checking disabled
)

// Various constants used in the LOC RR. See RFC 1876.
const (
	LOC_EQUATOR       = 1 << 31 // RFC 1876, Section 2.
	LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2.
	LOC_HOURS         = 60 * 1000
	LOC_DEGREES       = 60 * LOC_HOURS
	LOC_ALTITUDEBASE  = 100000
)

// Different Certificate Types, see RFC 4398, Section 2.1
const (
	CertPKIX = 1 + iota
	CertSPKI
	CertPGP
	CertIPIX
	CertISPKI
	CertIPGP
	CertACPKIX
	CertIACPKIX
	CertURI = 253
	CertOID = 254
)

// CertTypeToString converts the Cert Type to its string representation.
// See RFC 4398 and RFC 6944.
var CertTypeToString = map[uint16]string{
	CertPKIX:    "PKIX",
	CertSPKI:    "SPKI",
	CertPGP:     "PGP",
	CertIPIX:    "IPIX",
	CertISPKI:   "ISPKI",
	CertIPGP:    "IPGP",
	CertACPKIX:  "ACPKIX",
	CertIACPKIX: "IACPKIX",
	CertURI:     "URI",
	CertOID:     "OID",
}

// Prefix for IPv4 encoded as IPv6 address
const ipv4InIPv6Prefix = "::ffff:"

//go:generate go run types_generate.go

// Question holds a DNS question. Usually there is just one. While the
// original DNS RFCs allow multiple questions in the question section of a
// message, in practice it never works. Because most DNS servers see multiple
// questions as an error, it is recommended to only have one question per
// message.
type Question struct {
	Name   string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
	Qtype  uint16
	Qclass uint16
}

func ( *Question) ( int,  map[string]struct{}) int {
	 := domainNameLen(.Name, , , true)
	 += 2 + 2
	return 
}

func ( *Question) () ( string) {
	// prefix with ; (as in dig)
	 = ";" + sprintName(.Name) + "\t"
	 += Class(.Qclass).String() + "\t"
	 += " " + Type(.Qtype).String()
	return 
}

// ANY is a wild card record. See RFC 1035, Section 3.2.3. ANY is named "*" there.
// The ANY records can be (ab)used to create resource records without any rdata, that
// can be used in dynamic update requests. Basic use pattern:
//
//	a := &ANY{RR_Header{
//		Name:   "example.org.",
//		Rrtype: TypeA,
//		Class:  ClassINET,
//	}}
//
// Results in an A record without rdata.
type ANY struct {
	Hdr RR_Header
	// Does not have any rdata.
}

func ( *ANY) () string { return .Hdr.String() }

func (*ANY) ( *zlexer,  string) *ParseError {
	return &ParseError{err: "ANY records do not have a presentation format"}
}

// NULL RR. See RFC 1035.
type NULL struct {
	Hdr  RR_Header
	Data string `dns:"any"`
}

func ( *NULL) () string {
	// There is no presentation format; prefix string with a comment.
	return ";" + .Hdr.String() + .Data
}

func (*NULL) ( *zlexer,  string) *ParseError {
	return &ParseError{err: "NULL records do not have a presentation format"}
}

// NXNAME is a meta record. See https://www.iana.org/go/draft-ietf-dnsop-compact-denial-of-existence-04
// Reference: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
type NXNAME struct {
	Hdr RR_Header
	// Does not have any rdata
}

func ( *NXNAME) () string { return .Hdr.String() }

func (*NXNAME) ( *zlexer,  string) *ParseError {
	return &ParseError{err: "NXNAME records do not have a presentation format"}
}

// CNAME RR. See RFC 1034.
type CNAME struct {
	Hdr    RR_Header
	Target string `dns:"cdomain-name"`
}

func ( *CNAME) () string { return .Hdr.String() + sprintName(.Target) }

// HINFO RR. See RFC 1034.
type HINFO struct {
	Hdr RR_Header
	Cpu string
	Os  string
}

func ( *HINFO) () string {
	return .Hdr.String() + sprintTxt([]string{.Cpu, .Os})
}

// MB RR. See RFC 1035.
type MB struct {
	Hdr RR_Header
	Mb  string `dns:"cdomain-name"`
}

func ( *MB) () string { return .Hdr.String() + sprintName(.Mb) }

// MG RR. See RFC 1035.
type MG struct {
	Hdr RR_Header
	Mg  string `dns:"cdomain-name"`
}

func ( *MG) () string { return .Hdr.String() + sprintName(.Mg) }

// MINFO RR. See RFC 1035.
type MINFO struct {
	Hdr   RR_Header
	Rmail string `dns:"cdomain-name"`
	Email string `dns:"cdomain-name"`
}

func ( *MINFO) () string {
	return .Hdr.String() + sprintName(.Rmail) + " " + sprintName(.Email)
}

// MR RR. See RFC 1035.
type MR struct {
	Hdr RR_Header
	Mr  string `dns:"cdomain-name"`
}

func ( *MR) () string {
	return .Hdr.String() + sprintName(.Mr)
}

// MF RR. See RFC 1035.
type MF struct {
	Hdr RR_Header
	Mf  string `dns:"cdomain-name"`
}

func ( *MF) () string {
	return .Hdr.String() + sprintName(.Mf)
}

// MD RR. See RFC 1035.
type MD struct {
	Hdr RR_Header
	Md  string `dns:"cdomain-name"`
}

func ( *MD) () string {
	return .Hdr.String() + sprintName(.Md)
}

// MX RR. See RFC 1035.
type MX struct {
	Hdr        RR_Header
	Preference uint16
	Mx         string `dns:"cdomain-name"`
}

func ( *MX) () string {
	return .Hdr.String() + strconv.Itoa(int(.Preference)) + " " + sprintName(.Mx)
}

// AFSDB RR. See RFC 1183.
type AFSDB struct {
	Hdr      RR_Header
	Subtype  uint16
	Hostname string `dns:"domain-name"`
}

func ( *AFSDB) () string {
	return .Hdr.String() + strconv.Itoa(int(.Subtype)) + " " + sprintName(.Hostname)
}

// X25 RR. See RFC 1183, Section 3.1.
type X25 struct {
	Hdr         RR_Header
	PSDNAddress string
}

func ( *X25) () string {
	return .Hdr.String() + .PSDNAddress
}

// ISDN RR. See RFC 1183, Section 3.2.
type ISDN struct {
	Hdr        RR_Header
	Address    string
	SubAddress string
}

func ( *ISDN) () string {
	return .Hdr.String() + sprintTxt([]string{.Address, .SubAddress})
}

// RT RR. See RFC 1183, Section 3.3.
type RT struct {
	Hdr        RR_Header
	Preference uint16
	Host       string `dns:"domain-name"` // RFC 3597 prohibits compressing records not defined in RFC 1035.
}

func ( *RT) () string {
	return .Hdr.String() + strconv.Itoa(int(.Preference)) + " " + sprintName(.Host)
}

// NS RR. See RFC 1035.
type NS struct {
	Hdr RR_Header
	Ns  string `dns:"cdomain-name"`
}

func ( *NS) () string {
	return .Hdr.String() + sprintName(.Ns)
}

// PTR RR. See RFC 1035.
type PTR struct {
	Hdr RR_Header
	Ptr string `dns:"cdomain-name"`
}

func ( *PTR) () string {
	return .Hdr.String() + sprintName(.Ptr)
}

// RP RR. See RFC 1138, Section 2.2.
type RP struct {
	Hdr  RR_Header
	Mbox string `dns:"domain-name"`
	Txt  string `dns:"domain-name"`
}

func ( *RP) () string {
	return .Hdr.String() + sprintName(.Mbox) + " " + sprintName(.Txt)
}

// SOA RR. See RFC 1035.
type SOA struct {
	Hdr     RR_Header
	Ns      string `dns:"cdomain-name"`
	Mbox    string `dns:"cdomain-name"`
	Serial  uint32
	Refresh uint32
	Retry   uint32
	Expire  uint32
	Minttl  uint32
}

func ( *SOA) () string {
	return .Hdr.String() + sprintName(.Ns) + " " + sprintName(.Mbox) +
		" " + strconv.FormatInt(int64(.Serial), 10) +
		" " + strconv.FormatInt(int64(.Refresh), 10) +
		" " + strconv.FormatInt(int64(.Retry), 10) +
		" " + strconv.FormatInt(int64(.Expire), 10) +
		" " + strconv.FormatInt(int64(.Minttl), 10)
}

// TXT RR. See RFC 1035.
type TXT struct {
	Hdr RR_Header
	Txt []string `dns:"txt"`
}

func ( *TXT) () string { return .Hdr.String() + sprintTxt(.Txt) }

func sprintName( string) string {
	var  strings.Builder

	for  := 0;  < len(); {
		if [] == '.' {
			if .Len() != 0 {
				.WriteByte('.')
			}
			++
			continue
		}

		,  := nextByte(, )
		if  == 0 {
			// Drop "dangling" incomplete escapes.
			if .Len() == 0 {
				return [:]
			}
			break
		}
		if isDomainNameLabelSpecial() {
			if .Len() == 0 {
				.Grow(len() * 2)
				.WriteString([:])
			}
			.WriteByte('\\')
			.WriteByte()
		} else if  < ' ' ||  > '~' { // unprintable, use \DDD
			if .Len() == 0 {
				.Grow(len() * 2)
				.WriteString([:])
			}
			.WriteString(escapeByte())
		} else {
			if .Len() != 0 {
				.WriteByte()
			}
		}
		 += 
	}
	if .Len() == 0 {
		return 
	}
	return .String()
}

func sprintTxtOctet( string) string {
	var  strings.Builder
	.Grow(2 + len())
	.WriteByte('"')
	for  := 0;  < len(); {
		if +1 < len() && [] == '\\' && [+1] == '.' {
			.WriteString([ : +2])
			 += 2
			continue
		}

		,  := nextByte(, )
		if  == 0 {
			++ // dangling back slash
		} else {
			writeTXTStringByte(&, )
		}
		 += 
	}
	.WriteByte('"')
	return .String()
}

func sprintTxt( []string) string {
	var  strings.Builder
	for ,  := range  {
		.Grow(3 + len())
		if  > 0 {
			.WriteString(` "`)
		} else {
			.WriteByte('"')
		}
		for  := 0;  < len(); {
			,  := nextByte(, )
			if  == 0 {
				break
			}
			writeTXTStringByte(&, )
			 += 
		}
		.WriteByte('"')
	}
	return .String()
}

func writeTXTStringByte( *strings.Builder,  byte) {
	switch {
	case  == '"' ||  == '\\':
		.WriteByte('\\')
		.WriteByte()
	case  < ' ' ||  > '~':
		.WriteString(escapeByte())
	default:
		.WriteByte()
	}
}

const (
	escapedByteSmall = "" +
		`\000\001\002\003\004\005\006\007\008\009` +
		`\010\011\012\013\014\015\016\017\018\019` +
		`\020\021\022\023\024\025\026\027\028\029` +
		`\030\031`
	escapedByteLarge = `\127\128\129` +
		`\130\131\132\133\134\135\136\137\138\139` +
		`\140\141\142\143\144\145\146\147\148\149` +
		`\150\151\152\153\154\155\156\157\158\159` +
		`\160\161\162\163\164\165\166\167\168\169` +
		`\170\171\172\173\174\175\176\177\178\179` +
		`\180\181\182\183\184\185\186\187\188\189` +
		`\190\191\192\193\194\195\196\197\198\199` +
		`\200\201\202\203\204\205\206\207\208\209` +
		`\210\211\212\213\214\215\216\217\218\219` +
		`\220\221\222\223\224\225\226\227\228\229` +
		`\230\231\232\233\234\235\236\237\238\239` +
		`\240\241\242\243\244\245\246\247\248\249` +
		`\250\251\252\253\254\255`
)

// escapeByte returns the \DDD escaping of b which must
// satisfy b < ' ' || b > '~'.
func escapeByte( byte) string {
	if  < ' ' {
		return escapedByteSmall[*4 : *4+4]
	}

	 -= '~' + 1
	// The cast here is needed as b*4 may overflow byte.
	return escapedByteLarge[int()*4 : int()*4+4]
}

// isDomainNameLabelSpecial returns true if
// a domain name label byte should be prefixed
// with an escaping backslash.
func isDomainNameLabelSpecial( byte) bool {
	switch  {
	case '.', ' ', '\'', '@', ';', '(', ')', '"', '\\':
		return true
	}
	return false
}

func nextByte( string,  int) (byte, int) {
	if  >= len() {
		return 0, 0
	}
	if [] != '\\' {
		// not an escape sequence
		return [], 1
	}
	switch len() -  {
	case 1: // dangling escape
		return 0, 0
	case 2, 3: // too short to be \ddd
	default: // maybe \ddd
		if isDDD([+1:]) {
			return dddToByte([+1:]), 4
		}
	}
	// not \ddd, just an RFC 1035 "quoted" character
	return [+1], 2
}

// SPF RR. See RFC 4408, Section 3.1.1.
type SPF struct {
	Hdr RR_Header
	Txt []string `dns:"txt"`
}

func ( *SPF) () string { return .Hdr.String() + sprintTxt(.Txt) }

// AVC RR. See https://www.iana.org/assignments/dns-parameters/AVC/avc-completed-template.
type AVC struct {
	Hdr RR_Header
	Txt []string `dns:"txt"`
}

func ( *AVC) () string { return .Hdr.String() + sprintTxt(.Txt) }

// SRV RR. See RFC 2782.
type SRV struct {
	Hdr      RR_Header
	Priority uint16
	Weight   uint16
	Port     uint16
	Target   string `dns:"domain-name"`
}

func ( *SRV) () string {
	return .Hdr.String() +
		strconv.Itoa(int(.Priority)) + " " +
		strconv.Itoa(int(.Weight)) + " " +
		strconv.Itoa(int(.Port)) + " " + sprintName(.Target)
}

// NAPTR RR. See RFC 2915.
type NAPTR struct {
	Hdr         RR_Header
	Order       uint16
	Preference  uint16
	Flags       string
	Service     string
	Regexp      string
	Replacement string `dns:"domain-name"`
}

func ( *NAPTR) () string {
	return .Hdr.String() +
		strconv.Itoa(int(.Order)) + " " +
		strconv.Itoa(int(.Preference)) + " " +
		"\"" + .Flags + "\" " +
		"\"" + .Service + "\" " +
		"\"" + .Regexp + "\" " +
		.Replacement
}

// CERT RR. See RFC 4398.
type CERT struct {
	Hdr         RR_Header
	Type        uint16
	KeyTag      uint16
	Algorithm   uint8
	Certificate string `dns:"base64"`
}

func ( *CERT) () string {
	var (
		                  bool
		,  string
	)
	if ,  = CertTypeToString[.Type]; ! {
		 = strconv.Itoa(int(.Type))
	}
	if ,  = AlgorithmToString[.Algorithm]; ! {
		 = strconv.Itoa(int(.Algorithm))
	}
	return .Hdr.String() +  +
		" " + strconv.Itoa(int(.KeyTag)) +
		" " +  +
		" " + .Certificate
}

// DNAME RR. See RFC 2672.
type DNAME struct {
	Hdr    RR_Header
	Target string `dns:"domain-name"`
}

func ( *DNAME) () string {
	return .Hdr.String() + sprintName(.Target)
}

// A RR. See RFC 1035.
type A struct {
	Hdr RR_Header
	A   net.IP `dns:"a"`
}

func ( *A) () string {
	if .A == nil {
		return .Hdr.String()
	}
	return .Hdr.String() + .A.String()
}

// AAAA RR. See RFC 3596.
type AAAA struct {
	Hdr  RR_Header
	AAAA net.IP `dns:"aaaa"`
}

func ( *AAAA) () string {
	if .AAAA == nil {
		return .Hdr.String()
	}

	if .AAAA.To4() != nil {
		return .Hdr.String() + ipv4InIPv6Prefix + .AAAA.String()
	}

	return .Hdr.String() + .AAAA.String()
}

// PX RR. See RFC 2163.
type PX struct {
	Hdr        RR_Header
	Preference uint16
	Map822     string `dns:"domain-name"`
	Mapx400    string `dns:"domain-name"`
}

func ( *PX) () string {
	return .Hdr.String() + strconv.Itoa(int(.Preference)) + " " + sprintName(.Map822) + " " + sprintName(.Mapx400)
}

// GPOS RR. See RFC 1712.
type GPOS struct {
	Hdr       RR_Header
	Longitude string
	Latitude  string
	Altitude  string
}

func ( *GPOS) () string {
	return .Hdr.String() + .Longitude + " " + .Latitude + " " + .Altitude
}

// LOC RR. See RFC 1876.
type LOC struct {
	Hdr       RR_Header
	Version   uint8
	Size      uint8
	HorizPre  uint8
	VertPre   uint8
	Latitude  uint32
	Longitude uint32
	Altitude  uint32
}

// cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent
// format and returns a string in m (two decimals for the cm).
func cmToM( uint8) string {
	 :=  & 0xf0 >> 4
	 :=  & 0x0f

	if  < 2 {
		if  == 1 {
			 *= 10
		}

		return fmt.Sprintf("0.%02d", )
	}

	 := fmt.Sprintf("%d", )
	for  > 2 {
		 += "0"
		--
	}
	return 
}

func ( *LOC) () string {
	 := .Hdr.String()

	 := .Latitude
	 := "N"
	if  > LOC_EQUATOR {
		 =  - LOC_EQUATOR
	} else {
		 = "S"
		 = LOC_EQUATOR - 
	}
	 :=  / LOC_DEGREES
	 =  % LOC_DEGREES
	 :=  / LOC_HOURS
	 =  % LOC_HOURS
	 += fmt.Sprintf("%02d %02d %0.3f %s ", , , float64()/1000, )

	 := .Longitude
	 := "E"
	if  > LOC_PRIMEMERIDIAN {
		 =  - LOC_PRIMEMERIDIAN
	} else {
		 = "W"
		 = LOC_PRIMEMERIDIAN - 
	}
	 =  / LOC_DEGREES
	 =  % LOC_DEGREES
	 =  / LOC_HOURS
	 =  % LOC_HOURS
	 += fmt.Sprintf("%02d %02d %0.3f %s ", , , float64()/1000, )

	 := float64(.Altitude) / 100
	 -= LOC_ALTITUDEBASE
	if .Altitude%100 != 0 {
		 += fmt.Sprintf("%.2fm ", )
	} else {
		 += fmt.Sprintf("%.0fm ", )
	}

	 += cmToM(.Size) + "m "
	 += cmToM(.HorizPre) + "m "
	 += cmToM(.VertPre) + "m"
	return 
}

// SIG RR. See RFC 2535. The SIG RR is identical to RRSIG and nowadays only used for SIG(0), See RFC 2931.
type SIG struct {
	RRSIG
}

// RRSIG RR. See RFC 4034 and RFC 3755.
type RRSIG struct {
	Hdr         RR_Header
	TypeCovered uint16
	Algorithm   uint8
	Labels      uint8
	OrigTtl     uint32
	Expiration  uint32
	Inception   uint32
	KeyTag      uint16
	SignerName  string `dns:"domain-name"`
	Signature   string `dns:"base64"`
}

func ( *RRSIG) () string {
	 := .Hdr.String()
	 += Type(.TypeCovered).String()
	 += " " + strconv.Itoa(int(.Algorithm)) +
		" " + strconv.Itoa(int(.Labels)) +
		" " + strconv.FormatInt(int64(.OrigTtl), 10) +
		" " + TimeToString(.Expiration) +
		" " + TimeToString(.Inception) +
		" " + strconv.Itoa(int(.KeyTag)) +
		" " + sprintName(.SignerName) +
		" " + .Signature
	return 
}

// NXT RR. See RFC 2535.
type NXT struct {
	NSEC
}

// NSEC RR. See RFC 4034 and RFC 3755.
type NSEC struct {
	Hdr        RR_Header
	NextDomain string   `dns:"domain-name"`
	TypeBitMap []uint16 `dns:"nsec"`
}

func ( *NSEC) () string {
	 := .Hdr.String() + sprintName(.NextDomain)
	for ,  := range .TypeBitMap {
		 += " " + Type().String()
	}
	return 
}

func ( *NSEC) ( int,  map[string]struct{}) int {
	 := .Hdr.len(, )
	 += domainNameLen(.NextDomain, +, , false)
	 += typeBitMapLen(.TypeBitMap)
	return 
}

// DLV RR. See RFC 4431.
type DLV struct{ DS }

// CDS RR. See RFC 7344.
type CDS struct{ DS }

// DS RR. See RFC 4034 and RFC 3658.
type DS struct {
	Hdr        RR_Header
	KeyTag     uint16
	Algorithm  uint8
	DigestType uint8
	Digest     string `dns:"hex"`
}

func ( *DS) () string {
	return .Hdr.String() + strconv.Itoa(int(.KeyTag)) +
		" " + strconv.Itoa(int(.Algorithm)) +
		" " + strconv.Itoa(int(.DigestType)) +
		" " + strings.ToUpper(.Digest)
}

// KX RR. See RFC 2230.
type KX struct {
	Hdr        RR_Header
	Preference uint16
	Exchanger  string `dns:"domain-name"`
}

func ( *KX) () string {
	return .Hdr.String() + strconv.Itoa(int(.Preference)) +
		" " + sprintName(.Exchanger)
}

// TA RR. See http://www.watson.org/~weiler/INI1999-19.pdf.
type TA struct {
	Hdr        RR_Header
	KeyTag     uint16
	Algorithm  uint8
	DigestType uint8
	Digest     string `dns:"hex"`
}

func ( *TA) () string {
	return .Hdr.String() + strconv.Itoa(int(.KeyTag)) +
		" " + strconv.Itoa(int(.Algorithm)) +
		" " + strconv.Itoa(int(.DigestType)) +
		" " + strings.ToUpper(.Digest)
}

// TALINK RR. See https://www.iana.org/assignments/dns-parameters/TALINK/talink-completed-template.
type TALINK struct {
	Hdr          RR_Header
	PreviousName string `dns:"domain-name"`
	NextName     string `dns:"domain-name"`
}

func ( *TALINK) () string {
	return .Hdr.String() +
		sprintName(.PreviousName) + " " + sprintName(.NextName)
}

// SSHFP RR. See RFC 4255.
type SSHFP struct {
	Hdr         RR_Header
	Algorithm   uint8
	Type        uint8
	FingerPrint string `dns:"hex"`
}

func ( *SSHFP) () string {
	return .Hdr.String() + strconv.Itoa(int(.Algorithm)) +
		" " + strconv.Itoa(int(.Type)) +
		" " + strings.ToUpper(.FingerPrint)
}

// KEY RR. See RFC 2535.
type KEY struct {
	DNSKEY
}

// CDNSKEY RR. See RFC 7344.
type CDNSKEY struct {
	DNSKEY
}

// DNSKEY RR. See RFC 4034 and RFC 3755.
type DNSKEY struct {
	Hdr       RR_Header
	Flags     uint16
	Protocol  uint8
	Algorithm uint8
	PublicKey string `dns:"base64"`
}

func ( *DNSKEY) () string {
	return .Hdr.String() + strconv.Itoa(int(.Flags)) +
		" " + strconv.Itoa(int(.Protocol)) +
		" " + strconv.Itoa(int(.Algorithm)) +
		" " + .PublicKey
}

// IPSECKEY RR. See RFC 4025.
type IPSECKEY struct {
	Hdr         RR_Header
	Precedence  uint8
	GatewayType uint8
	Algorithm   uint8
	GatewayAddr net.IP `dns:"-"` // packing/unpacking/parsing/etc handled together with GatewayHost
	GatewayHost string `dns:"ipsechost"`
	PublicKey   string `dns:"base64"`
}

func ( *IPSECKEY) () string {
	var  string
	switch .GatewayType {
	case IPSECGatewayIPv4, IPSECGatewayIPv6:
		 = .GatewayAddr.String()
	case IPSECGatewayHost:
		 = .GatewayHost
	case IPSECGatewayNone:
		fallthrough
	default:
		 = "."
	}

	return .Hdr.String() + strconv.Itoa(int(.Precedence)) +
		" " + strconv.Itoa(int(.GatewayType)) +
		" " + strconv.Itoa(int(.Algorithm)) +
		" " +  +
		" " + .PublicKey
}

// AMTRELAY RR. See RFC 8777.
type AMTRELAY struct {
	Hdr         RR_Header
	Precedence  uint8
	GatewayType uint8  // discovery is packed in here at bit 0x80
	GatewayAddr net.IP `dns:"-"` // packing/unpacking/parsing/etc handled together with GatewayHost
	GatewayHost string `dns:"amtrelayhost"`
}

func ( *AMTRELAY) () string {
	var  string
	switch .GatewayType & 0x7f {
	case AMTRELAYIPv4, AMTRELAYIPv6:
		 = .GatewayAddr.String()
	case AMTRELAYHost:
		 = .GatewayHost
	case AMTRELAYNone:
		fallthrough
	default:
		 = "."
	}
	 := "0"
	if .GatewayType&0x80 == 0x80 {
		 = "1"
	}

	return .Hdr.String() + strconv.Itoa(int(.Precedence)) +
		" " +  +
		" " + strconv.Itoa(int(.GatewayType&0x7f)) +
		" " + 
}

// RKEY RR. See https://www.iana.org/assignments/dns-parameters/RKEY/rkey-completed-template.
type RKEY struct {
	Hdr       RR_Header
	Flags     uint16
	Protocol  uint8
	Algorithm uint8
	PublicKey string `dns:"base64"`
}

func ( *RKEY) () string {
	return .Hdr.String() + strconv.Itoa(int(.Flags)) +
		" " + strconv.Itoa(int(.Protocol)) +
		" " + strconv.Itoa(int(.Algorithm)) +
		" " + .PublicKey
}

// NSAPPTR RR. See RFC 1348.
type NSAPPTR struct {
	Hdr RR_Header
	Ptr string `dns:"domain-name"`
}

func ( *NSAPPTR) () string { return .Hdr.String() + sprintName(.Ptr) }

// NSEC3 RR. See RFC 5155.
type NSEC3 struct {
	Hdr        RR_Header
	Hash       uint8
	Flags      uint8
	Iterations uint16
	SaltLength uint8
	Salt       string `dns:"size-hex:SaltLength"`
	HashLength uint8
	NextDomain string   `dns:"size-base32:HashLength"`
	TypeBitMap []uint16 `dns:"nsec"`
}

func ( *NSEC3) () string {
	 := .Hdr.String()
	 += strconv.Itoa(int(.Hash)) +
		" " + strconv.Itoa(int(.Flags)) +
		" " + strconv.Itoa(int(.Iterations)) +
		" " + saltToString(.Salt) +
		" " + .NextDomain
	for ,  := range .TypeBitMap {
		 += " " + Type().String()
	}
	return 
}

func ( *NSEC3) ( int,  map[string]struct{}) int {
	 := .Hdr.len(, )
	 += 6 + len(.Salt)/2 + 1 + len(.NextDomain) + 1
	 += typeBitMapLen(.TypeBitMap)
	return 
}

// NSEC3PARAM RR. See RFC 5155.
type NSEC3PARAM struct {
	Hdr        RR_Header
	Hash       uint8
	Flags      uint8
	Iterations uint16
	SaltLength uint8
	Salt       string `dns:"size-hex:SaltLength"`
}

func ( *NSEC3PARAM) () string {
	 := .Hdr.String()
	 += strconv.Itoa(int(.Hash)) +
		" " + strconv.Itoa(int(.Flags)) +
		" " + strconv.Itoa(int(.Iterations)) +
		" " + saltToString(.Salt)
	return 
}

// TKEY RR. See RFC 2930.
type TKEY struct {
	Hdr        RR_Header
	Algorithm  string `dns:"domain-name"`
	Inception  uint32
	Expiration uint32
	Mode       uint16
	Error      uint16
	KeySize    uint16
	Key        string `dns:"size-hex:KeySize"`
	OtherLen   uint16
	OtherData  string `dns:"size-hex:OtherLen"`
}

// TKEY has no official presentation format, but this will suffice.
func ( *TKEY) () string {
	 := ";" + .Hdr.String() +
		" " + .Algorithm +
		" " + TimeToString(.Inception) +
		" " + TimeToString(.Expiration) +
		" " + strconv.Itoa(int(.Mode)) +
		" " + strconv.Itoa(int(.Error)) +
		" " + strconv.Itoa(int(.KeySize)) +
		" " + .Key +
		" " + strconv.Itoa(int(.OtherLen)) +
		" " + .OtherData
	return 
}

// RFC3597 represents an unknown/generic RR. See RFC 3597.
type RFC3597 struct {
	Hdr   RR_Header
	Rdata string `dns:"hex"`
}

func ( *RFC3597) () string {
	// Let's call it a hack
	 := rfc3597Header(.Hdr)

	 += "\\# " + strconv.Itoa(len(.Rdata)/2) + " " + .Rdata
	return 
}

func rfc3597Header( RR_Header) string {
	var  string

	 += sprintName(.Name) + "\t"
	 += strconv.FormatInt(int64(.Ttl), 10) + "\t"
	 += "CLASS" + strconv.Itoa(int(.Class)) + "\t"
	 += "TYPE" + strconv.Itoa(int(.Rrtype)) + "\t"
	return 
}

// URI RR. See RFC 7553.
type URI struct {
	Hdr      RR_Header
	Priority uint16
	Weight   uint16
	Target   string `dns:"octet"`
}

// rr.Target to be parsed as a sequence of character encoded octets according to RFC 3986
func ( *URI) () string {
	return .Hdr.String() + strconv.Itoa(int(.Priority)) +
		" " + strconv.Itoa(int(.Weight)) + " " + sprintTxtOctet(.Target)
}

// DHCID RR. See RFC 4701.
type DHCID struct {
	Hdr    RR_Header
	Digest string `dns:"base64"`
}

func ( *DHCID) () string { return .Hdr.String() + .Digest }

// TLSA RR. See RFC 6698.
type TLSA struct {
	Hdr          RR_Header
	Usage        uint8
	Selector     uint8
	MatchingType uint8
	Certificate  string `dns:"hex"`
}

func ( *TLSA) () string {
	return .Hdr.String() +
		strconv.Itoa(int(.Usage)) +
		" " + strconv.Itoa(int(.Selector)) +
		" " + strconv.Itoa(int(.MatchingType)) +
		" " + .Certificate
}

// SMIMEA RR. See RFC 8162.
type SMIMEA struct {
	Hdr          RR_Header
	Usage        uint8
	Selector     uint8
	MatchingType uint8
	Certificate  string `dns:"hex"`
}

func ( *SMIMEA) () string {
	 := .Hdr.String() +
		strconv.Itoa(int(.Usage)) +
		" " + strconv.Itoa(int(.Selector)) +
		" " + strconv.Itoa(int(.MatchingType))

	// Every Nth char needs a space on this output. If we output
	// this as one giant line, we can't read it can in because in some cases
	// the cert length overflows scan.maxTok (2048).
	 := splitN(.Certificate, 1024) // conservative value here
	 += " " + strings.Join(, " ")
	return 
}

// HIP RR. See RFC 8005.
type HIP struct {
	Hdr                RR_Header
	HitLength          uint8
	PublicKeyAlgorithm uint8
	PublicKeyLength    uint16
	Hit                string   `dns:"size-hex:HitLength"`
	PublicKey          string   `dns:"size-base64:PublicKeyLength"`
	RendezvousServers  []string `dns:"domain-name"`
}

func ( *HIP) () string {
	 := .Hdr.String() +
		strconv.Itoa(int(.PublicKeyAlgorithm)) +
		" " + .Hit +
		" " + .PublicKey
	for ,  := range .RendezvousServers {
		 += " " + sprintName()
	}
	return 
}

// NINFO RR. See https://www.iana.org/assignments/dns-parameters/NINFO/ninfo-completed-template.
type NINFO struct {
	Hdr    RR_Header
	ZSData []string `dns:"txt"`
}

func ( *NINFO) () string { return .Hdr.String() + sprintTxt(.ZSData) }

// NID RR. See RFC 6742.
type NID struct {
	Hdr        RR_Header
	Preference uint16
	NodeID     uint64
}

func ( *NID) () string {
	 := .Hdr.String() + strconv.Itoa(int(.Preference))
	 := fmt.Sprintf("%0.16x", .NodeID)
	 += " " + [0:4] + ":" + [4:8] + ":" + [8:12] + ":" + [12:16]
	return 
}

// L32 RR, See RFC 6742.
type L32 struct {
	Hdr        RR_Header
	Preference uint16
	Locator32  net.IP `dns:"a"`
}

func ( *L32) () string {
	if .Locator32 == nil {
		return .Hdr.String() + strconv.Itoa(int(.Preference))
	}
	return .Hdr.String() + strconv.Itoa(int(.Preference)) +
		" " + .Locator32.String()
}

// L64 RR, See RFC 6742.
type L64 struct {
	Hdr        RR_Header
	Preference uint16
	Locator64  uint64
}

func ( *L64) () string {
	 := .Hdr.String() + strconv.Itoa(int(.Preference))
	 := fmt.Sprintf("%0.16X", .Locator64)
	 += " " + [0:4] + ":" + [4:8] + ":" + [8:12] + ":" + [12:16]
	return 
}

// LP RR. See RFC 6742.
type LP struct {
	Hdr        RR_Header
	Preference uint16
	Fqdn       string `dns:"domain-name"`
}

func ( *LP) () string {
	return .Hdr.String() + strconv.Itoa(int(.Preference)) + " " + sprintName(.Fqdn)
}

// EUI48 RR. See RFC 7043.
type EUI48 struct {
	Hdr     RR_Header
	Address uint64 `dns:"uint48"`
}

func ( *EUI48) () string { return .Hdr.String() + euiToString(.Address, 48) }

// EUI64 RR. See RFC 7043.
type EUI64 struct {
	Hdr     RR_Header
	Address uint64
}

func ( *EUI64) () string { return .Hdr.String() + euiToString(.Address, 64) }

// CAA RR. See RFC 6844.
type CAA struct {
	Hdr   RR_Header
	Flag  uint8
	Tag   string
	Value string `dns:"octet"`
}

// rr.Value Is the character-string encoding of the value field as specified in RFC 1035, Section 5.1.
func ( *CAA) () string {
	return .Hdr.String() + strconv.Itoa(int(.Flag)) + " " + .Tag + " " + sprintTxtOctet(.Value)
}

// UID RR. Deprecated, IANA-Reserved.
type UID struct {
	Hdr RR_Header
	Uid uint32
}

func ( *UID) () string { return .Hdr.String() + strconv.FormatInt(int64(.Uid), 10) }

// GID RR. Deprecated, IANA-Reserved.
type GID struct {
	Hdr RR_Header
	Gid uint32
}

func ( *GID) () string { return .Hdr.String() + strconv.FormatInt(int64(.Gid), 10) }

// UINFO RR. Deprecated, IANA-Reserved.
type UINFO struct {
	Hdr   RR_Header
	Uinfo string
}

func ( *UINFO) () string { return .Hdr.String() + sprintTxt([]string{.Uinfo}) }

// EID RR. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt.
type EID struct {
	Hdr      RR_Header
	Endpoint string `dns:"hex"`
}

func ( *EID) () string { return .Hdr.String() + strings.ToUpper(.Endpoint) }

// NIMLOC RR. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt.
type NIMLOC struct {
	Hdr     RR_Header
	Locator string `dns:"hex"`
}

func ( *NIMLOC) () string { return .Hdr.String() + strings.ToUpper(.Locator) }

// OPENPGPKEY RR. See RFC 7929.
type OPENPGPKEY struct {
	Hdr       RR_Header
	PublicKey string `dns:"base64"`
}

func ( *OPENPGPKEY) () string { return .Hdr.String() + .PublicKey }

// CSYNC RR. See RFC 7477.
type CSYNC struct {
	Hdr        RR_Header
	Serial     uint32
	Flags      uint16
	TypeBitMap []uint16 `dns:"nsec"`
}

func ( *CSYNC) () string {
	 := .Hdr.String() + strconv.FormatInt(int64(.Serial), 10) + " " + strconv.Itoa(int(.Flags))

	for ,  := range .TypeBitMap {
		 += " " + Type().String()
	}
	return 
}

func ( *CSYNC) ( int,  map[string]struct{}) int {
	 := .Hdr.len(, )
	 += 4 + 2
	 += typeBitMapLen(.TypeBitMap)
	return 
}

// ZONEMD RR, from draft-ietf-dnsop-dns-zone-digest
type ZONEMD struct {
	Hdr    RR_Header
	Serial uint32
	Scheme uint8
	Hash   uint8
	Digest string `dns:"hex"`
}

func ( *ZONEMD) () string {
	return .Hdr.String() +
		strconv.Itoa(int(.Serial)) +
		" " + strconv.Itoa(int(.Scheme)) +
		" " + strconv.Itoa(int(.Hash)) +
		" " + .Digest
}

// RESINFO RR. See RFC 9606.

type RESINFO struct {
	Hdr RR_Header
	Txt []string `dns:"txt"`
}

func ( *RESINFO) () string { return .Hdr.String() + sprintTxt(.Txt) }

// APL RR. See RFC 3123.
type APL struct {
	Hdr      RR_Header
	Prefixes []APLPrefix `dns:"apl"`
}

// APLPrefix is an address prefix hold by an APL record.
type APLPrefix struct {
	Negation bool
	Network  net.IPNet
}

// String returns presentation form of the APL record.
func ( *APL) () string {
	var  strings.Builder
	.WriteString(.Hdr.String())
	for ,  := range .Prefixes {
		if  > 0 {
			.WriteByte(' ')
		}
		.WriteString(.str())
	}
	return .String()
}

// str returns presentation form of the APL prefix.
func ( *APLPrefix) () string {
	var  strings.Builder
	if .Negation {
		.WriteByte('!')
	}

	switch len(.Network.IP) {
	case net.IPv4len:
		.WriteByte('1')
	case net.IPv6len:
		.WriteByte('2')
	}

	.WriteByte(':')

	switch len(.Network.IP) {
	case net.IPv4len:
		.WriteString(.Network.IP.String())
	case net.IPv6len:
		// add prefix for IPv4-mapped IPv6
		if  := .Network.IP.To4();  != nil {
			.WriteString(ipv4InIPv6Prefix)
		}
		.WriteString(.Network.IP.String())
	}

	.WriteByte('/')

	,  := .Network.Mask.Size()
	.WriteString(strconv.Itoa())

	return .String()
}

// equals reports whether two APL prefixes are identical.
func ( *APLPrefix) ( *APLPrefix) bool {
	return .Negation == .Negation &&
		.Network.IP.Equal(.Network.IP) &&
		bytes.Equal(.Network.Mask, .Network.Mask)
}

// copy returns a copy of the APL prefix.
func ( *APLPrefix) () APLPrefix {
	return APLPrefix{
		Negation: .Negation,
		Network:  copyNet(.Network),
	}
}

// len returns size of the prefix in wire format.
func ( *APLPrefix) () int {
	// 4-byte header and the network address prefix (see Section 4 of RFC 3123)
	,  := .Network.Mask.Size()
	return 4 + (+7)/8
}

// TimeToString translates the RRSIG's incep. and expir. times to the
// string representation used when printing the record.
// It takes serial arithmetic (RFC 1982) into account.
func ( uint32) string {
	 := (int64()-time.Now().Unix())/year68 - 1
	if  < 0 {
		 = 0
	}
	 := time.Unix(int64()-*year68, 0).UTC()
	return .Format("20060102150405")
}

// StringToTime translates the RRSIG's incep. and expir. times from
// string values like "20110403154150" to an 32 bit integer.
// It takes serial arithmetic (RFC 1982) into account.
func ( string) (uint32, error) {
	,  := time.Parse("20060102150405", )
	if  != nil {
		return 0, 
	}
	 := .Unix()/year68 - 1
	if  < 0 {
		 = 0
	}
	return uint32(.Unix() - *year68), nil
}

// saltToString converts a NSECX salt to uppercase and returns "-" when it is empty.
func saltToString( string) string {
	if  == "" {
		return "-"
	}
	return strings.ToUpper()
}

func euiToString( uint64,  int) ( string) {
	switch  {
	case 64:
		 = fmt.Sprintf("%16.16x", )
		 = [0:2] + "-" + [2:4] + "-" + [4:6] + "-" + [6:8] +
			"-" + [8:10] + "-" + [10:12] + "-" + [12:14] + "-" + [14:16]
	case 48:
		 = fmt.Sprintf("%12.12x", )
		 = [0:2] + "-" + [2:4] + "-" + [4:6] + "-" + [6:8] +
			"-" + [8:10] + "-" + [10:12]
	}
	return
}

// cloneSlice returns a shallow copy of s.
func cloneSlice[ any,  ~[]]( )  {
	if  == nil {
		return nil
	}
	return append((nil), ...)
}

// copyNet returns a copy of a subnet.
func copyNet( net.IPNet) net.IPNet {
	return net.IPNet{
		IP:   cloneSlice(.IP),
		Mask: cloneSlice(.Mask),
	}
}

// SplitN splits a string into N sized string chunks.
// This might become an exported function once.
func splitN( string,  int) []string {
	if len() <  {
		return []string{}
	}
	 := []string{}
	,  := 0, 
	for {
		if  <= len() {
			 = append(, [:])
		} else {
			 = append(, [:])
			break

		}
		,  = +, +
	}

	return 
}