Class: DNSSD::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/dnssd/record.rb,
ext/dnssd/record.c,
ext/dnssd/service.c

Overview

Created when adding a DNS record using DNSSD::Service#add_record. Provides convenience methods for creating the DNS record.

See also RFC 1035

Constant Summary collapse

VALUE_TO_NAME =

Maps record constant values to the constant name

IN =

Internet service class

UINT2NUM(kDNSServiceClass_IN)
ANY =

Wildcard match.

UINT2NUM(kDNSServiceType_ANY)
A =

Host address.

UINT2NUM(kDNSServiceType_A)
A6 =

IPv6 Address (deprecated)

UINT2NUM(kDNSServiceType_A6)
AAAA =

IPv6 Address.

UINT2NUM(kDNSServiceType_AAAA)
APL =

Address Prefix List

UINT2NUM(kDNSServiceType_APL)
AFSDB =

AFS cell database.

UINT2NUM(kDNSServiceType_AFSDB)
ATMA =

ATM Address

UINT2NUM(kDNSServiceType_ATMA)
AXFR =

Transfer zone of authority.

UINT2NUM(kDNSServiceType_AXFR)
CERT =

Certification record

UINT2NUM(kDNSServiceType_CERT)
CNAME =

Canonical name.

UINT2NUM(kDNSServiceType_CNAME)
DHCID =

DHCID

UINT2NUM(kDNSServiceType_DHCID)
DNAME =

Non-terminal DNAME (for IPv6)

UINT2NUM(kDNSServiceType_DNAME)
DNSKEY =

DNSKEY

UINT2NUM(kDNSServiceType_DNSKEY)
DS =

Delegation Signer

UINT2NUM(kDNSServiceType_DS)
EID =

Endpoint identifier.

UINT2NUM(kDNSServiceType_EID)
GPOS =

Geographical position (withdrawn).

UINT2NUM(kDNSServiceType_GPOS)
HINFO =

Host information.

UINT2NUM(kDNSServiceType_HINFO)
IPSECKEY =

IPSECKEY

UINT2NUM(kDNSServiceType_IPSECKEY)
ISDN =

ISDN calling address.

UINT2NUM(kDNSServiceType_ISDN)
IXFR =

Incremental zone transfer.

UINT2NUM(kDNSServiceType_IXFR)
KEY =

Security key.

UINT2NUM(kDNSServiceType_KEY)
KX =

Key Exchange

UINT2NUM(kDNSServiceType_KX)
LOC =

Location Information.

UINT2NUM(kDNSServiceType_LOC)
MAILA =

Transfer mail agent records.

UINT2NUM(kDNSServiceType_MAILA)
MAILB =

Transfer mailbox records.

UINT2NUM(kDNSServiceType_MAILB)
MB =

Mailbox domain name.

UINT2NUM(kDNSServiceType_MB)
MD =

Mail destination.

UINT2NUM(kDNSServiceType_MD)
MF =

Mail forwarder.

UINT2NUM(kDNSServiceType_MF)
MG =

Mail group member.

UINT2NUM(kDNSServiceType_MG)
MINFO =

Mailbox information.

UINT2NUM(kDNSServiceType_MINFO)
MR =

Mail rename name.

UINT2NUM(kDNSServiceType_MR)
MX =

Mail routing information.

UINT2NUM(kDNSServiceType_MX)
NAPTR =

Naming Authority PoinTeR

UINT2NUM(kDNSServiceType_NAPTR)
NIMLOC =

Nimrod Locator.

UINT2NUM(kDNSServiceType_NIMLOC)
NS =

Authoritative server.

UINT2NUM(kDNSServiceType_NS)
NSAP =

NSAP address.

UINT2NUM(kDNSServiceType_NSAP)
NSAP_PTR =

Reverse NSAP lookup (deprecated).

UINT2NUM(kDNSServiceType_NSAP_PTR)
NSEC =

NSEC

UINT2NUM(kDNSServiceType_NSEC)
NULL =

Null resource record.

UINT2NUM(kDNSServiceType_NULL)
NXT =

Next domain (security).

UINT2NUM(kDNSServiceType_NXT)
OPT =

EDNS0 option (meta-RR)

UINT2NUM(kDNSServiceType_OPT)
PTR =

Domain name pointer.

UINT2NUM(kDNSServiceType_PTR)
PX =

X.400 mail mapping.

UINT2NUM(kDNSServiceType_PX)
RP =

Responsible person.

UINT2NUM(kDNSServiceType_RP)
RRSIG =

RRSIG

UINT2NUM(kDNSServiceType_RRSIG)
RT =

Router.

UINT2NUM(kDNSServiceType_RT)
SIG =

Security signature.

UINT2NUM(kDNSServiceType_SIG)
SINK =

Kitchen sink (experimental)

UINT2NUM(kDNSServiceType_SINK)
SOA =

Start of authority zone.

UINT2NUM(kDNSServiceType_SOA)
SRV =

Server Selection.

UINT2NUM(kDNSServiceType_SRV)
SSHFP =

SSH Key Fingerprint

UINT2NUM(kDNSServiceType_SSHFP)
TKEY =

Transaction key

UINT2NUM(kDNSServiceType_TKEY)
TSIG =

Transaction signature.

UINT2NUM(kDNSServiceType_TSIG)
TXT =

One or more text strings (NOT “zero or more…”).

UINT2NUM(kDNSServiceType_TXT)
WKS =

Well known service.

UINT2NUM(kDNSServiceType_WKS)
X25 =

X_25 calling address.

UINT2NUM(kDNSServiceType_X25)

Class Method Summary collapse

Class Method Details

.string_to_character_string(string) ⇒ Object

Turns string into an RFC-1035 character-string

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/dnssd/record.rb', line 24

def self.string_to_character_string(string)
  length = string.length
  raise ArgumentError, "#{string.inspect} is too long (255 bytes max)" if
    length > 255
  "#{length.chr}#{string}"
end

.string_to_domain_name(string) ⇒ Object

Turns string into an RFC-1035 domain-name



34
35
36
37
38
# File 'lib/dnssd/record.rb', line 34

def self.string_to_domain_name(string)
  string.split('.').map do |part|
    string_to_character_string part
  end.join('') << "\0"
end

.to_data(type, *args) ⇒ Object

Encodes resource args into type. Handles:

A AAAA CNAME MX NS PTR SOA SRV TXT

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dnssd/record.rb', line 45

def self.to_data(type, *args)
  raise ArgumentError, "unknown type #{type}" unless VALUE_TO_NAME.key? type

  data = case type
         when A then
           addr = args.shift
           addr = IPAddr.new addr unless IPAddr === addr
           raise ArgumentError, "#{addr} is not IPv4" unless addr.ipv4?
           addr.hton
         when AAAA then
           addr = args.shift
           addr = IPAddr.new addr unless IPAddr === addr
           raise ArgumentError, "#{addr} is not IPv6" unless addr.ipv6?
           addr.hton
         when CNAME, NS, PTR then
           string_to_domain_name args.shift
         when MX then
           [args.shift, string_to_domain_name(args.shift)].pack 'na*'
         when SOA then
           [
             string_to_domain_name(args.shift),
             string_to_domain_name(args.shift),
             args.shift, args.shift, args.shift, args.shift, args.shift
           ].pack 'a*a*NNNNN'
         when SRV then
           [
             args.shift, args.shift, args.shift,
             string_to_domain_name(args.shift)
           ].pack 'nnna*'
         when TXT then
           data = args.map do |string|
             string_to_character_string string
           end.join ''

           raise ArgumentError,
                 "TXT record too long (#{data.length} bytes)" if
             data.length > 65535

           args.clear

           data
         else
           raise ArgumentError, "unhandled record type #{VALUE_TO_NAME[type]}"
         end

  raise ArgumentError, "Too many arguments for #{VALUE_TO_NAME[type]}" unless
    args.empty?

  data
end