mdns

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(entries chan<- *ServiceEntry, exit chan struct{}) error

Listen 无限期的监听多播的更新

func Lookup

func Lookup(service string, entries chan<- *ServiceEntry) error

Lookup 使用默认参数查询

func Query

func Query(params *QueryParam) error

Query 在一个域中查找一个给定的服务,最多等待指定的秒数 结果是流式的 一个通道。发送不会阻塞,所以客户应该确保 读取或缓存。

Types

type Config

type Config struct {
	Zone              Zone
	IFace             *net.Interface
	Port              int
	GetMachineIP      GetMachineIP
	LocalhostChecking bool
}

type DNSSDService

type DNSSDService struct {
	ServiceMDNS *ServiceMDNS
}

func (*DNSSDService) Records

func (that *DNSSDService) Records(q dns.Question) []dns.RR

type GetMachineIP

type GetMachineIP func() net.IP

type QueryParam

type QueryParam struct {
	Service             string               // 要查找的服务
	Domain              string               // 要查找的域。默认是 local
	Type                uint16               // dns查询类型,默认是 dns.TypePTR
	Context             context.Context      // 上下文
	Timeout             time.Duration        // 查询超时时间,默认1s,如果通过context提供了超时,则忽略该参数
	Interface           *net.Interface       // 使用组播的网卡
	Entries             chan<- *ServiceEntry // 收到的响应包,以channel形式提供
	WantUniCastResponse bool                 // 是否需要单播响应,参考 per 5.4 in RFC
}

QueryParam 自定义查询参数

func DefaultParams

func DefaultParams(service string) *QueryParam

DefaultParams 获取查询默认参数

type Server

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

func NewServer

func NewServer(config *Config) (*Server, error)

func (*Server) SendMulticast

func (that *Server) SendMulticast(msg *dns.Msg) error

SendMulticast 发送组播消息

func (*Server) Shutdown

func (that *Server) Shutdown() error

type ServiceEntry

type ServiceEntry struct {
	Name       string // 服务名
	Host       string //
	AddrV4     net.IP
	AddrV6     net.IP
	Port       int
	Info       string
	InfoFields []string
	TTL        int
	Type       uint16
	Addr       net.IP
	// contains filtered or unexported fields
}

ServiceEntry 查询后的条目

type ServiceMDNS

type ServiceMDNS struct {
	Instance string   // 实例的名称 (e.g. "hostService name")
	Service  string   // 服务的名字 (e.g. "_http._tcp.")
	Domain   string   // 域 默认为“local”
	HostName string   // 主机的dns名称 (e.g. "mymachine.net.")
	Port     int      // 端口
	IPs      []net.IP // 当前服务使用的ip地址
	TXT      []string
	TTL      uint32
	// contains filtered or unexported fields
}

ServiceMDNS mdns服务

func NewServiceMDNS

func NewServiceMDNS(instance, service, domain, hostName string, port int, ips []net.IP, txt []string) (*ServiceMDNS, error)

NewServiceMDNS 创建MDNS服务 instance

func (*ServiceMDNS) Records

func (that *ServiceMDNS) Records(q dns.Question) []dns.RR

type Zone

type Zone interface {
	// Records 根据dns查询请求,返回一个dns记录。
	Records(q dns.Question) []dns.RR
}

Jump to

Keyboard shortcuts

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