Documentation
¶
Index ¶
Constants ¶
const ( TypeA = 1 TypeNS = 2 TypeCNAME = 5 TypeSOA = 6 TypeWKS = 11 TypePTR = 12 TypeHINFO = 13 TypeMINFO = 14 TypeMX = 15 TypeTXT = 16 TypeAAAA = 28 TypeSRV = 33 )
DNS resource record TYPE values, matching MRI's Resolv::DNS::Resource TypeValue constants.
const ClassIN = 1
ClassIN is the DNS IN class value (Resolv::DNS::Resource::IN::ClassValue == 1).
const DefaultHostsFileName = "/etc/hosts"
DefaultHostsFileName is Resolv::Hosts::DefaultFileName on a POSIX system.
Variables ¶
var IPv4Regex = regexp.MustCompile(
`\A(` + regex256 + `)\.(` + regex256 + `)\.(` + regex256 + `)\.(` + regex256 + `)\z`)
IPv4Regex matches the textual forms Ruby's Resolv::IPv4::Regex accepts: a dotted quad of four octets, each 0..255 with no leading zeros (anchored). It mirrors MRI's Regex256 alternation exactly.
var ( // IPv6Regex is the composite matcher (Resolv::IPv6::Regex): a textual IPv6 // address in any of its accepted forms. Each alternative is fully anchored, // so this matches exactly the strings CreateIPv6 accepts. IPv6Regex = regexp.MustCompile( `(?:\A` + regex8Hex + `\z)` + `|(?:\A` + regexCompressedHex + `\z)` + `|(?:\A` + regex6Hex4Dec + `\z)` + `|(?:\A` + regexCompressedHex4Dec + `\z)` + `|(?:\A` + regex8HexLinkLocal + `\z)` + `|(?:\A` + regexCompressedHexLinkLocal + `\z)`) )
The component IPv6 regexps, mirroring MRI's Resolv::IPv6::Regex_* constants.
Functions ¶
This section is empty.
Types ¶
type A ¶
A is Resolv::DNS::Resource::IN::A — an IPv4 address record.
func (A) ClassValue ¶
func (A) EncodeRData ¶
func (a A) EncodeRData(e *MessageEncoder)
type AAAA ¶
AAAA is Resolv::DNS::Resource::IN::AAAA — an IPv6 address record.
func (AAAA) ClassValue ¶
func (AAAA) EncodeRData ¶
func (a AAAA) EncodeRData(e *MessageEncoder)
type CNAME ¶
type CNAME struct{ DomainName }
CNAME is Resolv::DNS::Resource::IN::CNAME — the canonical name for an alias.
type DecodeError ¶
type DecodeError struct{ Msg string }
DecodeError reports malformed DNS wire data, matching the failures MRI's Resolv::DNS::DecodeError signals (truncated input, junk in an RDATA window, a forward/over-long name pointer).
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
type DomainName ¶
DomainName is the shared body of the single-Name records (NS, CNAME, PTR). Each concrete type carries its own TYPE so equality and dispatch stay precise.
func (DomainName) ClassValue ¶
func (DomainName) ClassValue() uint16
func (DomainName) EncodeRData ¶
func (n DomainName) EncodeRData(e *MessageEncoder)
func (DomainName) TypeValue ¶
func (n DomainName) TypeValue() uint16
type Generic ¶
Generic is Resolv::DNS::Resource::Generic — an opaque record for a TYPE/CLASS pair the library does not model specially. It round-trips the raw RDATA.
func (Generic) ClassValue ¶
func (Generic) EncodeRData ¶
func (g Generic) EncodeRData(e *MessageEncoder)
type HINFO ¶
HINFO is Resolv::DNS::Resource::IN::HINFO — host CPU/OS information.
func (HINFO) ClassValue ¶
func (HINFO) EncodeRData ¶
func (h HINFO) EncodeRData(e *MessageEncoder)
type Hosts ¶
type Hosts struct {
// contains filtered or unexported fields
}
Hosts is a pure-compute port of Ruby's Resolv::Hosts: a parsed /etc/hosts table mapping names to addresses and back. It performs no file I/O — the host supplies the file content as a string (ParseHosts) — but reproduces MRI's parsing and lookup semantics, including the reversed address order per name.
func ParseHosts ¶
ParseHosts parses /etc/hosts-format text into a Hosts table, replicating MRI's Resolv::Hosts#lazy_initialize: each line has its comment stripped and is split on whitespace into an address and its hostnames; the per-name address lists are reversed (so the last-seen address for a name is returned first).
func (*Hosts) GetAddress ¶
GetAddress returns the first address for name (Resolv::Hosts#getaddress), reporting an error when the name is absent.
func (*Hosts) GetAddresses ¶
GetAddresses returns all addresses for name (Resolv::Hosts#getaddresses).
type IPv4 ¶
type IPv4 struct {
// Addr is the raw 4-byte address (Ruby's @address String).
Addr [4]byte
}
IPv4 is a pure-compute port of Ruby's Resolv::IPv4: it parses and renders a dotted-quad address and holds the canonical 4-byte form (Resolv::IPv4#address).
func CreateIPv4 ¶
CreateIPv4 builds an IPv4 from a dotted-quad string, matching Resolv::IPv4.create. It returns an error (Ruby raises ArgumentError) when the text does not match IPv4Regex or an octet is out of range.
type IPv6 ¶
type IPv6 struct {
// Addr is the raw 16-byte address (Ruby's @address String).
Addr [16]byte
}
IPv6 is a pure-compute port of Ruby's Resolv::IPv6: it parses the textual IPv6 forms and holds the canonical 16-byte form (Resolv::IPv6#address).
MRI's Resolv::IPv6.create only consults the 8Hex, CompressedHex, 6Hex4Dec and CompressedHex4Dec forms — never the link-local %zone forms — so CreateIPv6 rejects a %zone string exactly as MRI does, even though IPv6Regex (the Resolv::IPv6::Regex constant, used by match?) accepts it.
func CreateIPv6 ¶
CreateIPv6 builds an IPv6 from a textual address, matching Resolv::IPv6.create. It returns an error (Ruby raises ArgumentError) for input matching none of the accepted forms or with an out-of-range embedded IPv4 octet.
type Label ¶
type Label struct {
// Str is the label's bytes as supplied (Resolv::DNS::Label::Str#string).
Str string
}
Label is a single DNS label (Ruby's Resolv::DNS::Label::Str). It preserves the original byte string while comparing case-insensitively over ASCII, per RFC 4343, exactly as MRI does (@downcase = string.b.downcase).
type MX ¶
MX is Resolv::DNS::Resource::IN::MX — a mail exchanger.
func (MX) ClassValue ¶
func (MX) EncodeRData ¶
func (m MX) EncodeRData(e *MessageEncoder)
type Message ¶
type Message struct {
ID uint16
QR uint16
Opcode uint16
AA uint16
TC uint16
RD uint16
RA uint16
RCode uint16
Question []Question
Answer []RR
Authority []RR
Additional []RR
}
Message is a pure-compute port of Ruby's Resolv::DNS::Message: a DNS header, the question section, and the three resource-record sections. It encodes to and decodes from the RFC 1035 wire format with 0xC0 name compression.
func Decode ¶
Decode parses DNS wire bytes into a Message (Resolv::DNS::Message.decode). When the truncation (TC) bit is set, MRI returns after the header, so Decode does the same and leaves the sections empty.
func NewMessage ¶
NewMessage builds an empty Message with the given ID (Resolv::DNS::Message.new).
func (*Message) AddAdditional ¶
AddAdditional appends an additional record (Resolv::DNS::Message#add_additional).
func (*Message) AddAuthority ¶
AddAuthority appends an authority record (Resolv::DNS::Message#add_authority).
func (*Message) AddQuestion ¶
AddQuestion appends a question (Resolv::DNS::Message#add_question).
type MessageDecoder ¶
type MessageDecoder struct {
// contains filtered or unexported fields
}
MessageDecoder reads wire bytes with a movable limit for RDATA windows, mirroring Ruby's Resolv::DNS::Message::MessageDecoder.
type MessageEncoder ¶
type MessageEncoder struct {
// contains filtered or unexported fields
}
MessageEncoder accumulates wire bytes and a name-compression table, mirroring Ruby's Resolv::DNS::Message::MessageEncoder.
type NS ¶
type NS struct{ DomainName }
NS is Resolv::DNS::Resource::IN::NS — an authoritative name server.
type Name ¶
type Name struct {
// Labels are the dot-separated components, most-significant first.
Labels []Label
// Absolute reports whether the source had a trailing dot.
Absolute bool
}
Name is a pure-compute port of Ruby's Resolv::DNS::Name: an ordered list of labels plus an absolute flag (trailing dot). It carries no wire bytes; wire encoding/decoding (with 0xC0 compression) lives on the Message coder.
func NewName ¶
NewName builds a Name from a dotted string (Resolv::DNS::Name.create). The labels are the maximal non-dot runs (MRI's Label.split, /[^\.]+/), and the name is absolute iff the string ends in a dot.
func NewNameLabels ¶
NewNameLabels builds a Name directly from labels and an absolute flag, as the wire decoder does (Resolv::DNS::Name.new defaults absolute=true).
func (Name) Equal ¶
Equal reports name equality (Resolv::DNS::Name#==): same absolute flag and case-insensitively equal labels.
func (Name) String ¶
String renders the dotted name without a trailing dot, even when absolute (Resolv::DNS::Name#to_s).
func (Name) SubdomainOf ¶
SubdomainOf reports whether n is a strict subdomain of other (Resolv::DNS::Name#subdomain_of?): same absolute flag, strictly more labels, and a matching suffix.
type PTR ¶
type PTR struct{ DomainName }
PTR is Resolv::DNS::Resource::IN::PTR — a pointer to another name.
type Question ¶
Question is one entry of a Message's question section: a name plus the queried TYPE/CLASS (Resolv::DNS::Message#question yields [name, typeclass]).
type RR ¶
RR is one resource record in an answer/authority/additional section: an owner name, a TTL, and the typed RDATA (Resolv::DNS::Message#answer yields [name, ttl, data]).
type Resource ¶
type Resource interface {
// TypeValue is the record's DNS TYPE (Resolv::DNS::Resource::TypeValue).
TypeValue() uint16
// ClassValue is the record's DNS CLASS (Resolv::DNS::Resource::ClassValue).
ClassValue() uint16
// EncodeRData writes the record's RDATA to the encoder.
EncodeRData(e *MessageEncoder)
}
Resource is the wire-level interface every record implements: it knows its TYPE/CLASS and how to encode/decode its RDATA. The encoder writes the owner name, type, class, TTL and a 16-bit length around EncodeRData; the decoder reads them and calls DecodeRData within the length window.
type SOA ¶
type SOA struct {
MName Name
RName Name
Serial uint32
Refresh uint32
Retry uint32
Expire uint32
Minimum uint32
TTL uint32
}
SOA is Resolv::DNS::Resource::IN::SOA — a start-of-authority record.
func (SOA) ClassValue ¶
func (SOA) EncodeRData ¶
func (s SOA) EncodeRData(e *MessageEncoder)
type SRV ¶
SRV is Resolv::DNS::Resource::IN::SRV — a service location record. Its target name is encoded without compression, matching MRI (put_name compress: false).
func (SRV) ClassValue ¶
func (SRV) EncodeRData ¶
func (s SRV) EncodeRData(e *MessageEncoder)
type TXT ¶
TXT is Resolv::DNS::Resource::IN::TXT — one or more character-strings.
func (TXT) ClassValue ¶
func (TXT) EncodeRData ¶
func (t TXT) EncodeRData(e *MessageEncoder)
