mdns

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mdns advertises and browses DNS-SD services over multicast DNS (RFC 6762, RFC 6763), over IPv4, as Linked Instances find each other on the LAN (ADR 0027).

Port 5353 is also the default port of the dns Service, which Host mode's DNS forwarding sends to, and an mDNS daemon (avahi-daemon, mDNSResponder, Windows' DNS Client) usually holds it on the wildcard address. Neither side takes it from the other:

  • A Responder binds the mDNS group address itself (the wildcard on Windows, which cannot bind a multicast address), with SO_REUSEADDR and SO_REUSEPORT, so it shares multicast queries with the daemon and never receives unicast datagrams meant for the dns Service's specific address. Its host name is its own (gcpemu-…), never the machine's, which the daemon answers for.
  • Browse is a one-shot querier (RFC 6762 §5.1): it queries from an ephemeral port, and responders answer it by unicast to that port, so browsing binds nothing on 5353.

Index

Constants

This section is empty.

Variables

View Source
var (
	Port  = 5353
	Group = net.IPv4(224, 0, 0, 251)
)

Port is the mDNS port, and Group the IPv4 group address.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Instance is its label, and Host the name its SRV record targets.
	Instance string
	Host     string
	Port     int
	Addrs    []net.IP
	// TXT maps its TXT record's keys, lowercased, to their values.
	TXT map[string]string
}

Entry is a browsed service instance.

func Browse

func Browse(ctx context.Context, typ string, o Options) ([]Entry, error)

Browse queries for service instances of typ (e.g. "_gcpemu._tcp") on every multicast-capable interface, and returns those that answer within o.Wait, by instance label.

type Options

type Options struct {
	// Port zero means Port.
	Port int
	// Wait is how long Browse collects answers; zero means a second, or
	// until its context is done if that is sooner.
	Wait time.Duration
	Log  *slog.Logger
}

Options configure Advertise and Browse.

type Responder

type Responder struct {
	// contains filtered or unexported fields
}

Responder answers mDNS queries for a Service until Close.

func Advertise(svc Service, o Options) (*Responder, error)

Advertise starts answering queries for svc on the interfaces that hold its addresses, and announces it there.

func (*Responder) Close

func (r *Responder) Close() error

Close sends a goodbye (RFC 6762 §10.1) and stops answering.

type Service

type Service struct {
	// Instance is the instance's label, e.g. "default@office".
	Instance string
	// Type is the service type, e.g. "_gcpemu._tcp".
	Type string
	// Host is the label of the host name the service's addresses are
	// published under, in .local; it must not be the machine's own.
	Host string
	Port int
	// Addrs are the addresses to advertise. An unspecified one stands for
	// every address of every multicast-capable interface.
	Addrs []net.IP
	// TXT holds the TXT record's strings, "key=value".
	TXT []string
}

Service is a DNS-SD service instance to advertise.

Jump to

Keyboard shortcuts

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