mdns

package module
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 11 Imported by: 4

README


Pion mDNS

A Go implementation of mDNS

Pion mDNS Slack Widget
GitHub Workflow Status Go Reference Coverage Status Go Report Card


Go mDNS implementation. The original user is Pion WebRTC, but we would love to see it work for everyone.

Running Server

For a mDNS server that responds to queries for pion-test.local

go run examples/server/main.go

For a mDNS server that responds to queries for pion-test.local with a given address

go run examples/server/publish_ip/main.go -ip=[IP]

If you don't set the ip parameter, "1.2.3.4" will be used instead.

Running Client

To query using Pion you can run the query example

go run examples/query/main.go

You can use the macOS client

dns-sd -q pion-test.local

Or the avahi client

avahi-resolve -a pion-test.local

RFCs

Implemented

Roadmap

The library is used as a part of our WebRTC implementation. Please refer to that roadmap to track our major milestones.

Community

Pion has an active community on the Slack.

Follow the Pion Twitter for project updates and important WebRTC news.

We are always looking to support your projects. Please reach out if you have something to build! If you need commercial support or don't want to use public methods you can contact us at team@pion.ly

Contributing

Check out the contributing wiki to join the group of amazing people making this project possible

License

MIT License - see LICENSE for full text

Documentation

Overview

Package mdns implements mDNS (multicast DNS)

Index

Constants

View Source
const (
	// DefaultAddressIPv4 is the default used by mDNS
	// and in most cases should be the address that the
	// ipv4.PacketConn passed to Server is bound to
	DefaultAddressIPv4 = "224.0.0.0:5353"

	// DefaultAddressIPv6 is the default IPv6 address used
	// by mDNS and in most cases should be the address that
	// the ipv6.PacketConn passed to Server is bound to
	DefaultAddressIPv6 = "[FF02::]:5353"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the name of the client/server used for logging purposes.
	Name string

	// QueryInterval controls how often we sends Queries until we
	// get a response for the requested name
	QueryInterval time.Duration

	// LocalNames are the names that we will generate answers for
	// when we get questions
	LocalNames []string

	// LocalAddress will override the published address with the given IP
	// when set. Otherwise, the automatically determined address will be used.
	LocalAddress net.IP

	LoggerFactory logging.LoggerFactory

	// IncludeLoopback will include loopback interfaces to be eligble for queries and answers.
	IncludeLoopback bool

	// Interfaces will override the interfaces used for queries and answers.
	Interfaces []net.Interface
}

Config is used to configure a mDNS client or server.

type Conn

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

Conn represents a mDNS Server

func Server

func Server(
	multicastPktConnV4 *ipv4.PacketConn,
	multicastPktConnV6 *ipv6.PacketConn,
	config *Config,
) (*Conn, error)

Server establishes a mDNS connection over an existing conn. Either one or both of the multicast packet conns should be provided. The presence of each IP type of PacketConn will dictate what kinds of questions are sent for queries. That is, if an ipv6.PacketConn is provided, then AAAA questions will be sent. A questions will only be sent if an ipv4.PacketConn is also provided. In the future, we may add a QueryAddr method that allows specifying this more clearly.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the mDNS Conn

func (*Conn) Query deprecated

func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeader, net.Addr, error)

Query sends mDNS Queries for the following name until either the Context is canceled/expires or we get a result

Deprecated: Use QueryAddr instead as it supports the easier to use netip.Addr.

func (*Conn) QueryAddr added in v2.0.5

func (c *Conn) QueryAddr(ctx context.Context, name string) (dnsmessage.ResourceHeader, netip.Addr, error)

QueryAddr sends mDNS Queries for the following name until either the Context is canceled/expires or we get a result

Directories

Path Synopsis
examples
query
This example program showcases the use of the mDNS client by querying a previously published address
This example program showcases the use of the mDNS client by querying a previously published address
server
This example program showcases the use of the mDNS server by publishing "pion-test.local"
This example program showcases the use of the mDNS server by publishing "pion-test.local"
server/publish_ip
This example program allows to set an IP that deviates from the automatically determined interface address.
This example program allows to set an IP that deviates from the automatically determined interface address.

Jump to

Keyboard shortcuts

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