rr.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef foorrhfoo
  2. #define foorrhfoo
  3. /***
  4. This file is part of avahi.
  5. avahi is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. avahi is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
  12. Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with avahi; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  16. USA.
  17. ***/
  18. /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
  19. #include <inttypes.h>
  20. #include <sys/types.h>
  21. #include <avahi-common/strlst.h>
  22. #include <avahi-common/address.h>
  23. #include <avahi-common/cdecl.h>
  24. AVAHI_C_DECL_BEGIN
  25. /** DNS record types, see RFC 1035, in addition to those defined in defs.h */
  26. enum {
  27. AVAHI_DNS_TYPE_ANY = 0xFF, /**< Special query type for requesting all records */
  28. AVAHI_DNS_TYPE_OPT = 41, /**< EDNS0 option */
  29. AVAHI_DNS_TYPE_TKEY = 249,
  30. AVAHI_DNS_TYPE_TSIG = 250,
  31. AVAHI_DNS_TYPE_IXFR = 251,
  32. AVAHI_DNS_TYPE_AXFR = 252
  33. };
  34. /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
  35. enum {
  36. AVAHI_DNS_CLASS_ANY = 0xFF, /**< Special query type for requesting all records */
  37. 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 */
  38. 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 */
  39. };
  40. /** Encapsulates a DNS query key consisting of class, type and
  41. name. Use avahi_key_ref()/avahi_key_unref() for manipulating the
  42. reference counter. The structure is intended to be treated as "immutable", no
  43. changes should be imposed after creation */
  44. typedef struct AvahiKey {
  45. int ref; /**< Reference counter */
  46. char *name; /**< Record name */
  47. uint16_t clazz; /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
  48. uint16_t type; /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
  49. } AvahiKey;
  50. /** Encapsulates a DNS resource record. The structure is intended to
  51. * be treated as "immutable", no changes should be imposed after
  52. * creation. */
  53. typedef struct AvahiRecord {
  54. int ref; /**< Reference counter */
  55. AvahiKey *key; /**< Reference to the query key of this record */
  56. uint32_t ttl; /**< DNS TTL of this record */
  57. union {
  58. struct {
  59. void* data;
  60. uint16_t size;
  61. } generic; /**< Generic record data for unknown types */
  62. struct {
  63. uint16_t priority;
  64. uint16_t weight;
  65. uint16_t port;
  66. char *name;
  67. } srv; /**< Data for SRV records */
  68. struct {
  69. char *name;
  70. } ptr, ns, cname; /**< Data for PTR, NS and CNAME records */
  71. struct {
  72. char *cpu;
  73. char *os;
  74. } hinfo; /**< Data for HINFO records */
  75. struct {
  76. AvahiStringList *string_list;
  77. } txt; /**< Data for TXT records */
  78. struct {
  79. AvahiIPv4Address address;
  80. } a; /**< Data for A records */
  81. struct {
  82. AvahiIPv6Address address;
  83. } aaaa; /**< Data for AAAA records */
  84. } data; /**< Record data */
  85. } AvahiRecord;
  86. /** Create a new AvahiKey object. The reference counter will be set to 1. */
  87. AvahiKey *avahi_key_new(const char *name, uint16_t clazz, uint16_t type);
  88. /** Increase the reference counter of an AvahiKey object by one */
  89. AvahiKey *avahi_key_ref(AvahiKey *k);
  90. /** Decrease the reference counter of an AvahiKey object by one */
  91. void avahi_key_unref(AvahiKey *k);
  92. /** Check whether two AvahiKey object contain the same
  93. * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
  94. * other class/type. */
  95. int avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
  96. /** Return a numeric hash value for a key for usage in hash tables. */
  97. unsigned avahi_key_hash(const AvahiKey *k);
  98. /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
  99. AvahiRecord *avahi_record_new(AvahiKey *k, uint32_t ttl);
  100. /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
  101. AvahiRecord *avahi_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
  102. /** Increase the reference counter of an AvahiRecord by one. */
  103. AvahiRecord *avahi_record_ref(AvahiRecord *r);
  104. /** Decrease the reference counter of an AvahiRecord by one. */
  105. void avahi_record_unref(AvahiRecord *r);
  106. /** Return a textual representation of the specified DNS class. The
  107. * returned pointer points to a read only internal string. */
  108. const char *avahi_dns_class_to_string(uint16_t clazz);
  109. /** Return a textual representation of the specified DNS class. The
  110. * returned pointer points to a read only internal string. */
  111. const char *avahi_dns_type_to_string(uint16_t type);
  112. /** Create a textual representation of the specified key. avahi_free() the
  113. * result! */
  114. char *avahi_key_to_string(const AvahiKey *k);
  115. /** Create a textual representation of the specified record, similar
  116. * in style to BIND zone file data. avahi_free() the result! */
  117. char *avahi_record_to_string(const AvahiRecord *r);
  118. /** Check whether two records are equal (regardless of the TTL */
  119. int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
  120. /** Check whether the specified key is valid */
  121. int avahi_key_is_valid(AvahiKey *k);
  122. /** Check whether the specified record is valid */
  123. int avahi_record_is_valid(AvahiRecord *r);
  124. /** Parse a binary rdata object and fill it into *record. This function is actually implemented in dns.c */
  125. int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size);
  126. /** Serialize an AvahiRecord object into binary rdata. This function is actually implemented in dns.c */
  127. size_t avahi_rdata_serialize(AvahiRecord *record, void *rdata, size_t max_size);
  128. /** Return TRUE if the AvahiRecord object is a link-local A or AAAA address */
  129. int avahi_record_is_link_local_address(const AvahiRecord *r);
  130. AVAHI_C_DECL_END
  131. #endif