7 This file is part of avahi.
9 avahi is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 avahi is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17 Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with avahi; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #define AVAHI_DNS_PACKET_HEADER_SIZE 12
29 #define AVAHI_DNS_PACKET_EXTRA_SIZE 48
30 #define AVAHI_DNS_LABELS_MAX 127
31 #define AVAHI_DNS_RDATA_MAX 0xFFFF
32 #define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
34 typedef struct AvahiDnsPacket {
35 size_t size, rindex, max_size;
36 AvahiHashmap *name_table; /* for name compression */
40 #define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
42 AvahiDnsPacket* avahi_dns_packet_new(unsigned mtu);
43 AvahiDnsPacket* avahi_dns_packet_new_query(unsigned mtu);
44 AvahiDnsPacket* avahi_dns_packet_new_response(unsigned mtu, int aa);
46 AvahiDnsPacket* avahi_dns_packet_new_reply(AvahiDnsPacket* p, unsigned mtu, int copy_queries, int aa);
48 void avahi_dns_packet_free(AvahiDnsPacket *p);
49 void avahi_dns_packet_set_field(AvahiDnsPacket *p, unsigned idx, uint16_t v);
50 uint16_t avahi_dns_packet_get_field(AvahiDnsPacket *p, unsigned idx);
51 void avahi_dns_packet_inc_field(AvahiDnsPacket *p, unsigned idx);
53 uint8_t *avahi_dns_packet_extend(AvahiDnsPacket *p, size_t l);
55 void avahi_dns_packet_cleanup_name_table(AvahiDnsPacket *p);
57 uint8_t *avahi_dns_packet_append_uint16(AvahiDnsPacket *p, uint16_t v);
58 uint8_t *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, uint32_t v);
59 uint8_t *avahi_dns_packet_append_name(AvahiDnsPacket *p, const char *name);
60 uint8_t *avahi_dns_packet_append_bytes(AvahiDnsPacket *p, const void *d, size_t l);
61 uint8_t* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, int unicast_response);
62 uint8_t* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, int cache_flush, unsigned max_ttl);
63 uint8_t* avahi_dns_packet_append_string(AvahiDnsPacket *p, const char *s);
65 int avahi_dns_packet_is_query(AvahiDnsPacket *p);
66 int avahi_dns_packet_check_valid(AvahiDnsPacket *p);
67 int avahi_dns_packet_check_valid_multicast(AvahiDnsPacket *p);
69 int avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, uint16_t *ret_v);
70 int avahi_dns_packet_consume_uint32(AvahiDnsPacket *p, uint32_t *ret_v);
71 int avahi_dns_packet_consume_name(AvahiDnsPacket *p, char *ret_name, size_t l);
72 int avahi_dns_packet_consume_bytes(AvahiDnsPacket *p, void* ret_data, size_t l);
73 AvahiKey* avahi_dns_packet_consume_key(AvahiDnsPacket *p, int *ret_unicast_response);
74 AvahiRecord* avahi_dns_packet_consume_record(AvahiDnsPacket *p, int *ret_cache_flush);
75 int avahi_dns_packet_consume_string(AvahiDnsPacket *p, char *ret_string, size_t l);
77 const void* avahi_dns_packet_get_rptr(AvahiDnsPacket *p);
79 int avahi_dns_packet_skip(AvahiDnsPacket *p, size_t length);
81 int avahi_dns_packet_is_empty(AvahiDnsPacket *p);
82 size_t avahi_dns_packet_space(AvahiDnsPacket *p);
84 #define AVAHI_DNS_FIELD_ID 0
85 #define AVAHI_DNS_FIELD_FLAGS 1
86 #define AVAHI_DNS_FIELD_QDCOUNT 2
87 #define AVAHI_DNS_FIELD_ANCOUNT 3
88 #define AVAHI_DNS_FIELD_NSCOUNT 4
89 #define AVAHI_DNS_FIELD_ARCOUNT 5
91 #define AVAHI_DNS_FLAG_QR (1 << 15)
92 #define AVAHI_DNS_FLAG_OPCODE (15 << 11)
93 #define AVAHI_DNS_FLAG_RCODE (15)
94 #define AVAHI_DNS_FLAG_TC (1 << 9)
95 #define AVAHI_DNS_FLAG_AA (1 << 10)
97 #define AVAHI_DNS_FLAGS(qr, opcode, aa, tc, rd, ra, z, ad, cd, rcode) \
98 (((uint16_t) !!qr << 15) | \
99 ((uint16_t) (opcode & 15) << 11) | \
100 ((uint16_t) !!aa << 10) | \
101 ((uint16_t) !!tc << 9) | \
102 ((uint16_t) !!rd << 8) | \
103 ((uint16_t) !!ra << 7) | \
104 ((uint16_t) !!ad << 5) | \
105 ((uint16_t) !!cd << 4) | \
106 ((uint16_t) (rcode & 15)))
108 #define AVAHI_MDNS_SUFFIX_LOCAL "local"
109 #define AVAHI_MDNS_SUFFIX_ADDR_IPV4 "254.169.in-addr.arpa"
110 #define AVAHI_MDNS_SUFFIX_ADDR_IPV6 "0.8.e.f.ip6.arpa"