Generated from Manticore v1.1.5 • 201 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.

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"`
}

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.