Generated from Manticore v1.1.6 • 388 packages. View on pkg.go.dev

resourcerecord

import "github.com/TheManticoreProject/Manticore/network/llmnr/resourcerecord"

Index

func IPToRData

func IPToRData(ip string) []byte

IPToRData converts an IP address string to its corresponding RData byte slice representation. It determines whether the IP address is IPv4 or IPv6 and calls the appropriate conversion function.

Parameters: - ip: A string representing the IP address to be converted.

Returns: - A byte slice containing the RData representation of the IP address. - nil if the IP address is neither a valid IPv4 nor IPv6 address.

func IPv4ToRData

func IPv4ToRData(ip string) []byte

IPv4ToRData converts an IPv4 address string to its corresponding RData byte slice representation.

Parameters: - ip: A string representing the IPv4 address to be converted.

Returns: - A byte slice containing the RData representation of the IPv4 address.

func IPv6ToRData

func IPv6ToRData(ip string) []byte

IPv6ToRData converts an IPv6 address string to its corresponding RData byte slice representation.

Parameters: - ip: A string representing the IPv6 address to be converted.

Returns: - A byte slice containing the RData representation of the IPv6 address.

func NameToRData

func NameToRData(name string) ([]byte, error)

NameToRData encodes a single domain name as RDATA for a name-bearing record (PTR/CNAME/NS). The name is emitted uncompressed; compression-on-write is a separate concern and Marshal recomputes RDLENGTH from the resulting bytes.

func SRVToRData

func SRVToRData(priority uint16, weight uint16, port uint16, target string) ([]byte, error)

SRVToRData encodes an SRV record’s RDATA (RFC 2782): the priority, weight and port as big-endian uint16s followed by the uncompressed target name.

func TXTToRData

func TXTToRData(strs []string) ([]byte, error)

TXTToRData encodes one or more character-strings as TXT RDATA (RFC 1035 §3.3.14). Each string is emitted as a single length octet followed by its bytes; a string longer than 255 bytes cannot be represented and is rejected.

type ResourceRecord

ResourceRecord represents a resource record in the LLMNR protocol.

A resource record is used to store information about a domain name, such as its IP address, mail server, or other related data. The ResourceRecord struct contains fields for the domain name, type, class, time-to-live (TTL), resource data length (RDLength), and resource data (RData).

type ResourceRecord struct {
    // The domain name associated with the resource record.
    Name domain_name.DomainName `json:"name"`

    // The type of the resource record, indicating the kind of data stored (e.g., TypeA for IPv4 address).
    Type llmnr_type.Type `json:"type"`

    // The class of the resource record, typically ClassIN for Internet.
    Class class.Class `json:"class"`

    // The time-to-live value, indicating how long the record can be cached before it should be discarded.
    TTL uint32 `json:"ttl"`

    // The length of the resource data in bytes.
    RDLength uint16 `json:"rdlength"`

    // The resource data, which contains the actual information associated with the domain name (e.g., an IP address).
    RData []byte `json:"rdata"`
    // contains filtered or unexported fields
}

func (*ResourceRecord) AsA

func (rr *ResourceRecord) AsA() (net.IP, error)

AsA returns the IPv4 address carried by an A record. It errors if the record is not an A record or if RDATA is not exactly four octets (RFC 1035 §3.4.1).

func (*ResourceRecord) AsAAAA

func (rr *ResourceRecord) AsAAAA() (net.IP, error)

AsAAAA returns the IPv6 address carried by an AAAA record. It errors if the record is not an AAAA record or if RDATA is not exactly sixteen octets (RFC 3596 §2.2).

func (*ResourceRecord) AsCNAME

func (rr *ResourceRecord) AsCNAME() (string, error)

AsCNAME returns the canonical name carried by a CNAME record (RFC 1035 §3.3.1).

func (*ResourceRecord) AsNS

func (rr *ResourceRecord) AsNS() (string, error)

AsNS returns the name server carried by an NS record (RFC 1035 §3.3.11).

func (*ResourceRecord) AsPTR

func (rr *ResourceRecord) AsPTR() (string, error)

AsPTR returns the domain name carried by a PTR record (RFC 1035 §3.3.12).

func (*ResourceRecord) AsSRV

func (rr *ResourceRecord) AsSRV() (priority uint16, weight uint16, port uint16, target string, err error)

AsSRV returns the priority, weight, port and target of an SRV record. SRV RDATA is three big-endian uint16s (priority, weight, port) followed by the target domain name (RFC 2782). The target may in principle contain a compression pointer, which is resolved against the message origin.

func (*ResourceRecord) AsTXT

func (rr *ResourceRecord) AsTXT() ([]string, error)

AsTXT returns the character-strings carried by a TXT record. TXT RDATA is one or more <character-string>s, each a single length octet followed by that many bytes (RFC 1035 §3.3.14 and §3.3).

func (*ResourceRecord) Describe

func (rr *ResourceRecord) Describe(indent int)

Describe prints a detailed description of the ResourceRecord.

Parameters: - indent: An integer value specifying the indentation level for the output.

func (*ResourceRecord) Marshal

func (rr *ResourceRecord) Marshal() ([]byte, error)

Marshal converts a ResourceRecord into a byte slice using the LLMNR protocol’s wire format. It encodes the domain name, type, class, TTL, RDLength, and RData fields sequentially.

Parameters: - rr: The ResourceRecord to be encoded.

Returns:

  • A byte slice with the encoded resource record.
  • An error if encoding fails, such as with an invalid domain name.

func (*ResourceRecord) Unmarshal

func (rr *ResourceRecord) Unmarshal(data []byte) (int, error)

Unmarshal decodes a byte slice into a ResourceRecord struct. It expects the byte slice to be in the wire format as specified by the LLMNR protocol. The function first decodes the domain name, followed by the type, class, TTL, RDLength, and RData fields.

Parameters: - data: A byte slice containing the resource record in wire format. - offset: The starting position in the byte slice from which to begin decoding.

Returns:

  • A ResourceRecord struct containing the decoded data.
  • An integer representing the new offset position after decoding.
  • An error if the decoding fails at any point, such as if the data is too short or if there is an error decoding the domain name.

func (*ResourceRecord) UnmarshalFromMessage

func (rr *ResourceRecord) UnmarshalFromMessage(message []byte, offset int) (int, error)

UnmarshalFromMessage decodes a ResourceRecord located at offset inside the full message buffer. It is used instead of Unmarshal when the record’s name may contain 0xC0 compression pointers (responders routinely compress the answer NAME to point back at the question), so those pointers resolve against the start of the message (RFC 1035 §4.1.4) rather than against a sub-slice.

Parameters: - message: The full LLMNR message in wire format. - offset: The absolute offset of the resource record inside message.

Returns:

  • The number of bytes consumed from message at offset.
  • An error if the decoding fails at any point.