4 * DNS packet definitions
6 * a Net::DNS like library for C
8 * (c) NLnet Labs, 2005-2006
10 * See the file LICENSE for the license
16 * Contains the definition of ldns_pkt and its parts, as well
17 * as functions to manipulate those.
24 #define LDNS_MAX_PACKETLEN 65535
26 /* allow flags to be given to ldns_pkt_query_new */
27 #define LDNS_QR 1 /* Query Response flag */
28 #define LDNS_AA 2 /* Authoritative Answer - server flag */
29 #define LDNS_TC 4 /* TrunCated - server flag */
30 #define LDNS_RD 8 /* Recursion Desired - query flag */
31 #define LDNS_CD 16 /* Checking Disabled - query flag */
32 #define LDNS_RA 32 /* Recursion Available - server flag */
33 #define LDNS_AD 64 /* Authenticated Data - server flag */
35 #include <ldns/error.h>
36 #include <ldns/common.h>
38 #include <ldns/edns.h>
45 /* opcodes for pkt's */
46 enum ldns_enum_pkt_opcode {
47 LDNS_PACKET_QUERY = 0,
48 LDNS_PACKET_IQUERY = 1,
49 LDNS_PACKET_STATUS = 2, /* there is no 3?? DNS is weird */
50 LDNS_PACKET_NOTIFY = 4,
51 LDNS_PACKET_UPDATE = 5
53 typedef enum ldns_enum_pkt_opcode ldns_pkt_opcode;
56 enum ldns_enum_pkt_rcode {
57 LDNS_RCODE_NOERROR = 0,
58 LDNS_RCODE_FORMERR = 1,
59 LDNS_RCODE_SERVFAIL = 2,
60 LDNS_RCODE_NXDOMAIN = 3,
61 LDNS_RCODE_NOTIMPL = 4,
62 LDNS_RCODE_REFUSED = 5,
63 LDNS_RCODE_YXDOMAIN = 6,
64 LDNS_RCODE_YXRRSET = 7,
65 LDNS_RCODE_NXRRSET = 8,
66 LDNS_RCODE_NOTAUTH = 9,
67 LDNS_RCODE_NOTZONE = 10
69 typedef enum ldns_enum_pkt_rcode ldns_pkt_rcode;
72 * Header of a dns packet
74 * Contains the information about the packet itself, as specified in RFC1035
76 4.1.1. Header section format
78 The header contains the following fields:
81 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
82 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
84 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
85 |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
86 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
88 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
90 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
92 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
94 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
98 ID A 16 bit identifier assigned by the program that
99 generates any kind of query. This identifier is copied
100 the corresponding reply and can be used by the requester
101 to match up replies to outstanding queries.
103 QR A one bit field that specifies whether this message is a
104 query (0), or a response (1).
106 OPCODE A four bit field that specifies kind of query in this
107 message. This value is set by the originator of a query
108 and copied into the response. The values are:
110 0 a standard query (QUERY)
112 1 an inverse query (IQUERY)
114 2 a server status request (STATUS)
116 3-15 reserved for future use
118 AA Authoritative Answer - this bit is valid in responses,
119 and specifies that the responding name server is an
120 authority for the domain name in question section.
122 Note that the contents of the answer section may have
123 multiple owner names because of aliases. The AA bit
125 corresponds to the name which matches the query name, or
126 the first owner name in the answer section.
128 TC TrunCation - specifies that this message was truncated
129 due to length greater than that permitted on the
130 transmission channel.
132 RD Recursion Desired - this bit may be set in a query and
133 is copied into the response. If RD is set, it directs
134 the name server to pursue the query recursively.
135 Recursive query support is optional.
137 RA Recursion Available - this be is set or cleared in a
138 response, and denotes whether recursive query support is
139 available in the name server.
141 Z Reserved for future use. Must be zero in all queries
144 RCODE Response code - this 4 bit field is set as part of
145 responses. The values have the following
150 1 Format error - The name server was
151 unable to interpret the query.
153 2 Server failure - The name server was
154 unable to process this query due to a
155 problem with the name server.
157 3 Name Error - Meaningful only for
158 responses from an authoritative name
159 server, this code signifies that the
160 domain name referenced in the query does
163 4 Not Implemented - The name server does
164 not support the requested kind of query.
166 5 Refused - The name server refuses to
167 perform the specified operation for
168 policy reasons. For example, a name
169 server may not wish to provide the
170 information to the particular requester,
171 or a name server may not wish to perform
172 a particular operation (e.g., zone
174 transfer) for particular data.
176 6-15 Reserved for future use.
178 QDCOUNT an unsigned 16 bit integer specifying the number of
179 entries in the question section.
181 ANCOUNT an unsigned 16 bit integer specifying the number of
182 resource records in the answer section.
184 NSCOUNT an unsigned 16 bit integer specifying the number of name
185 server resource records in the authority records
188 ARCOUNT an unsigned 16 bit integer specifying the number of
189 resource records in the additional records section.
193 struct ldns_struct_hdr
195 /** Id of a packet */
197 /** Query bit (0=query, 1=answer) */
199 /** Authoritative answer */
201 /** Packet truncated */
203 /** Recursion desired */
205 /** Checking disabled */
207 /** Recursion available */
209 /** Authentic data */
212 ldns_pkt_opcode _opcode; /* XXX 8 bits? */
224 typedef struct ldns_struct_hdr ldns_hdr;
229 * This structure contains a complete DNS packet (either a query or an answer)
231 * It is the complete representation of what you actually send to a
232 * nameserver, and what it sends back (assuming you are the client here).
234 struct ldns_struct_pkt
236 /** Header section */
238 /* extra items needed in a packet */
239 /** an rdf (A or AAAA) with the IP address of the server it is from */
240 ldns_rdf *_answerfrom;
241 /** Timestamp of the time the packet was sent or created */
242 struct timeval timestamp;
243 /** The duration of the query this packet is an answer to */
245 /** The size of the wire format of the packet in octets */
247 /** Optional tsig rr */
249 /** EDNS0 available buffer size, see RFC2671 */
250 uint16_t _edns_udp_size;
251 /** EDNS0 Extended rcode */
252 uint8_t _edns_extended_rcode;
254 uint8_t _edns_version;
255 /* OPT pseudo-RR presence flag */
256 uint8_t _edns_present;
257 /** Reserved EDNS data bits */
259 /** Arbitrary EDNS rdata */
260 ldns_rdf *_edns_data;
261 /** Structed EDNS data */
262 ldns_edns_option_list *_edns_list;
263 /** Question section */
264 ldns_rr_list *_question;
265 /** Answer section */
266 ldns_rr_list *_answer;
267 /** Authority section */
268 ldns_rr_list *_authority;
269 /** Additional section */
270 ldns_rr_list *_additional;
272 typedef struct ldns_struct_pkt ldns_pkt;
275 * The sections of a packet
277 enum ldns_enum_pkt_section {
278 LDNS_SECTION_QUESTION = 0,
279 LDNS_SECTION_ANSWER = 1,
280 LDNS_SECTION_AUTHORITY = 2,
281 LDNS_SECTION_ADDITIONAL = 3,
282 /** bogus section, if not interested */
283 LDNS_SECTION_ANY = 4,
284 /** used to get all non-question rrs from a packet */
285 LDNS_SECTION_ANY_NOQUESTION = 5
287 typedef enum ldns_enum_pkt_section ldns_pkt_section;
290 * The different types of packets
292 enum ldns_enum_pkt_type {
293 LDNS_PACKET_QUESTION,
294 LDNS_PACKET_REFERRAL,
296 LDNS_PACKET_NXDOMAIN,
300 typedef enum ldns_enum_pkt_type ldns_pkt_type;
308 * \param[in] p the packet
309 * \return the packet id
311 uint16_t ldns_pkt_id(const ldns_pkt *p);
313 * Read the packet's qr bit
314 * \param[in] p the packet
315 * \return value of the bit
317 bool ldns_pkt_qr(const ldns_pkt *p);
319 * Read the packet's aa bit
320 * \param[in] p the packet
321 * \return value of the bit
323 bool ldns_pkt_aa(const ldns_pkt *p);
325 * Read the packet's tc bit
326 * \param[in] p the packet
327 * \return value of the bit
329 bool ldns_pkt_tc(const ldns_pkt *p);
331 * Read the packet's rd bit
332 * \param[in] p the packet
333 * \return value of the bit
335 bool ldns_pkt_rd(const ldns_pkt *p);
337 * Read the packet's cd bit
338 * \param[in] p the packet
339 * \return value of the bit
341 bool ldns_pkt_cd(const ldns_pkt *p);
343 * Read the packet's ra bit
344 * \param[in] p the packet
345 * \return value of the bit
347 bool ldns_pkt_ra(const ldns_pkt *p);
349 * Read the packet's ad bit
350 * \param[in] p the packet
351 * \return value of the bit
353 bool ldns_pkt_ad(const ldns_pkt *p);
355 * Read the packet's code
356 * \param[in] p the packet
359 ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *p);
361 * Return the packet's response code
362 * \param[in] p the packet
363 * \return the response code
365 ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *p);
367 * Return the packet's qd count
368 * \param[in] p the packet
369 * \return the qd count
371 uint16_t ldns_pkt_qdcount(const ldns_pkt *p);
373 * Return the packet's an count
374 * \param[in] p the packet
375 * \return the an count
377 uint16_t ldns_pkt_ancount(const ldns_pkt *p);
379 * Return the packet's ns count
380 * \param[in] p the packet
381 * \return the ns count
383 uint16_t ldns_pkt_nscount(const ldns_pkt *p);
385 * Return the packet's ar count
386 * \param[in] p the packet
387 * \return the ar count
389 uint16_t ldns_pkt_arcount(const ldns_pkt *p);
392 * Return the packet's answerfrom
393 * \param[in] p packet
394 * \return the name of the server
396 ldns_rdf *ldns_pkt_answerfrom(const ldns_pkt *p);
399 * Return the packet's timestamp
400 * \param[in] p the packet
401 * \return the timestamp
403 struct timeval ldns_pkt_timestamp(const ldns_pkt *p);
405 * Return the packet's querytime
406 * \param[in] p the packet
407 * \return the querytime
409 uint32_t ldns_pkt_querytime(const ldns_pkt *p);
412 * Return the packet's size in bytes
413 * \param[in] p the packet
416 size_t ldns_pkt_size(const ldns_pkt *p);
419 * Return the number of RRs in the given section.
420 * Returns the sum of all RRs when LDNS_SECTION_ANY is given.
421 * Returns the sum of all non-question RRs when LDNS_SECTION_ANY_NOQUESTION
423 * \param[in] p the packet
424 * \param[in] s the section
425 * \return the number of RRs in the given section
427 uint16_t ldns_pkt_section_count(const ldns_pkt *p, ldns_pkt_section s);
430 * Return the packet's tsig pseudo rr's
431 * \param[in] p the packet
432 * \return the tsig rr
434 ldns_rr *ldns_pkt_tsig(const ldns_pkt *p);
437 * Return the packet's question section
438 * \param[in] p the packet
439 * \return the section
441 ldns_rr_list *ldns_pkt_question(const ldns_pkt *p);
443 * Return the packet's answer section
444 * \param[in] p the packet
445 * \return the section
447 ldns_rr_list *ldns_pkt_answer(const ldns_pkt *p);
449 * Return the packet's authority section
450 * \param[in] p the packet
451 * \return the section
453 ldns_rr_list *ldns_pkt_authority(const ldns_pkt *p);
455 * Return the packet's additional section
456 * \param[in] p the packet
457 * \return the section
459 ldns_rr_list *ldns_pkt_additional(const ldns_pkt *p);
461 * Return the packet's question, answer, authority and additional sections
462 * concatenated, in a new rr_list clone.
463 * \param[in] p the packet
466 ldns_rr_list *ldns_pkt_all(const ldns_pkt *p);
468 * Return the packet's answer, authority and additional sections concatenated,
469 * in a new rr_list clone. Like ldns_pkt_all but without the questions.
470 * \param[in] p the packet
471 * \return the rrs except the question rrs
473 ldns_rr_list *ldns_pkt_all_noquestion(const ldns_pkt *p);
476 * return all the rr_list's in the packet. Clone the lists, instead
477 * of returning pointers.
478 * \param[in] p the packet to look in
479 * \param[in] s what section(s) to return
480 * \return ldns_rr_list with the rr's or NULL if none were found
482 ldns_rr_list *ldns_pkt_get_section_clone(const ldns_pkt *p, ldns_pkt_section s);
485 * return all the rr with a specific name from a packet. Optionally
486 * specify from which section in the packet
487 * \param[in] p the packet
488 * \param[in] r the name
489 * \param[in] s the packet's section
490 * \return a list with the rr's or NULL if none were found
492 ldns_rr_list *ldns_pkt_rr_list_by_name(const ldns_pkt *p, const ldns_rdf *r, ldns_pkt_section s);
494 * return all the rr with a specific type from a packet. Optionally
495 * specify from which section in the packet
496 * \param[in] p the packet
497 * \param[in] t the type
498 * \param[in] s the packet's section
499 * \return a list with the rr's or NULL if none were found
501 ldns_rr_list *ldns_pkt_rr_list_by_type(const ldns_pkt *p, ldns_rr_type t, ldns_pkt_section s);
503 * return all the rr with a specific type and type from a packet. Optionally
504 * specify from which section in the packet
505 * \param[in] packet the packet
506 * \param[in] ownername the name
507 * \param[in] type the type
508 * \param[in] sec the packet's section
509 * \return a list with the rr's or NULL if none were found
511 ldns_rr_list *ldns_pkt_rr_list_by_name_and_type(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_rr_type type, ldns_pkt_section sec);
515 * check to see if an rr exist in the packet
516 * \param[in] pkt the packet to examine
517 * \param[in] sec in which section to look
518 * \param[in] rr the rr to look for
520 bool ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr);
524 * sets the flags in a packet.
525 * \param[in] pkt the packet to operate on
526 * \param[in] flags ORed values: LDNS_QR| LDNS_AR for instance
527 * \return true on success otherwise false
529 bool ldns_pkt_set_flags(ldns_pkt *pkt, uint16_t flags);
532 * Set the packet's id
533 * \param[in] p the packet
534 * \param[in] id the id to set
536 void ldns_pkt_set_id(ldns_pkt *p, uint16_t id);
538 * Set the packet's id to a random value
539 * \param[in] p the packet
541 void ldns_pkt_set_random_id(ldns_pkt *p);
543 * Set the packet's qr bit
544 * \param[in] p the packet
545 * \param[in] b the value to set (boolean)
547 void ldns_pkt_set_qr(ldns_pkt *p, bool b);
549 * Set the packet's aa bit
550 * \param[in] p the packet
551 * \param[in] b the value to set (boolean)
553 void ldns_pkt_set_aa(ldns_pkt *p, bool b);
555 * Set the packet's tc bit
556 * \param[in] p the packet
557 * \param[in] b the value to set (boolean)
559 void ldns_pkt_set_tc(ldns_pkt *p, bool b);
561 * Set the packet's rd bit
562 * \param[in] p the packet
563 * \param[in] b the value to set (boolean)
565 void ldns_pkt_set_rd(ldns_pkt *p, bool b);
567 * Set the packet's cd bit
568 * \param[in] p the packet
569 * \param[in] b the value to set (boolean)
571 void ldns_pkt_set_cd(ldns_pkt *p, bool b);
573 * Set the packet's ra bit
574 * \param[in] p the packet
575 * \param[in] b the value to set (boolean)
577 void ldns_pkt_set_ra(ldns_pkt *p, bool b);
579 * Set the packet's ad bit
580 * \param[in] p the packet
581 * \param[in] b the value to set (boolean)
583 void ldns_pkt_set_ad(ldns_pkt *p, bool b);
586 * Set the packet's opcode
587 * \param[in] p the packet
588 * \param[in] c the opcode
590 void ldns_pkt_set_opcode(ldns_pkt *p, ldns_pkt_opcode c);
592 * Set the packet's response code
593 * \param[in] p the packet
594 * \param[in] c the rcode
596 void ldns_pkt_set_rcode(ldns_pkt *p, uint8_t c);
598 * Set the packet's qd count
599 * \param[in] p the packet
600 * \param[in] c the count
602 void ldns_pkt_set_qdcount(ldns_pkt *p, uint16_t c);
604 * Set the packet's an count
605 * \param[in] p the packet
606 * \param[in] c the count
608 void ldns_pkt_set_ancount(ldns_pkt *p, uint16_t c);
610 * Set the packet's ns count
611 * \param[in] p the packet
612 * \param[in] c the count
614 void ldns_pkt_set_nscount(ldns_pkt *p, uint16_t c);
616 * Set the packet's arcount
617 * \param[in] p the packet
618 * \param[in] c the count
620 void ldns_pkt_set_arcount(ldns_pkt *p, uint16_t c);
622 * Set the packet's answering server
623 * \param[in] p the packet
624 * \param[in] r the address
626 void ldns_pkt_set_answerfrom(ldns_pkt *p, ldns_rdf *r);
628 * Set the packet's query time
629 * \param[in] p the packet
630 * \param[in] t the querytime in msec
632 void ldns_pkt_set_querytime(ldns_pkt *p, uint32_t t);
634 * Set the packet's size
635 * \param[in] p the packet
636 * \param[in] s the size
638 void ldns_pkt_set_size(ldns_pkt *p, size_t s);
641 * Set the packet's timestamp
642 * \param[in] p the packet
643 * \param[in] timeval the timestamp
645 void ldns_pkt_set_timestamp(ldns_pkt *p, struct timeval timeval);
647 * Set a packet's section count to x
648 * \param[in] p the packet
649 * \param[in] s the section
650 * \param[in] x the section count
652 void ldns_pkt_set_section_count(ldns_pkt *p, ldns_pkt_section s, uint16_t x);
654 * Set the packet's tsig rr
655 * \param[in] p the packet
656 * \param[in] t the tsig rr
658 void ldns_pkt_set_tsig(ldns_pkt *p, ldns_rr *t);
661 * looks inside the packet to determine
662 * what kind of packet it is, AUTH, NXDOMAIN, REFERRAL, etc.
663 * \param[in] p the packet to examine
664 * \return the type of packet
666 ldns_pkt_type ldns_pkt_reply_type(const ldns_pkt *p);
669 * return the packet's edns udp size
670 * \param[in] packet the packet
673 uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet);
675 * return the packet's edns extended rcode
676 * \param[in] packet the packet
679 uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet);
681 * return the packet's edns version
682 * \param[in] packet the packet
683 * \return the version
685 uint8_t ldns_pkt_edns_version(const ldns_pkt *packet);
687 * return the packet's edns z value
688 * \param[in] packet the packet
689 * \return the z value
691 uint16_t ldns_pkt_edns_z(const ldns_pkt *packet);
693 * return the packet's EDNS data
694 * \param[in] packet the packet
697 ldns_rdf *ldns_pkt_edns_data(const ldns_pkt *packet);
700 * return the packet's edns do bit
701 * \param[in] packet the packet
702 * \return the bit's value
704 bool ldns_pkt_edns_do(const ldns_pkt *packet);
706 * Set the packet's edns do bit
707 * \param[in] packet the packet
708 * \param[in] value the bit's new value
710 void ldns_pkt_set_edns_do(ldns_pkt *packet, bool value);
713 * return the packet's EDNS header bits that are unassigned.
715 uint16_t ldns_pkt_edns_unassigned(const ldns_pkt *packet);
718 * Set the packet's EDNS header bits that are unassigned.
719 * \param[in] packet the packet
720 * \param[in] value the value
722 void ldns_pkt_set_edns_unassigned(ldns_pkt *packet, uint16_t value);
725 * returns true if this packet needs and EDNS rr to be sent.
726 * At the moment the only reason is an expected packet
727 * size larger than 512 bytes, but for instance dnssec would
728 * be a good reason too.
730 * \param[in] packet the packet to check
731 * \return true if packet needs edns rr
733 bool ldns_pkt_edns(const ldns_pkt *packet);
736 * Returns a list of structured EDNS options. The list will be automatically
737 * freed when the packet is freed. The option list can be manipulated and
738 * will be used when converting the packet to wireformat with ldns_pkt2wire.
740 * \param[in] packet the packet which contains the EDNS data
741 * \return the list of EDNS options
743 ldns_edns_option_list* ldns_pkt_edns_get_option_list(ldns_pkt *packet);
746 * Set the packet's edns udp size
747 * \param[in] packet the packet
748 * \param[in] s the size
750 void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s);
752 * Set the packet's edns extended rcode
753 * \param[in] packet the packet
754 * \param[in] c the code
756 void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c);
758 * Set the packet's edns version
759 * \param[in] packet the packet
760 * \param[in] v the version
762 void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v);
764 * Set the packet's edns z value
765 * \param[in] packet the packet
766 * \param[in] z the value
768 void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z);
770 * Set the packet's EDNS data
771 * \param[in] packet the packet
772 * \param[in] data the data
774 void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data);
777 * Set the packet's structured EDNS data. Once an edns_option_list is set
778 * (or get), the option list will be used for converting into wireformat.
779 * \param[in] packet the packet
780 * \param[in] list the options list that will create the data
782 void ldns_pkt_set_edns_option_list(ldns_pkt *packet, ldns_edns_option_list *list);
785 * allocates and initializes a ldns_pkt structure.
786 * \return pointer to the new packet
788 ldns_pkt *ldns_pkt_new(void);
791 * frees the packet structure and all data that it contains.
792 * \param[in] packet The packet structure to free
795 void ldns_pkt_free(ldns_pkt *packet);
798 * creates a query packet for the given name, type, class.
799 * \param[out] p the packet to be returned
800 * \param[in] rr_name the name to query for (as string)
801 * \param[in] rr_type the type to query for
802 * \param[in] rr_class the class to query for
803 * \param[in] flags packet flags
804 * \return LDNS_STATUS_OK or a ldns_status mesg with the error
806 ldns_status ldns_pkt_query_new_frm_str(ldns_pkt **p, const char *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class , uint16_t flags);
809 * creates an IXFR request packet for the given name, class.
810 * adds the SOA record to the authority section.
811 * \param[out] p the packet to be returned
812 * \param[in] rr_name the name to query for (as string)
813 * \param[in] rr_class the class to query for
814 * \param[in] flags packet flags
815 * \param[in] soa soa record to be added to the authority section (not copied).
816 * \return LDNS_STATUS_OK or a ldns_status mesg with the error
818 ldns_status ldns_pkt_ixfr_request_new_frm_str(ldns_pkt **p, const char *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr* soa);
821 * creates a packet with a query in it for the given name, type and class.
822 * \param[in] rr_name the name to query for (not copied).
823 * The returned packet will take ownership of rr_name, so the caller should not free it.
824 * \param[in] rr_type the type to query for
825 * \param[in] rr_class the class to query for
826 * \param[in] flags packet flags
827 * \return ldns_pkt* a pointer to the new pkt
829 ldns_pkt *ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags);
832 * creates an IXFR request packet for the given name, type and class.
833 * adds the SOA record to the authority section.
834 * \param[in] rr_name the name to query for (not copied).
835 * The returned packet will take ownership of rr_name, so the caller should not free it.
836 * \param[in] rr_class the class to query for
837 * \param[in] flags packet flags
838 * \param[in] soa soa record to be added to the authority section (not copied).
839 * \return ldns_pkt* a pointer to the new pkt
841 ldns_pkt *ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr* soa);
844 * clones the given packet, creating a fully allocated copy
846 * \param[in] pkt the packet to clone
847 * \return ldns_pkt* pointer to the new packet
849 ldns_pkt *ldns_pkt_clone(const ldns_pkt *pkt);
852 * directly set the additional section
853 * \param[in] p packet to operate on
854 * \param[in] rr rrlist to set
856 void ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rr);
859 * directly set the answer section
860 * \param[in] p packet to operate on
861 * \param[in] rr rrlist to set
863 void ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rr);
866 * directly set the question section
867 * \param[in] p packet to operate on
868 * \param[in] rr rrlist to set
870 void ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rr);
873 * directly set the authority section
874 * \param[in] p packet to operate on
875 * \param[in] rr rrlist to set
877 void ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rr);
880 * push an rr on a packet
881 * \param[in] packet packet to operate on
882 * \param[in] section where to put it
883 * \param[in] rr rr to push
884 * \return a boolean which is true when the rr was added
886 bool ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr);
889 * push an rr on a packet, provided the RR is not there.
890 * \param[in] pkt packet to operate on
891 * \param[in] sec where to put it
892 * \param[in] rr rr to push
893 * \return a boolean which is true when the rr was added
895 bool ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr);
898 * push a rr_list on a packet
899 * \param[in] packet packet to operate on
900 * \param[in] section where to put it
901 * \param[in] list the rr_list to push
902 * \return a boolean which is true when the rr was added
904 bool ldns_pkt_push_rr_list(ldns_pkt *packet, ldns_pkt_section section, ldns_rr_list *list);
907 * push an rr_list to a packet, provided the RRs are not already there.
908 * \param[in] pkt packet to operate on
909 * \param[in] sec where to put it
910 * \param[in] list the rr_list to push
911 * \return a boolean which is true when the rr was added
913 bool ldns_pkt_safe_push_rr_list(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr_list *list);
916 * check if a packet is empty
917 * \param[in] p packet
918 * \return true: empty, false: not empty
920 bool ldns_pkt_empty(ldns_pkt *p);
926 #endif /* LDNS_PACKET_H */