mdns

package module
v0.0.0-...-724533c Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: BSD-3-Clause Imports: 11 Imported by: 2

README

macos linux CodeQL

This is a standalone go based mdns and service discovery implementation.

The file doc.go describes the user interface.

The subdir go_dns is a modified version of the go dns pkg.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AAAAtoIP

func AAAAtoIP(rr *dns.RR_AAAA) net.IP

Convert an AAAA RR into a net.IP

func AtoIP

func AtoIP(rr *dns.RR_A) net.IP

Convert an A RR into a net.IP

func NewAddressRR

func NewAddressRR(name string, class uint16, ttl uint32, ip net.IP) dns.RR

Returns an A or AAAA RR, whichever is appropriate for the passed in address.

func NewPtrRR

func NewPtrRR(name string, class uint16, ttl uint32, ptr string) dns.RR

Returns a PTR RR.

func NewSrvRR

func NewSrvRR(name string, class uint16, ttl uint32, target string, port, priority, weight uint16) dns.RR

Returns a SRV RR.

func NewTxtRR

func NewTxtRR(name string, class uint16, ttl uint32, txt []string) dns.RR

Returns a TXT RR. This is a limited TXT RR that can contain only one string

func SetMulticastLoopback

func SetMulticastLoopback(conn *net.UDPConn, ipversion int, v bool) (*net.UDPConn, error)

SetMulticastLoopback turns on or off multicast loopbacks on the interface the connection is on.

func SetMulticastTTL

func SetMulticastTTL(conn *net.UDPConn, ipversion int, v int) (*net.UDPConn, error)

SetMulticastTTL sets the TTL on packets from this connection.

Types

type MDNS

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

func NewMDNS

func NewMDNS(host, v4addr, v6addr string, loopback bool, logLevel int) (s *MDNS, err error)

Create a new MDNS service.

func (*MDNS) AddService

func (s *MDNS) AddService(service, host string, port uint16, txt ...string) error

Announce a service. If the host name is empty, we just use the host name from NewMDNS. If the host name ends in .local. we strip it off. If the port is zero, we do not announce the host addresses.

func (*MDNS) Hostname

func (s *MDNS) Hostname() string

Hostname return our chosen host name.

func (*MDNS) RemoveService

func (s *MDNS) RemoveService(service, host string, port uint16, txt ...string) error

Remove a service. If the host name is empty, we just use the host name from NewMDNS. If the host name ends in .local. we strip it off.

func (*MDNS) ResolveAddress

func (s *MDNS) ResolveAddress(dn string) ([]net.IP, uint32)

ResolveToAddress return all IP addresses for a domain name (from all interfaces). These come from A and AAAA RR's for the name <host>.local. We use a map to dedup replies and then make a slice out of the map values. It also returns the lowest TTL of all the address records.

func (*MDNS) ResolveInstance

func (s *MDNS) ResolveInstance(instance, service string) ServiceInstance

ResolveInstance returns the address records, the port, and the min ttl for a single service instance.

func (*MDNS) ResolveRR

func (s *MDNS) ResolveRR(dn string, rrtype uint16) []dns.RR

Resolve a particular RR type.

func (*MDNS) ScanInterfaces

func (s *MDNS) ScanInterfaces() (string, error)

ScanInterfaces looks for changes in the interface list and makes sure we are using them for mdns.

func (*MDNS) ServiceDiscovery

func (s *MDNS) ServiceDiscovery(service string) []ServiceInstance

ServiceDiscovery returns all current instances of a service (i.e. with a SRV record). We assume the user has already subscribed to the service to get systems on the network to multicast their entries.

func (*MDNS) ServiceMemberDiscovery

func (s *MDNS) ServiceMemberDiscovery(service string) []string

ServiceMemberDiscovery returns all the members of a service (i.e. with a PTR record).

func (*MDNS) ServiceMemberWatch

func (s *MDNS) ServiceMemberWatch(service string) (<-chan ServiceInstance, func())

ServiceMemberWatch returns a reply channel over which membership changes are announced. The returned function stops watching and closes the reply channel. A zero SRV and TXT record means that the instance is no longer a member.

func (*MDNS) SetOutgoingTTL

func (s *MDNS) SetOutgoingTTL(ttl uint32)

Change the ttl for outgoing records to something other than the default.

func (*MDNS) Stop

func (s *MDNS) Stop()

Stop all udpListeners.

func (*MDNS) SubscribeToService

func (s *MDNS) SubscribeToService(service string)

SubscriberToService declares our interest in a service. This should elicit responses from everyone implementing that service. This is orthogonal to offering the service ourselves.

func (*MDNS) UnsubscribeFromService

func (s *MDNS) UnsubscribeFromService(service string)

UnsubscribeFromService withholds our interest in a service.

type ServiceInstance

type ServiceInstance struct {
	Name   string
	SrvRRs []*dns.RR_SRV
	TxtRRs []*dns.RR_TXT
}

Directories

Path Synopsis
Package dns should not be used directly by google3; instead, use net/dns/go/dns.
Package dns should not be used directly by google3; instead, use net/dns/go/dns.

Jump to

Keyboard shortcuts

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