dns_naming

package
v0.0.0-...-88cdd03 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package dns_naming maps a name from the wire to a mac address. It is useful on a lan to link hosts to known names. It works for mdns, dns, nbns, and ssdp names as these all use standard dns message formats when replying to queries.

Index

Constants

View Source
const MDNSServiceDiscovery = "_services._dns-sd._udp.local."

MDNS RFC

see https://datatracker.ietf.org/doc/html/rfc6762
see Apple bonjour - https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NetServices/Introduction.html

One of the motivations for DNS-based Service Discovery is to enable a
visiting client (e.g., a Wi-Fi-equipped [IEEEW] laptop computer,
tablet, or mobile telephone) arriving on a new network to discover
what services are available on that network, without any manual
configuration.

This discovery is performed using DNS queries, using Unicast or
Multicast DNS.  Five special RR names are reserved for this purpose:

 b._dns-sd._udp.<domain>.
db._dns-sd._udp.<domain>.
 r._dns-sd._udp.<domain>.
dr._dns-sd._udp.<domain>.
lb._dns-sd._udp.<domain>.

TODO: investigate mdns domain resolution

For example, if a host has the address 192.168.12.34, with
the subnet mask 255.255.0.0, then the 'base' address of the subnet is
192.168.0.0, and to discover the recommended automatic browsing
domain(s) for devices on this subnet, the host issues a DNS PTR query
for the name "lb._dns-sd._udp.0.0.168.192.in-addr.arpa."

Service Discovery RFC

see https://datatracker.ietf.org/doc/html/rfc6763

Given a type of service that a client is looking for, and a domain in which the client is looking for that service, this mechanism allows clients to discover a list of named instances of that desired service, using standard DNS queries. This mechanism is referred to as DNS-based Service Discovery, or DNS-SD.

Variables

View Source
var Debug bool
View Source
var Logger = fastlog.New(module)
View Source
var (
	LoggerMDNS = fastlog.New(moduleMDNS)
)

Functions

func ReverseDNS

func ReverseDNS(ip netip.Addr) error

reverseDNS query the PTR record for ip return ErrNotFound if there is no PTR record

Types

type DNSHandler

type DNSHandler struct {
	DNSTable map[string]packet.DNSEntry // store dns records
	// contains filtered or unexported fields
}

func New

func New(session *packet.Session) (h *DNSHandler, err error)

func (*DNSHandler) Close

func (h *DNSHandler) Close() error

func (*DNSHandler) DNSExist

func (h *DNSHandler) DNSExist(ip netip.Addr) bool

func (*DNSHandler) DNSFind

func (h *DNSHandler) DNSFind(name string) packet.DNSEntry

func (*DNSHandler) DNSLookupPTR

func (h *DNSHandler) DNSLookupPTR(ip netip.Addr)

func (*DNSHandler) PrintDNSTable

func (h *DNSHandler) PrintDNSTable()

func (*DNSHandler) ProcessDNS

func (h *DNSHandler) ProcessDNS(frame packet.Frame) (e packet.DNSEntry, err error)

ProcessDNS parse the DNS packet and record in DNS cache table.

It returns a copy of the DNSEntry that is free from race conditions. The caller has a unique copy.

func (*DNSHandler) ProcessMDNS

func (h *DNSHandler) ProcessMDNS(frame packet.Frame) (ipv4 []packet.IPNameEntry, ipv6 []packet.IPNameEntry, err error)

ProcesMDNS will process a multicast DNS packet. Note: host cannot be nil.

func (*DNSHandler) ProcessNBNS

func (h *DNSHandler) ProcessNBNS(host *packet.Host, ether packet.Ether, payload []byte) (name packet.NameEntry, err error)

func (*DNSHandler) ProcessSSDP

func (h *DNSHandler) ProcessSSDP(host *packet.Host, ether packet.Ether, payload []byte) (name packet.NameEntry, location string, err error)

func (*DNSHandler) SendLLMNRQuery

func (h *DNSHandler) SendLLMNRQuery(name string) (err error)

SendLLMNRQuery send a multicast LLMNR query

func (*DNSHandler) SendMDNSQuery

func (h *DNSHandler) SendMDNSQuery(name string) (err error)

SendMDNSQuery send a multicast DNS query

func (*DNSHandler) SendNBNSNodeStatus

func (h *DNSHandler) SendNBNSNodeStatus() (err error)

SendNBNSNodeStatus transmit a nbns node status request.

node status request is a standard dns question packet with class set to 0x21 (NBNS node status request).

func (*DNSHandler) SendNBNSQuery

func (h *DNSHandler) SendNBNSQuery(srcAddr packet.Addr, dstAddr packet.Addr, name string) (err error)

SendNBNSQuery send NBNS node status request query

nbnb query request is a standard dns question packet with class set to 0x20 (NBNS query request).

func (*DNSHandler) SendSSDPSearch

func (h *DNSHandler) SendSSDPSearch() (err error)

SendSSDPSearch transmit a multicast SSDP M-SEARCH discovery packet

TODO: test with samsung SSDP string

MSearch ST: urn:samsung.com:service:MultiScreenService:1
see: https://developer.samsung.com/smarttv/develop/legacy-platform-library/art00030/index.html#

func (*DNSHandler) SendSleepProxyResponse

func (h *DNSHandler) SendSleepProxyResponse(srcAddr packet.Addr, dstAddr packet.Addr, id uint16, name string) (err error)

func (*DNSHandler) Start

func (h *DNSHandler) Start() error

func (*DNSHandler) UPNPServiceDiscovery

func (h *DNSHandler) UPNPServiceDiscovery(addr packet.Addr, location string) (name packet.NameEntry, err error)

type HostName

type HostName struct {
	Name       string
	Addr       packet.Addr
	Attributes map[string]string
}

type UPNPDevice

type UPNPDevice struct {
	Name             string `xml:"friendlyName"`
	Model            string `xml:"modelName"`
	ModelNumber      string `xml:"modelNumber"`
	ModelDescription string `xml:"modelDescription"`
	Manufacturer     string `xml:"manufacturer"`
}

example XML <root xmlns="urn:schemas-upnp-org:device-1-0">

<specVersion>
  <major>1</major>
  <minor>0</minor>
</specVersion>
<device>
  <friendlyName>192.168.0.103 - Sonos Play:1</friendlyName>
  <manufacturer>Sonos, Inc.</manufacturer>
  <modelNumber>S1</modelNumber>
  <modelDescription>Sonos Play:1</modelDescription>
  <modelName>Sonos Play:1</modelName>

type UPNPService

type UPNPService struct {
	XMLName xml.Name   `xml:"root"`
	Device  UPNPDevice `xml:"device"`
}

Jump to

Keyboard shortcuts

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