1 #ifndef foorrhfoo
2 #define foorrhfoo
3 
4 /***
5   This file is part of avahi.
6 
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.
11 
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.
16 
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
20   USA.
21 ***/
22 
23 /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
24 
25 #include <inttypes.h>
26 #include <sys/types.h>
27 
28 #include <avahi-common/strlst.h>
29 #include <avahi-common/address.h>
30 #include <avahi-common/cdecl.h>
31 
32 AVAHI_C_DECL_BEGIN
33 
34 /** DNS record types, see RFC 1035, in addition to those defined in defs.h */
35 enum {
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
42 };
43 
44 /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
45 enum {
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 */
49 };
50 
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 */
60 } AvahiKey;
61 
62 /** Encapsulates a DNS resource record. The structure is intended to
63  * be treated as "immutable", no changes should be imposed after
64  * creation. */
65 typedef struct AvahiRecord {
66     int ref;         /**< Reference counter */
67     AvahiKey *key;   /**< Reference to the query key of this record */
68 
69     uint32_t ttl;     /**< DNS TTL of this record */
70 
71     union {
72 
73         struct {
74             void* data;
75             uint16_t size;
76         } generic; /**< Generic record data for unknown types */
77 
78         struct {
79             uint16_t priority;
80             uint16_t weight;
81             uint16_t port;
82             char *name;
83         } srv; /**< Data for SRV records */
84 
85         struct {
86             char *name;
87         } ptr, ns, cname; /**< Data for PTR, NS and CNAME records */
88 
89         struct {
90             char *cpu;
91             char *os;
92         } hinfo; /**< Data for HINFO records */
93 
94         struct {
95             AvahiStringList *string_list;
96         } txt; /**< Data for TXT records */
97 
98         struct {
99             AvahiIPv4Address address;
100         } a; /**< Data for A records */
101 
102         struct {
103             AvahiIPv6Address address;
104         } aaaa; /**< Data for AAAA records */
105 
106     } data; /**< Record data */
107 
108 } AvahiRecord;
109 
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);
112 
113 /** Increase the reference counter of an AvahiKey object by one */
114 AvahiKey *avahi_key_ref(AvahiKey *k);
115 
116 /** Decrease the reference counter of an AvahiKey object by one */
117 void avahi_key_unref(AvahiKey *k);
118 
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);
123 
124 /** Return a numeric hash value for a key for usage in hash tables. */
125 unsigned avahi_key_hash(const AvahiKey *k);
126 
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);
129 
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);
132 
133 /** Increase the reference counter of an AvahiRecord by one. */
134 AvahiRecord *avahi_record_ref(AvahiRecord *r);
135 
136 /** Decrease the reference counter of an AvahiRecord by one. */
137 void avahi_record_unref(AvahiRecord *r);
138 
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);
142 
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);
146 
147 /** Create a textual representation of the specified key. avahi_free() the
148  * result! */
149 char *avahi_key_to_string(const AvahiKey *k);
150 
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);
154 
155 /** Check whether two records are equal (regardless of the TTL */
156 int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
157 
158 /** Check whether the specified key is valid */
159 int avahi_key_is_valid(AvahiKey *k);
160 
161 /** Check whether the specified record is valid */
162 int avahi_record_is_valid(AvahiRecord *r);
163 
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);
166 
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);
169 
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);
172 
173 AVAHI_C_DECL_END
174 
175 #endif
176