zeroconf

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package zeroconf is a pure Golang library that employs Multicast DNS-SD for browsing and resolving services in your network and registering own services in the local network.

It basically implements aspects of the standards RFC 6762 (mDNS) and RFC 6763 (DNS-SD). Though it does not support all requirements yet, the aim is to provide a complient solution in the long-term with the community.

By now, it should be compatible to [Avahi](http://avahi.org/) (tested) and Apple's Bonjour (untested). Should work in the most office, home and private environments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Browse

func Browse(ctx context.Context, service, domain string, entries chan<- *ServiceEntry, opts ...ClientOption) error

Browse for all services of a given type in a given domain. Received entries are sent on the entries channel. It blocks until the context is canceled (or an error occurs).

func Lookup

func Lookup(ctx context.Context, instance, service, domain string, entries chan<- *ServiceEntry, opts ...ClientOption) error

Lookup a specific service by its name and type in a given domain. Received entries are sent on the entries channel. It blocks until the context is canceled (or an error occurs).

Types

type ClientOption

type ClientOption func(*clientOpts)

ClientOption fills the option struct to configure intefaces, etc.

func SelectIPTraffic

func SelectIPTraffic(t IPType) ClientOption

SelectIPTraffic selects the type of IP packets (IPv4, IPv6, or both) this instance listens for. This does not guarantee that only mDNS entries of this sepcific type passes. E.g. typical mDNS packets distributed via IPv4, may contain both DNS A and AAAA entries.

func SelectIfaces

func SelectIfaces(ifaces []net.Interface) ClientOption

SelectIfaces selects the interfaces to query for mDNS records

type IPType

type IPType uint8

IPType specifies the IP traffic the client listens for. This does not guarantee that only mDNS entries of this sepcific type passes. E.g. typical mDNS packets distributed via IPv4, often contain both DNS A and AAAA entries.

const (
	IPv4        IPType = 0x01
	IPv6        IPType = 0x02
	IPv4AndIPv6        = IPv4 | IPv6 // default option
)

Options for IPType.

type Server

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

Server structure encapsulates both IPv4/IPv6 UDP connections

func Register

func Register(instance, service, domain string, port int, text []string, ifaces []net.Interface, opts ...ServerOption) (*Server, error)

Register a service by given arguments. This call will take the system's hostname and lookup IP by that hostname.

func RegisterProxy

func RegisterProxy(instance, service, domain string, port int, host string, ips []string, text []string, ifaces []net.Interface, opts ...ServerOption) (*Server, error)

RegisterProxy registers a service proxy. This call will skip the hostname/IP lookup and will use the provided values.

func (*Server) SetText

func (s *Server) SetText(text []string)

SetText updates and announces the TXT records

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown closes all udp connections and unregisters the service

func (*Server) TTL deprecated

func (s *Server) TTL(ttl uint32)

TTL sets the TTL for DNS replies

Deprecated: This method is racy. Use the TTL server option instead.

type ServerOption

type ServerOption func(*serverOpts)

ServerOption fills the option struct.

func TTL

func TTL(ttl uint32) ServerOption

TTL sets the TTL for DNS replies.

type ServiceEntry

type ServiceEntry struct {
	ServiceRecord
	HostName string    `json:"hostname"` // Host machine DNS name
	Port     int       `json:"port"`     // Service Port
	Text     []string  `json:"text"`     // Service info served as a TXT record
	Expiry   time.Time `json:"expiry"`   // Expiry of the service entry, will be converted to a TTL value
	AddrIPv4 []net.IP  `json:"-"`        // Host machine IPv4 address
	AddrIPv6 []net.IP  `json:"-"`        // Host machine IPv6 address
}

ServiceEntry represents a browse/lookup result for client API. It is also used to configure service registration (server API), which is used to answer multicast queries.

type ServiceRecord

type ServiceRecord struct {
	Instance string   `json:"name"`     // Instance name (e.g. "My web page")
	Service  string   `json:"type"`     // Service name (e.g. _http._tcp.)
	Subtypes []string `json:"subtypes"` // Service subtypes
	Domain   string   `json:"domain"`   // If blank, assumes "local"
	// contains filtered or unexported fields
}

ServiceRecord contains the basic description of a service, which contains instance name, service type & domain

func (*ServiceRecord) ServiceInstanceName

func (s *ServiceRecord) ServiceInstanceName() string

ServiceInstanceName returns a complete service instance name (e.g. MyDemo\ Service._foobar._tcp.local.), which is composed from service instance name, service name and a domain.

func (*ServiceRecord) ServiceName

func (s *ServiceRecord) ServiceName() string

ServiceName returns a complete service name (e.g. _foobar._tcp.local.), which is composed of a service name (also referred as service type) and a domain.

func (*ServiceRecord) ServiceTypeName

func (s *ServiceRecord) ServiceTypeName() string

ServiceTypeName returns the complete identifier for a DNS-SD query.

Jump to

Keyboard shortcuts

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