5 This file is part of avahi.
7 avahi is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 avahi is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with avahi; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
26 #include <sys/types.h>
28 #include <avahi-common/strlst.h>
29 #include <avahi-common/address.h>
30 #include <avahi-common/cdecl.h>
34 /** DNS record types, see RFC 1035, in addition to those defined in defs.h */
36 AVAHI_DNS_TYPE_ANY = 0xFF, /**< Special query type for requesting all records */
37 AVAHI_DNS_TYPE_OPT = 41, /**< EDNS0 option */
38 AVAHI_DNS_TYPE_TKEY = 249,
39 AVAHI_DNS_TYPE_TSIG = 250,
40 AVAHI_DNS_TYPE_IXFR = 251,
41 AVAHI_DNS_TYPE_AXFR = 252
44 /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
46 AVAHI_DNS_CLASS_ANY = 0xFF, /**< Special query type for requesting all records */
47 AVAHI_DNS_CACHE_FLUSH = 0x8000, /**< Not really a class but a bit which may be set in response packets, see mDNS spec for more information */
48 AVAHI_DNS_UNICAST_RESPONSE = 0x8000 /**< Not really a class but a bit which may be set in query packets, see mDNS spec for more information */
51 /** Encapsulates a DNS query key consisting of class, type and
52 name. Use avahi_key_ref()/avahi_key_unref() for manipulating the
53 reference counter. The structure is intended to be treated as "immutable", no
54 changes should be imposed after creation */
55 typedef struct AvahiKey {
56 int ref; /**< Reference counter */
57 char *name; /**< Record name */
58 uint16_t clazz; /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
59 uint16_t type; /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
62 /** Encapsulates a DNS resource record. The structure is intended to
63 * be treated as "immutable", no changes should be imposed after
65 typedef struct AvahiRecord {
66 int ref; /**< Reference counter */
67 AvahiKey *key; /**< Reference to the query key of this record */
69 uint32_t ttl; /**< DNS TTL of this record */
76 } generic; /**< Generic record data for unknown types */
83 } srv; /**< Data for SRV records */
87 } ptr, ns, cname; /**< Data for PTR, NS and CNAME records */
92 } hinfo; /**< Data for HINFO records */
95 AvahiStringList *string_list;
96 } txt; /**< Data for TXT records */
99 AvahiIPv4Address address;
100 } a; /**< Data for A records */
103 AvahiIPv6Address address;
104 } aaaa; /**< Data for AAAA records */
106 } data; /**< Record data */
110 /** Create a new AvahiKey object. The reference counter will be set to 1. */
111 AvahiKey *avahi_key_new(const char *name, uint16_t clazz, uint16_t type);
113 /** Increase the reference counter of an AvahiKey object by one */
114 AvahiKey *avahi_key_ref(AvahiKey *k);
116 /** Decrease the reference counter of an AvahiKey object by one */
117 void avahi_key_unref(AvahiKey *k);
119 /** Check whether two AvahiKey object contain the same
120 * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
121 * other class/type. */
122 int avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
124 /** Return a numeric hash value for a key for usage in hash tables. */
125 unsigned avahi_key_hash(const AvahiKey *k);
127 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
128 AvahiRecord *avahi_record_new(AvahiKey *k, uint32_t ttl);
130 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
131 AvahiRecord *avahi_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
133 /** Increase the reference counter of an AvahiRecord by one. */
134 AvahiRecord *avahi_record_ref(AvahiRecord *r);
136 /** Decrease the reference counter of an AvahiRecord by one. */
137 void avahi_record_unref(AvahiRecord *r);
139 /** Return a textual representation of the specified DNS class. The
140 * returned pointer points to a read only internal string. */
141 const char *avahi_dns_class_to_string(uint16_t clazz);
143 /** Return a textual representation of the specified DNS class. The
144 * returned pointer points to a read only internal string. */
145 const char *avahi_dns_type_to_string(uint16_t type);
147 /** Create a textual representation of the specified key. avahi_free() the
149 char *avahi_key_to_string(const AvahiKey *k);
151 /** Create a textual representation of the specified record, similar
152 * in style to BIND zone file data. avahi_free() the result! */
153 char *avahi_record_to_string(const AvahiRecord *r);
155 /** Check whether two records are equal (regardless of the TTL */
156 int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
158 /** Check whether the specified key is valid */
159 int avahi_key_is_valid(AvahiKey *k);
161 /** Check whether the specified record is valid */
162 int avahi_record_is_valid(AvahiRecord *r);
164 /** Parse a binary rdata object and fill it into *record. This function is actually implemented in dns.c */
165 int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size);
167 /** Serialize an AvahiRecord object into binary rdata. This function is actually implemented in dns.c */
168 size_t avahi_rdata_serialize(AvahiRecord *record, void *rdata, size_t max_size);
170 /** Return TRUE if the AvahiRecord object is a link-local A or AAAA address */
171 int avahi_record_is_link_local_address(const AvahiRecord *r);