Skip to content
/ dnssd Public
forked from brutella/dnssd

This library implements Multicast DNS (mDNS) and DNS-Based Service Discovery (DNS-SD) for Zero Configuration Networking in Go.

License

Notifications You must be signed in to change notification settings

hkontrol/dnssd

 
 

Repository files navigation

DNS-SD

Forked version of brutella/dnssd

This library implements Multicast DNS and DNS-Based Service Discovery to provide zero-configuration operations. It lets you announce and find services in a specific link-local domain.

Usage

Create a mDNS responder

The following code creates a service with name "My Website._http._tcp.local." for the host "My Computer" which has all IPs from network interface "eth0". The service is added to a responder.

import (
	"context"
	"github.com/hkontrol/dnssd"
)

cfg := dnssd.Config{
    Name:   "My Website",
    Type:   "_http._tcp",
    Domain: "local",
    Host:   "My Computer",
    Ifaces: []string{"eth0"},,
    Port:   12345,
}
sv, _ := dnssd.NewService(cfg)

In most cases you only need to specify the name, type and port of the service.

cfg := dnssd.Config{
    Name:   "My Website",
    Type:   "_http._tcp",
    Port:   12345,
}
sv, _ := dnssd.NewService(cfg)

Then you create a responder and add the service to it.

rp, _ := dnssd.NewResponder()
hdl, _ := rp.Add(sv)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

rp.Respond(ctx)

When calling Respond the responder probes for the service instance name and host name to be unqiue in the network. Once probing is finished, the service will be announced.

Update TXT records

Once a service is added to a responder, you can use the hdl to update properties.

hdl.UpdateText(map[string]string{"key1": "value1", "key2": "value2"}, rsp)

Examples

There are examples in the _cmd directory to register services, resolve service instances and to browse for service types.

TODO

  • Support hot plugging
  • Support negative responses (RFC6762 6.1)
  • Handle txt records case insensitive
  • Remove outdated services from cache regularly
  • Make sure that hostnames are FQDNs

License

dnssd is available under the MIT license. See the LICENSE file for more info.

About

This library implements Multicast DNS (mDNS) and DNS-Based Service Discovery (DNS-SD) for Zero Configuration Networking in Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%