mdns

package
v0.0.0-...-4685c53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

The mdns package listens and broadcasts for DNS packets

It listens on IP4 and IP6 connections for messages, and emits them to any subscribers. In order to create a task instance, use the `New` function with a `Config` object. The `Run` function is then used to start the task instance, until the passed context is cancelled, which closes the channels for all subscribers.

A `Message` can be created from a DNS packet (an answer) or with a question, and sent using the `Send` method.

Index

Constants

View Source
const (
	DefaultName  = "mdns"
	DefaultLabel = "local"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	L         string `hcl:"label,label" json:"label,omitempty"`            // Label for the configuration
	Interface string `hcl:"interface,optional" json:"interface,omitempty"` // The interface to bind to. Defaults to all broadcast interfaces
	// contains filtered or unexported fields
}

func (Config) Label

func (c Config) Label() string

Return the label of the instance

func (Config) Name

func (c Config) Name() string

Return the name of the plugin

func (Config) New

func (c Config) New(ctx context.Context, provider Provider) (Task, error)

Return a new task. Label for the task can be retrieved from context

type DNSTask

type DNSTask interface {
	Task

	// Send a DNS message
	Send(context.Context, Message) error
}

A `DNSTask` which receives and sends messages

func NewWithConfig

func NewWithConfig(c Config) (DNSTask, error)

Create a task instance from a `Config` object

type Message

type Message interface {
	PTR() []Ptr             // Return PTR records
	A() []net.IP            // Return A records
	TXT() []string          // Return TXT records
	SRV() []Srv             // Return SRV records
	Bytes() ([]byte, error) // Return the packed message
	IsAnswer() bool         // Return true when the message is an answer
	IfIndex() int           // Interface to send and receive on, or nil
}

A sent or received message

func MessageFromPacket

func MessageFromPacket(packet []byte, sender net.Addr, iface net.Interface) (Message, error)

Create a message from a received packet, with a sender and the interface that the message was received on

func MessageWithQuestion

func MessageWithQuestion(question string, iface net.Interface) (Message, error)

Create a message from a question, to be sent on a specific interface or on all interfaces if the index is zero

type Ptr

type Ptr interface {
	Service() string    // Return service
	Name() string       // Return name
	TTL() time.Duration // Return time-to-live for record
}

type Srv

type Srv interface {
	Host() string     // Return host
	Port() uint16     // Return port
	Priority() uint16 // Return priority
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL