Zero Configuration Networking: Using the Java APIs, Part 2
Pages: 1, 2, 3, 4, 5, 6
Adding, Updating, and Removing Additional Records
A standard DNS-SD service is described by two DNS records: an SRV record, giving target host and port number, and a TXT record, containing zero or more key/value attributes. For almost all applications, advertising a service with these two records is all that's needed. However, there are certain applications—iChat being the prime example—that have extra requirements. For the benefit of applications like this, DNS-SD provides some additional specialized APIs to add, update, and remove additional records.
DNS-SD allows applications to add additional DNS records to an existing service registration using DNSSDRegistration's addRecord method. iChat attaches a small JPEG image to each advertised service, containing the user's icon or picture, and because this is too large to fit in a TXT record attribute, iChat attaches it as an additional record. Adding records like this is something that should not be done indiscriminately because of the cost in increased network traffic, but in the case of iChat, it is the most appropriate way to communicate a user's icon to all the other iChat clients on the local network.
Calling addRecord( ) returns a DNSRecord object, which supports two operations, update( ) and remove( ). If you need to change the data in the record (as iChat does when the user changes the icon), then you can use update( ) to provide new data to replace the old data in the record.
When adding a record, you need to specify the DNS type of the record. The original DNS types are listed in RFC 1035, and newer types are given in later RFCs. For example, the SRV record type (type 33) is specified in RFC 2782. You can also find the list of currently defined DNS types at http://www.iana.org/assignments/dns-parameters. On many systems, you can also find the defined types listed in one of the C header files, such as /usr/include/nameser.h or /usr/include/dns_sd.h. The current IANA list of DNS types is shown in Table 8-2.
Table 8-2. DNS resource record types
|
TYPE |
Value |
Meaning |
Reference |
|---|---|---|---|
|
A |
|
A host address |
RFC1035 |
|
NS |
|
An authoritative name server |
RFC1035 |
|
MD |
|
A mail destination (OBSOLETE; use MX) |
RFC1035 |
|
MF |
|
A mail forwarder (OBSOLETE; use MX) |
RFC1035 |
|
CNAME |
|
The canonical name for an alias |
RFC1035 |
|
SOA |
|
Marks the start of a zone of authority |
RFC1035 |
|
MB |
|
A mailbox domain name (EXPERIMENTAL) |
RFC1035 |
|
MG |
|
A mail group member (EXPERIMENTAL) |
RFC1035 |
|
MR |
|
A mail rename domain name (EXPERIMENTAL) |
RFC1035 |
|
NULL |
|
A null RR (EXPERIMENTAL) |
RFC1035 |
|
WKS |
|
A well-known service description |
RFC1035 |
|
PTR |
|
A domain name pointer |
RFC1035 |
|
HINFO |
|
Host information |
RFC1035 |
|
MINFO |
|
Mailbox or mail list information |
RFC1035 |
|
MX |
|
Mail exchange |
RFC1035 |
|
TXT |
|
Text strings |
RFC1035 |
|
RP |
|
For Responsible Person |
RFC1183 |
|
AFSDB |
|
For AFS Data Base location |
RFC1183 |
|
X25 |
|
For X.25 PSDN address |
RFC1183 |
|
ISDN |
|
For ISDN address |
RFC1183 |
|
RT |
|
For Route Through |
RFC1183 |
|
NSAP |
|
For NSAP address, NSAP style A record |
RFC1706 |
|
NSAP-PTR |
|
|
|
|
SIG |
|
For security signature |
RFC2535 RFC3755 RFC4034 |
|
KEY |
|
For security key |
RFC2535 RFC3755 RFC4034 |
|
PX |
|
X.400 mail mapping information |
RFC2163 |
|
GPOS |
|
Geographical Position |
RFC1712 |
|
AAAA |
|
IP6 Address |
Thomson |
|
LOC |
|
Location Information |
Vixie |
|
NXT |
|
Next Domain (OBSOLETE) |
RFC2535, RFC3755 |
|
EID |
|
Endpoint Identifier |
Patton |
|
NIMLOC |
|
Nimrod Locator |
Patton |
|
SRV |
|
Server Selection |
RFC2782 |
|
ATMA |
|
ATM Address |
Dobrowski |
|
NAPTR |
|
Naming Authority Pointer |
RFC2168, RFC2915 |
|
KX |
|
Key Exchanger |
RFC2230 |
|
CERT |
|
CERT |
RFC2538 |
|
A6 |
|
A6 |
RFC2874 |
|
DNAME |
|
DNAME |
RFC2672 |
|
SINK |
|
SINK |
Eastlake |
|
OPT |
|
OPT |
RFC2671 |
|
APL |
|
APL |
RFC3123 |
|
DS |
|
Delegation Signer |
RFC3658 |
|
SSHFP |
|
SSH Key Fingerprint |
RFC-ietf-secsh-dns-05.txt |
|
IPSECKEY |
|
IPSECKEY |
RFC4025 |
|
RRSIG |
|
RRSIG |
RFC3755 |
|
NSEC |
|
NSEC |
RFC3755 |
|
DNSKEY |
|
DNSKEY |
RFC3755 |
|
UINFO |
|
IANA-Reserved |
|
|
UID |
|
IANA-Reserved |
|
|
GID |
|
IANA-Reserved |
|
|
UNSPEC |
|
IANA-Reserved |
|
|
TKEY |
|
Transaction Key |
RFC2930 |
|
TSIG |
|
Transaction Signature |
RFC2845 |
|
IXFR |
|
Incremental transfer |
RFC1995 |
|
AXFR |
|
Transfer of an entire zone |
RFC1035 |
|
MAILB |
|
Mailbox-related RRs (MB, MG, or MR) |
RFC1035 |
|
MAILA |
|
Mail agent RRs (OBSOLETE; see MX) |
RFC1035 |
|
ANY |
|
A request for any record(s) |
RFC1035 |
When adding or updating records, it is your responsibility to make sure that the byte array data you provide is properly formatted for the DNS record type in question. You can specify the DNS time to live (TTL), though for most applications, it's most sensible to simply pass zero and let DNS-SD use its default TTL.