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
29 #define AVAHI_DNS_PACKET_MAX_SIZE 9000
30 #define AVAHI_DNS_PACKET_HEADER_SIZE 12
31 #define AVAHI_DNS_PACKET_EXTRA_SIZE 48
33 typedef struct AvahiDnsPacket {
34 guint size, rindex, max_size;
35 GHashTable *name_table; /* for name compression */
38 #define AVAHI_DNS_PACKET_DATA(p) (((guint8*) p) + sizeof(AvahiDnsPacket))
40 AvahiDnsPacket* avahi_dns_packet_new(guint mtu);
41 AvahiDnsPacket* avahi_dns_packet_new_query(guint mtu);
42 AvahiDnsPacket* avahi_dns_packet_new_response(guint mtu, gboolean aa);
44 AvahiDnsPacket* avahi_dns_packet_new_reply(AvahiDnsPacket* p, guint mtu, gboolean copy_queries, gboolean aa);
46 void avahi_dns_packet_free(AvahiDnsPacket *p);
47 void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint index, guint16 v);
48 guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint index);
49 void avahi_dns_packet_inc_field(AvahiDnsPacket *p, guint index);
51 guint8 *avahi_dns_packet_extend(AvahiDnsPacket *p, guint l);
53 guint8 *avahi_dns_packet_append_uint16(AvahiDnsPacket *p, guint16 v);
54 guint8 *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, guint32 v);
55 guint8 *avahi_dns_packet_append_name(AvahiDnsPacket *p, const gchar *name);
56 guint8 *avahi_dns_packet_append_bytes(AvahiDnsPacket *p, gconstpointer, guint l);
57 guint8* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, gboolean unicast_response);
58 guint8* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, gboolean cache_flush, guint max_ttl);
59 guint8* avahi_dns_packet_append_string(AvahiDnsPacket *p, const gchar *s);
61 gint avahi_dns_packet_is_query(AvahiDnsPacket *p);
62 gint avahi_dns_packet_check_valid(AvahiDnsPacket *p);
64 gint avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, guint16 *ret_v);
65 gint avahi_dns_packet_consume_uint32(AvahiDnsPacket *p, guint32 *ret_v);
66 gint avahi_dns_packet_consume_name(AvahiDnsPacket *p, gchar *ret_name, guint l);
67 gint avahi_dns_packet_consume_bytes(AvahiDnsPacket *p, gpointer ret_data, guint l);
68 AvahiKey* avahi_dns_packet_consume_key(AvahiDnsPacket *p, gboolean *ret_unicast_response);
69 AvahiRecord* avahi_dns_packet_consume_record(AvahiDnsPacket *p, gboolean *ret_cache_flush);
70 gint avahi_dns_packet_consume_string(AvahiDnsPacket *p, gchar *ret_string, guint l);
72 gconstpointer avahi_dns_packet_get_rptr(AvahiDnsPacket *p);
74 gint avahi_dns_packet_skip(AvahiDnsPacket *p, guint length);
76 gboolean avahi_dns_packet_is_empty(AvahiDnsPacket *p);
77 guint avahi_dns_packet_space(AvahiDnsPacket *p);
79 #define AVAHI_DNS_FIELD_ID 0
80 #define AVAHI_DNS_FIELD_FLAGS 1
81 #define AVAHI_DNS_FIELD_QDCOUNT 2
82 #define AVAHI_DNS_FIELD_ANCOUNT 3
83 #define AVAHI_DNS_FIELD_NSCOUNT 4
84 #define AVAHI_DNS_FIELD_ARCOUNT 5
86 #define AVAHI_DNS_FLAG_QR (1 << 15)
87 #define AVAHI_DNS_FLAG_OPCODE (15 << 11)
88 #define AVAHI_DNS_FLAG_RCODE (15)
89 #define AVAHI_DNS_FLAG_TC (1 << 9)
90 #define AVAHI_DNS_FLAG_AA (1 << 10)
92 #define AVAHI_DNS_FLAGS(qr, opcode, aa, tc, rd, ra, z, ad, cd, rcode) \
93 (((guint16) !!qr << 15) | \
94 ((guint16) (opcode & 15) << 11) | \
95 ((guint16) !!aa << 10) | \
96 ((guint16) !!tc << 9) | \
97 ((guint16) !!rd << 8) | \
98 ((guint16) !!ra << 7) | \
99 ((guint16) !!ad << 5) | \
100 ((guint16) !!cd << 4) | \
101 ((guint16) (rd & 15)))