packet.c
Go to the documentation of this file.
1/*
2 * packet.c
3 *
4 * dns packet implementation
5 *
6 * a Net::DNS like library for C
7 *
8 * (c) NLnet Labs, 2004-2006
9 *
10 * See the file LICENSE for the license
11 */
12
13#include <ldns/config.h>
14
15#include <ldns/ldns.h>
16
17#include <strings.h>
18#include <limits.h>
19
20#ifdef HAVE_SSL
21#include <openssl/rand.h>
22#endif
23
24/* Access functions
25 * do this as functions to get type checking
26 */
27
28#define LDNS_EDNS_MASK_DO_BIT 0x8000
29#define LDNS_EDNS_MASK_CO_BIT 0x4000
30#define LDNS_EDNS_MASK_UNASSIGNED (0xFFFF & ~( LDNS_EDNS_MASK_DO_BIT \
31 | LDNS_EDNS_MASK_CO_BIT ))
32
33
34/* TODO defines for 3600 */
35/* convert to and from numerical flag values */
37 { 3600, "do"},
38 { 0, NULL}
39};
40
41/* read */
42uint16_t
43ldns_pkt_id(const ldns_pkt *packet)
44{
45 return packet->_header->_id;
46}
47
48bool
49ldns_pkt_qr(const ldns_pkt *packet)
50{
51 return packet->_header->_qr;
52}
53
54bool
55ldns_pkt_aa(const ldns_pkt *packet)
56{
57 return packet->_header->_aa;
58}
59
60bool
61ldns_pkt_tc(const ldns_pkt *packet)
62{
63 return packet->_header->_tc;
64}
65
66bool
67ldns_pkt_rd(const ldns_pkt *packet)
68{
69 return packet->_header->_rd;
70}
71
72bool
73ldns_pkt_cd(const ldns_pkt *packet)
74{
75 return packet->_header->_cd;
76}
77
78bool
79ldns_pkt_ra(const ldns_pkt *packet)
80{
81 return packet->_header->_ra;
82}
83
84bool
85ldns_pkt_ad(const ldns_pkt *packet)
86{
87 return packet->_header->_ad;
88}
89
92{
93 return packet->_header->_opcode;
94}
95
98{
99 return packet->_header->_rcode;
100}
101
102uint16_t
104{
105 return packet->_header->_qdcount;
106}
107
108uint16_t
110{
111 return packet->_header->_ancount;
112}
113
114uint16_t
116{
117 return packet->_header->_nscount;
118}
119
120uint16_t
122{
123 return packet->_header->_arcount;
124}
125
128{
129 return packet->_question;
130}
131
134{
135 return packet->_answer;
136}
137
140{
141 return packet->_authority;
142}
143
146{
147 return packet->_additional;
148}
149
150/* return ALL section concatenated */
152ldns_pkt_all(const ldns_pkt *packet)
153{
154 ldns_rr_list *all, *prev_all;
155
157 ldns_pkt_question(packet),
158 ldns_pkt_answer(packet));
159 prev_all = all;
160 all = ldns_rr_list_cat_clone(all,
161 ldns_pkt_authority(packet));
162 ldns_rr_list_deep_free(prev_all);
163 prev_all = all;
164 all = ldns_rr_list_cat_clone(all,
165 ldns_pkt_additional(packet));
166 ldns_rr_list_deep_free(prev_all);
167 return all;
168}
169
172{
173 ldns_rr_list *all, *all2;
174
176 ldns_pkt_answer(packet),
177 ldns_pkt_authority(packet));
178 all2 = ldns_rr_list_cat_clone(all,
179 ldns_pkt_additional(packet));
180
182 return all2;
183}
184
185size_t
187{
188 return packet->_size;
189}
190
191uint32_t
193{
194 return packet->_querytime;
195}
196
197ldns_rdf *
199{
200 return packet->_answerfrom;
201}
202
203struct timeval
205{
206 return packet->timestamp;
207}
208
209uint16_t
211{
212 return packet->_edns_udp_size;
213}
214
215uint8_t
217{
218 return packet->_edns_extended_rcode;
219}
220
221uint8_t
223{
224 return packet->_edns_version;
225}
226
227uint16_t
229{
230 return packet->_edns_z;
231}
232
233bool
235{
236 return (packet->_edns_z & LDNS_EDNS_MASK_DO_BIT);
237}
238
239void
240ldns_pkt_set_edns_do(ldns_pkt *packet, bool value)
241{
242 if (value) {
243 packet->_edns_z = packet->_edns_z | LDNS_EDNS_MASK_DO_BIT;
244 } else {
245 packet->_edns_z = packet->_edns_z & ~LDNS_EDNS_MASK_DO_BIT;
246 }
247}
248
249bool
251{
252 return (packet->_edns_z & LDNS_EDNS_MASK_CO_BIT);
253}
254
255void
256ldns_pkt_set_edns_co(ldns_pkt *packet, bool value)
257{
258 if (value) {
259 packet->_edns_z = packet->_edns_z | LDNS_EDNS_MASK_CO_BIT;
260 } else {
261 packet->_edns_z = packet->_edns_z & ~LDNS_EDNS_MASK_CO_BIT;
262 }
263}
264
265uint16_t
267{
268 return (packet->_edns_z & LDNS_EDNS_MASK_UNASSIGNED);
269}
270
271void
273{
274 packet->_edns_z = (packet->_edns_z & ~LDNS_EDNS_MASK_UNASSIGNED)
275 | (value & LDNS_EDNS_MASK_UNASSIGNED);
276}
277
278ldns_rdf *
280{
281 return packet->_edns_data;
282}
283
284/* return only those rr that share the ownername */
287 const ldns_rdf *ownername,
289{
290 ldns_rr_list *rrs;
291 ldns_rr_list *ret;
292 uint16_t i;
293
294 if (!packet) {
295 return NULL;
296 }
297
298 rrs = ldns_pkt_get_section_clone(packet, sec);
299 ret = NULL;
300
301 for(i = 0; i < ldns_rr_list_rr_count(rrs); i++) {
303 ldns_rr_list_rr(rrs, i)),
304 ownername) == 0) {
305 /* owner names match */
306 if (ret == NULL) {
307 ret = ldns_rr_list_new();
308 }
311 ldns_rr_list_rr(rrs, i))
312 );
313 }
314 }
315
317
318 return ret;
319}
320
321/* return only those rr that share a type */
324 ldns_rr_type type,
326{
327 ldns_rr_list *rrs;
328 ldns_rr_list *new;
329 uint16_t i;
330
331 if(!packet) {
332 return NULL;
333 }
334
335 rrs = ldns_pkt_get_section_clone(packet, sec);
336 new = ldns_rr_list_new();
337
338 for(i = 0; i < ldns_rr_list_rr_count(rrs); i++) {
339 if (type == ldns_rr_get_type(ldns_rr_list_rr(rrs, i))) {
340 /* types match */
343 ldns_rr_list_rr(rrs, i))
344 );
345 }
346 }
348
349 if (ldns_rr_list_rr_count(new) == 0) {
351 return NULL;
352 } else {
353 return new;
354 }
355}
356
357/* return only those rrs that share name and type */
360 const ldns_rdf *ownername,
361 ldns_rr_type type,
363{
364 ldns_rr_list *rrs;
365 ldns_rr_list *new;
366 ldns_rr_list *ret;
367 uint16_t i;
368
369 if(!packet) {
370 return NULL;
371 }
372
373 rrs = ldns_pkt_get_section_clone(packet, sec);
374 new = ldns_rr_list_new();
375 ret = NULL;
376
377 for(i = 0; i < ldns_rr_list_rr_count(rrs); i++) {
378 if (type == ldns_rr_get_type(ldns_rr_list_rr(rrs, i)) &&
380 ownername
381 ) == 0
382 ) {
383 /* types match */
385 ret = new;
386 }
387 }
389 if (!ret) {
391 }
392 return ret;
393}
394
395bool
396ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr)
397{
398 bool result = false;
399
400 switch (sec) {
409 case LDNS_SECTION_ANY:
411 /* fallthrough */
413 result = result
417 }
418
419 return result;
420}
421
422uint16_t
424{
425 switch(s) {
427 return ldns_pkt_qdcount(packet);
429 return ldns_pkt_ancount(packet);
431 return ldns_pkt_nscount(packet);
433 return ldns_pkt_arcount(packet);
434 case LDNS_SECTION_ANY:
435 return ldns_pkt_qdcount(packet) +
436 ldns_pkt_ancount(packet) +
437 ldns_pkt_nscount(packet) +
438 ldns_pkt_arcount(packet);
440 return ldns_pkt_ancount(packet) +
441 ldns_pkt_nscount(packet) +
442 ldns_pkt_arcount(packet);
443 default:
444 return 0;
445 }
446}
447
448bool
450{
451 if (!p) {
452 return true; /* NULL is empty? */
453 }
455 return false;
456 } else {
457 return true;
458 }
459}
460
461
464{
465 switch(s) {
469 return ldns_rr_list_clone(ldns_pkt_answer(packet));
474 case LDNS_SECTION_ANY:
475 /* these are already clones */
476 return ldns_pkt_all(packet);
478 return ldns_pkt_all_noquestion(packet);
479 default:
480 return NULL;
481 }
482}
483
485 return pkt->_tsig_rr;
486}
487
488/* write */
489void
490ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
491{
492 packet->_header->_id = id;
493}
494
495void
497{
498 uint16_t rid = ldns_get_random();
499 ldns_pkt_set_id(packet, rid);
500}
501
502
503void
504ldns_pkt_set_qr(ldns_pkt *packet, bool qr)
505{
506 packet->_header->_qr = qr;
507}
508
509void
510ldns_pkt_set_aa(ldns_pkt *packet, bool aa)
511{
512 packet->_header->_aa = aa;
513}
514
515void
516ldns_pkt_set_tc(ldns_pkt *packet, bool tc)
517{
518 packet->_header->_tc = tc;
519}
520
521void
522ldns_pkt_set_rd(ldns_pkt *packet, bool rd)
523{
524 packet->_header->_rd = rd;
525}
526
527void
532
533void
535{
536 p->_question = rr;
537}
538
539void
541{
542 p->_answer = rr;
543}
544
545void
550
551void
552ldns_pkt_set_cd(ldns_pkt *packet, bool cd)
553{
554 packet->_header->_cd = cd;
555}
556
557void
558ldns_pkt_set_ra(ldns_pkt *packet, bool ra)
559{
560 packet->_header->_ra = ra;
561}
562
563void
564ldns_pkt_set_ad(ldns_pkt *packet, bool ad)
565{
566 packet->_header->_ad = ad;
567}
568
569void
571{
572 packet->_header->_opcode = opcode;
573}
574
575void
576ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
577{
578 packet->_header->_rcode = rcode;
579}
580
581void
582ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
583{
584 packet->_header->_qdcount = qdcount;
585}
586
587void
588ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
589{
590 packet->_header->_ancount = ancount;
591}
592
593void
594ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
595{
596 packet->_header->_nscount = nscount;
597}
598
599void
600ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
601{
602 packet->_header->_arcount = arcount;
603}
604
605void
606ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time)
607{
608 packet->_querytime = time;
609}
610
611void
613{
614 packet->_answerfrom = answerfrom;
615}
616
617void
618ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
619{
620 packet->timestamp.tv_sec = timeval.tv_sec;
621 packet->timestamp.tv_usec = timeval.tv_usec;
622}
623
624void
625ldns_pkt_set_size(ldns_pkt *packet, size_t s)
626{
627 packet->_size = s;
628}
629
630void
632{
633 packet->_edns_udp_size = s;
634}
635
636void
638{
639 packet->_edns_extended_rcode = c;
640}
641
642void
644{
645 packet->_edns_version = v;
646}
647
648void
649ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
650{
651 packet->_edns_z = z;
652}
653
654void
656{
657 packet->_edns_data = data;
658}
659
660void
662{
663 if (packet->_edns_list)
665 packet->_edns_list = list;
666}
667
668
669void
671{
672 switch(s) {
674 ldns_pkt_set_qdcount(packet, count);
675 break;
677 ldns_pkt_set_ancount(packet, count);
678 break;
680 ldns_pkt_set_nscount(packet, count);
681 break;
683 ldns_pkt_set_arcount(packet, count);
684 break;
685 case LDNS_SECTION_ANY:
687 break;
688 }
689}
690
692{
693 pkt->_tsig_rr = rr;
694}
695
696bool
698{
699 switch(section) {
701 if (!ldns_rr_list_push_rr(ldns_pkt_question(packet), rr)) {
702 return false;
703 }
704 ldns_pkt_set_qdcount(packet, ldns_pkt_qdcount(packet) + 1);
705 break;
707 if (!ldns_rr_list_push_rr(ldns_pkt_answer(packet), rr)) {
708 return false;
709 }
710 ldns_pkt_set_ancount(packet, ldns_pkt_ancount(packet) + 1);
711 break;
713 if (!ldns_rr_list_push_rr(ldns_pkt_authority(packet), rr)) {
714 return false;
715 }
716 ldns_pkt_set_nscount(packet, ldns_pkt_nscount(packet) + 1);
717 break;
719 if (!ldns_rr_list_push_rr(ldns_pkt_additional(packet), rr)) {
720 return false;
721 }
722 ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet) + 1);
723 break;
724 case LDNS_SECTION_ANY:
726 /* shouldn't this error? */
727 break;
728 }
729 return true;
730}
731
732bool
734{
735
736 /* check to see if its there */
737 if (ldns_pkt_rr(pkt, sec, rr)) {
738 /* already there */
739 return false;
740 }
741 return ldns_pkt_push_rr(pkt, sec, rr);
742}
743
744bool
746{
747 size_t i;
748 for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
749 if (!ldns_pkt_push_rr(p, s, ldns_rr_list_rr(list, i))) {
750 return false;
751 }
752 }
753 return true;
754}
755
756bool
758{
759 size_t i;
760 for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
761 if (!ldns_pkt_safe_push_rr(p, s, ldns_rr_list_rr(list, i))) {
762 return false;
763 }
764 }
765 return true;
766}
767
768bool
770{
771 return (ldns_pkt_edns_udp_size(pkt) > 0 ||
773 ldns_pkt_edns_data(pkt) ||
774 ldns_pkt_edns_do(pkt) ||
775 ldns_pkt_edns_co(pkt) ||
776 pkt->_edns_list ||
777 pkt->_edns_present
778 );
779}
780
785{
786 size_t pos = 0;
787 ldns_edns_option_list* edns_list;
788 size_t max;
789 const uint8_t* wire;
790
791 if (!edns_data)
792 return NULL;
793
794 max = ldns_rdf_size(edns_data);
795 wire = ldns_rdf_data(edns_data);
796 if (!max)
797 return NULL;
798
799 if (!(edns_list = ldns_edns_option_list_new()))
800 return NULL;
801
802 while (pos < max) {
803 ldns_edns_option* edns;
804 uint8_t *data;
805
806 if (pos + 4 > max) { /* make sure the header fits */
808 return NULL;
809 }
810 ldns_edns_option_code code = ldns_read_uint16(&wire[pos]);
811 size_t size = ldns_read_uint16(&wire[pos+2]);
812 pos += 4;
813
814 if (pos + size > max) { /* make sure the size fits the data */
816 return NULL;
817 }
818 data = LDNS_XMALLOC(uint8_t, size);
819
820 if (!data) {
822 return NULL;
823 }
824 memcpy(data, &wire[pos], size);
825 pos += size;
826
827 edns = ldns_edns_new(code, size, data);
828
829 if (!edns) {
831 return NULL;
832 }
833 if (!ldns_edns_option_list_push(edns_list, edns)) {
835 return NULL;
836 }
837 }
838 return edns_list;
839
840}
841
844{
845 /* return the list if it already exists */
846 if (packet->_edns_list != NULL)
847 return packet->_edns_list;
848
849 /* if the list doesn't exists, we create it by parsing the
850 * packet->_edns_data
851 */
852 if (!ldns_pkt_edns_data(packet))
853 return NULL;
854
855 return ( packet->_edns_list
857}
858
859
860/* Create/destroy/convert functions
861 */
862ldns_pkt *
864{
865 ldns_pkt *packet;
866 packet = LDNS_MALLOC(ldns_pkt);
867 if (!packet) {
868 return NULL;
869 }
870
871 packet->_header = LDNS_MALLOC(ldns_hdr);
872 if (!packet->_header) {
873 LDNS_FREE(packet);
874 return NULL;
875 }
876
877 packet->_question = ldns_rr_list_new();
878 packet->_answer = ldns_rr_list_new();
879 packet->_authority = ldns_rr_list_new();
880 packet->_additional = ldns_rr_list_new();
881
882 /* default everything to false */
883 ldns_pkt_set_qr(packet, false);
884 ldns_pkt_set_aa(packet, false);
885 ldns_pkt_set_tc(packet, false);
886 ldns_pkt_set_rd(packet, false);
887 ldns_pkt_set_ra(packet, false);
888 ldns_pkt_set_ad(packet, false);
889 ldns_pkt_set_cd(packet, false);
890
892 ldns_pkt_set_rcode(packet, 0);
893 ldns_pkt_set_id(packet, 0);
894 ldns_pkt_set_size(packet, 0);
895 ldns_pkt_set_querytime(packet, 0);
896 memset(&packet->timestamp, 0, sizeof(packet->timestamp));
897 ldns_pkt_set_answerfrom(packet, NULL);
902
905 ldns_pkt_set_edns_version(packet, 0);
906 ldns_pkt_set_edns_z(packet, 0);
907 ldns_pkt_set_edns_data(packet, NULL);
908 packet->_edns_list = NULL;
909 packet->_edns_present = false;
910
911 ldns_pkt_set_tsig(packet, NULL);
912
913 return packet;
914}
915
916void
918{
919 if (packet) {
920 LDNS_FREE(packet->_header);
925 ldns_rr_free(packet->_tsig_rr);
929 LDNS_FREE(packet);
930 }
931}
932
933bool
934ldns_pkt_set_flags(ldns_pkt *packet, uint16_t flags)
935{
936 if (!packet) {
937 return false;
938 }
939 if ((flags & LDNS_QR) == LDNS_QR) {
940 ldns_pkt_set_qr(packet, true);
941 }
942 if ((flags & LDNS_AA) == LDNS_AA) {
943 ldns_pkt_set_aa(packet, true);
944 }
945 if ((flags & LDNS_RD) == LDNS_RD) {
946 ldns_pkt_set_rd(packet, true);
947 }
948 if ((flags & LDNS_TC) == LDNS_TC) {
949 ldns_pkt_set_tc(packet, true);
950 }
951 if ((flags & LDNS_CD) == LDNS_CD) {
952 ldns_pkt_set_cd(packet, true);
953 }
954 if ((flags & LDNS_RA) == LDNS_RA) {
955 ldns_pkt_set_ra(packet, true);
956 }
957 if ((flags & LDNS_AD) == LDNS_AD) {
958 ldns_pkt_set_ad(packet, true);
959 }
960 return true;
961}
962
963
964static ldns_rr*
965ldns_pkt_authsoa(const ldns_rdf* rr_name, ldns_rr_class rr_class)
966{
967 ldns_rr* soa_rr = ldns_rr_new();
968 ldns_rdf *owner_rdf;
969 ldns_rdf *mname_rdf;
970 ldns_rdf *rname_rdf;
971 ldns_rdf *serial_rdf;
972 ldns_rdf *refresh_rdf;
973 ldns_rdf *retry_rdf;
974 ldns_rdf *expire_rdf;
975 ldns_rdf *minimum_rdf;
976
977 if (!soa_rr) {
978 return NULL;
979 }
980 owner_rdf = ldns_rdf_clone(rr_name);
981 if (!owner_rdf) {
982 ldns_rr_free(soa_rr);
983 return NULL;
984 }
985
986 ldns_rr_set_owner(soa_rr, owner_rdf);
988 ldns_rr_set_class(soa_rr, rr_class);
989 ldns_rr_set_question(soa_rr, false);
990
991 if (ldns_str2rdf_dname(&mname_rdf, ".") != LDNS_STATUS_OK) {
992 ldns_rr_free(soa_rr);
993 return NULL;
994 } else {
995 ldns_rr_push_rdf(soa_rr, mname_rdf);
996 }
997 if (ldns_str2rdf_dname(&rname_rdf, ".") != LDNS_STATUS_OK) {
998 ldns_rr_free(soa_rr);
999 return NULL;
1000 } else {
1001 ldns_rr_push_rdf(soa_rr, rname_rdf);
1002 }
1004 if (!serial_rdf) {
1005 ldns_rr_free(soa_rr);
1006 return NULL;
1007 } else {
1008 ldns_rr_push_rdf(soa_rr, serial_rdf);
1009 }
1011 if (!refresh_rdf) {
1012 ldns_rr_free(soa_rr);
1013 return NULL;
1014 } else {
1015 ldns_rr_push_rdf(soa_rr, refresh_rdf);
1016 }
1018 if (!retry_rdf) {
1019 ldns_rr_free(soa_rr);
1020 return NULL;
1021 } else {
1022 ldns_rr_push_rdf(soa_rr, retry_rdf);
1023 }
1025 if (!expire_rdf) {
1026 ldns_rr_free(soa_rr);
1027 return NULL;
1028 } else {
1029 ldns_rr_push_rdf(soa_rr, expire_rdf);
1030 }
1032 if (!minimum_rdf) {
1033 ldns_rr_free(soa_rr);
1034 return NULL;
1035 } else {
1036 ldns_rr_push_rdf(soa_rr, minimum_rdf);
1037 }
1038 return soa_rr;
1039}
1040
1041
1042static ldns_status
1043ldns_pkt_query_new_frm_str_internal(ldns_pkt **p, const char *name,
1044 ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags,
1045 ldns_rr* authsoa_rr)
1046{
1047 ldns_pkt *packet;
1048 ldns_rr *question_rr;
1049 ldns_rdf *name_rdf;
1050
1051 packet = ldns_pkt_new();
1052 if (!packet) {
1053 return LDNS_STATUS_MEM_ERR;
1054 }
1055
1056 if (!ldns_pkt_set_flags(packet, flags)) {
1057 ldns_pkt_free(packet);
1058 return LDNS_STATUS_ERR;
1059 }
1060
1061 question_rr = ldns_rr_new();
1062 if (!question_rr) {
1063 ldns_pkt_free(packet);
1064 return LDNS_STATUS_MEM_ERR;
1065 }
1066
1067 if (rr_type == 0) {
1068 rr_type = LDNS_RR_TYPE_A;
1069 }
1070 if (rr_class == 0) {
1071 rr_class = LDNS_RR_CLASS_IN;
1072 }
1073
1074 if (ldns_str2rdf_dname(&name_rdf, name) == LDNS_STATUS_OK) {
1075 ldns_rr_set_owner(question_rr, name_rdf);
1076 ldns_rr_set_type(question_rr, rr_type);
1077 ldns_rr_set_class(question_rr, rr_class);
1078 ldns_rr_set_question(question_rr, true);
1079
1080 ldns_pkt_push_rr(packet, LDNS_SECTION_QUESTION, question_rr);
1081 } else {
1082 ldns_rr_free(question_rr);
1083 ldns_pkt_free(packet);
1084 return LDNS_STATUS_ERR;
1085 }
1086
1087 if (authsoa_rr) {
1088 ldns_pkt_push_rr(packet, LDNS_SECTION_AUTHORITY, authsoa_rr);
1089 }
1090
1091 packet->_tsig_rr = NULL;
1092 ldns_pkt_set_answerfrom(packet, NULL);
1093 if (p) {
1094 *p = packet;
1095 return LDNS_STATUS_OK;
1096 } else {
1097 ldns_pkt_free(packet);
1098 return LDNS_STATUS_NULL;
1099 }
1100}
1101
1104 ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
1105{
1106 return ldns_pkt_query_new_frm_str_internal(p, name, rr_type,
1107 rr_class, flags, NULL);
1108}
1109
1112 ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
1113{
1114 ldns_rr* authsoa_rr = soa;
1115 if (!authsoa_rr) {
1116 ldns_rdf *name_rdf;
1117 if (ldns_str2rdf_dname(&name_rdf, name) == LDNS_STATUS_OK) {
1118 authsoa_rr = ldns_pkt_authsoa(name_rdf, rr_class);
1119 }
1120 ldns_rdf_free(name_rdf);
1121 }
1122 return ldns_pkt_query_new_frm_str_internal(p, name, LDNS_RR_TYPE_IXFR,
1123 rr_class, flags, authsoa_rr);
1124}
1125
1126static ldns_pkt *
1127ldns_pkt_query_new_internal(ldns_rdf *rr_name, ldns_rr_type rr_type,
1128 ldns_rr_class rr_class, uint16_t flags, ldns_rr* authsoa_rr)
1129{
1130 ldns_pkt *packet;
1131 ldns_rr *question_rr;
1132
1133 packet = ldns_pkt_new();
1134 if (!packet) {
1135 return NULL;
1136 }
1137
1138 if (!ldns_pkt_set_flags(packet, flags)) {
1139 return NULL;
1140 }
1141
1142 question_rr = ldns_rr_new();
1143 if (!question_rr) {
1144 ldns_pkt_free(packet);
1145 return NULL;
1146 }
1147
1148 if (rr_type == 0) {
1149 rr_type = LDNS_RR_TYPE_A;
1150 }
1151 if (rr_class == 0) {
1152 rr_class = LDNS_RR_CLASS_IN;
1153 }
1154
1155 ldns_rr_set_owner(question_rr, rr_name);
1156 ldns_rr_set_type(question_rr, rr_type);
1157 ldns_rr_set_class(question_rr, rr_class);
1158 ldns_rr_set_question(question_rr, true);
1159 ldns_pkt_push_rr(packet, LDNS_SECTION_QUESTION, question_rr);
1160
1161 if (authsoa_rr) {
1162 ldns_pkt_push_rr(packet, LDNS_SECTION_AUTHORITY, authsoa_rr);
1163 }
1164
1165 packet->_tsig_rr = NULL;
1166 return packet;
1167}
1168
1169ldns_pkt *
1171 ldns_rr_class rr_class, uint16_t flags)
1172{
1173 return ldns_pkt_query_new_internal(rr_name, rr_type,
1174 rr_class, flags, NULL);
1175}
1176
1177ldns_pkt *
1179 uint16_t flags, ldns_rr* soa)
1180{
1181 ldns_rr* authsoa_rr = soa;
1182 if (!authsoa_rr) {
1183 authsoa_rr = ldns_pkt_authsoa(rr_name, rr_class);
1184 }
1185 return ldns_pkt_query_new_internal(rr_name, LDNS_RR_TYPE_IXFR,
1186 rr_class, flags, authsoa_rr);
1187}
1188
1191{
1192 ldns_rr_list *tmp;
1193
1194 if (!p) {
1195 return LDNS_PACKET_UNKNOWN;
1196 }
1197
1199 return LDNS_PACKET_NXDOMAIN;
1200 }
1201
1202 if (ldns_pkt_ancount(p) == 0 && ldns_pkt_arcount(p) == 0
1203 && ldns_pkt_nscount(p) == 1) {
1204
1205 /* check for SOA */
1208 if (tmp) {
1210 return LDNS_PACKET_NODATA;
1211 } else {
1212 /* I have no idea ... */
1213 }
1214 }
1215
1216 if (ldns_pkt_ancount(p) == 0 && ldns_pkt_nscount(p) > 0) {
1219 if (tmp) {
1220 /* there are nameservers here */
1222 return LDNS_PACKET_REFERRAL;
1223 } else {
1224 /* I have no idea */
1225 }
1227 }
1228
1229 /* if we cannot determine the packet type, we say it's an
1230 * answer...
1231 */
1232 return LDNS_PACKET_ANSWER;
1233}
1234
1235ldns_pkt *
1237{
1238 ldns_pkt *new_pkt;
1239
1240 if (!pkt) {
1241 return NULL;
1242 }
1243 new_pkt = ldns_pkt_new();
1244
1245 ldns_pkt_set_id(new_pkt, ldns_pkt_id(pkt));
1246 ldns_pkt_set_qr(new_pkt, ldns_pkt_qr(pkt));
1247 ldns_pkt_set_aa(new_pkt, ldns_pkt_aa(pkt));
1248 ldns_pkt_set_tc(new_pkt, ldns_pkt_tc(pkt));
1249 ldns_pkt_set_rd(new_pkt, ldns_pkt_rd(pkt));
1250 ldns_pkt_set_cd(new_pkt, ldns_pkt_cd(pkt));
1251 ldns_pkt_set_ra(new_pkt, ldns_pkt_ra(pkt));
1252 ldns_pkt_set_ad(new_pkt, ldns_pkt_ad(pkt));
1259 if (ldns_pkt_answerfrom(pkt))
1264 ldns_pkt_set_size(new_pkt, ldns_pkt_size(pkt));
1266
1271 new_pkt->_edns_present = pkt->_edns_present;
1272 ldns_pkt_set_edns_z(new_pkt, ldns_pkt_edns_z(pkt));
1273 if(ldns_pkt_edns_data(pkt))
1274 ldns_pkt_set_edns_data(new_pkt,
1278 if (pkt->_edns_list)
1281
1290 return new_pkt;
1291}
int ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2)
Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6.
Definition dname.c:359
enum ldns_enum_edns_option ldns_edns_option_code
Definition edns.h:46
ldns_edns_option * ldns_edns_new(ldns_edns_option_code code, size_t size, void *data)
allocates a new EDNS structure and fills it.
Definition edns.c:139
ldns_edns_option_list * ldns_edns_option_list_new(void)
allocates space for a new list of EDNS options
Definition edns.c:209
signed char ldns_edns_option_list_push(ldns_edns_option_list *options_list, ldns_edns_option *option)
adds an EDNS option at the end of the list of options.
Definition edns.c:338
ldns_edns_option_list * ldns_edns_option_list_clone(ldns_edns_option_list *options_list)
clone the EDNS options list and it's contents
Definition edns.c:224
void ldns_edns_option_list_deep_free(ldns_edns_option_list *options_list)
Definition edns.c:264
@ LDNS_STATUS_NULL
Definition error.h:51
@ LDNS_STATUS_ERR
Definition error.h:37
@ LDNS_STATUS_MEM_ERR
Definition error.h:34
@ LDNS_STATUS_OK
Definition error.h:26
enum ldns_enum_status ldns_status
Definition error.h:149
Including this file will include all ldns files, and define some lookup tables.
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
Definition packet.c:917
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet's edns version
Definition packet.c:222
void ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
Set the packet's an count.
Definition packet.c:588
ldns_edns_option_list * pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
Definition packet.c:784
void ldns_pkt_set_rd(ldns_pkt *packet, signed char rd)
Set the packet's rd bit.
Definition packet.c:522
void ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time)
Set the packet's query time.
Definition packet.c:606
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
Set the packet's tsig rr.
Definition packet.c:691
signed char ldns_pkt_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
push a rr_list on a packet
Definition packet.c:745
void ldns_pkt_set_tc(ldns_pkt *packet, signed char tc)
Set the packet's tc bit.
Definition packet.c:516
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *packet)
Read the packet's code.
Definition packet.c:91
ldns_pkt * ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, type and class.
Definition packet.c:1178
signed char ldns_pkt_edns(const ldns_pkt *pkt)
returns true if this packet needs and EDNS rr to be sent.
Definition packet.c:769
signed char ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr)
push an rr on a packet, provided the RR is not there.
Definition packet.c:733
signed char ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr)
check to see if an rr exist in the packet
Definition packet.c:396
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
Definition packet.c:631
void ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
Set the packet's opcode.
Definition packet.c:570
void ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rr)
directly set the additional section
Definition packet.c:528
void ldns_pkt_set_aa(ldns_pkt *packet, signed char aa)
Set the packet's aa bit.
Definition packet.c:510
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
Definition packet.c:127
void ldns_pkt_set_random_id(ldns_pkt *packet)
Set the packet's id to a random value.
Definition packet.c:496
void ldns_pkt_set_edns_option_list(ldns_pkt *packet, ldns_edns_option_list *list)
Set the packet's structured EDNS data.
Definition packet.c:661
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *packet)
Return the packet's answerfrom.
Definition packet.c:198
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
Definition packet.c:43
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
Definition packet.c:121
signed char ldns_pkt_edns_co(const ldns_pkt *packet)
return the packet's edns co bit
Definition packet.c:250
#define LDNS_EDNS_MASK_UNASSIGNED
Definition packet.c:30
struct timeval ldns_pkt_timestamp(const ldns_pkt *packet)
Return the packet's timestamp.
Definition packet.c:204
void ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
Set the packet's ns count.
Definition packet.c:594
ldns_rr_list * ldns_pkt_all_noquestion(const ldns_pkt *packet)
Return the packet's answer, authority and additional sections concatenated, in a new rr_list clone.
Definition packet.c:171
void ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rr)
directly set the authority section
Definition packet.c:546
void ldns_pkt_set_ra(ldns_pkt *packet, signed char ra)
Set the packet's ra bit.
Definition packet.c:558
ldns_pkt * ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a packet with a query in it for the given name, type and class.
Definition packet.c:1170
void ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
Set the packet's timestamp.
Definition packet.c:618
ldns_rr * ldns_pkt_tsig(const ldns_pkt *pkt)
Return the packet's tsig pseudo rr's.
Definition packet.c:484
void ldns_pkt_set_cd(ldns_pkt *packet, signed char cd)
Set the packet's cd bit.
Definition packet.c:552
void ldns_pkt_set_size(ldns_pkt *packet, size_t s)
Set the packet's size.
Definition packet.c:625
signed char ldns_pkt_aa(const ldns_pkt *packet)
Read the packet's aa bit.
Definition packet.c:55
ldns_rr_list * ldns_pkt_rr_list_by_type(const ldns_pkt *packet, ldns_rr_type type, ldns_pkt_section sec)
return all the rr with a specific type from a packet.
Definition packet.c:323
signed char ldns_pkt_empty(ldns_pkt *p)
check if a packet is empty
Definition packet.c:449
ldns_edns_option_list * ldns_pkt_edns_get_option_list(ldns_pkt *packet)
Returns a list of structured EDNS options.
Definition packet.c:843
#define LDNS_EDNS_MASK_DO_BIT
Definition packet.c:28
signed char ldns_pkt_set_flags(ldns_pkt *packet, uint16_t flags)
sets the flags in a packet.
Definition packet.c:934
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
Definition packet.c:133
void ldns_pkt_set_edns_co(ldns_pkt *packet, signed char value)
Set the packet's edns co bit.
Definition packet.c:256
uint16_t ldns_pkt_edns_unassigned(const ldns_pkt *packet)
return the packet's EDNS header bits that are unassigned.
Definition packet.c:266
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
Definition packet.c:109
signed char ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr)
push an rr on a packet
Definition packet.c:697
void ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rr)
directly set the answer section
Definition packet.c:540
#define LDNS_EDNS_MASK_CO_BIT
Definition packet.c:29
void ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rr)
directly set the question section
Definition packet.c:534
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
Definition packet.c:863
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
Definition packet.c:145
void ldns_pkt_set_edns_do(ldns_pkt *packet, signed char value)
Set the packet's edns do bit.
Definition packet.c:240
void ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
Set the packet's qd count.
Definition packet.c:582
signed char ldns_pkt_cd(const ldns_pkt *packet)
Read the packet's cd bit.
Definition packet.c:73
size_t ldns_pkt_size(const ldns_pkt *packet)
Return the packet's size in bytes.
Definition packet.c:186
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet's edns z value.
Definition packet.c:649
ldns_rr_list * ldns_pkt_rr_list_by_name(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_pkt_section sec)
return all the rr with a specific name from a packet.
Definition packet.c:286
signed char ldns_pkt_qr(const ldns_pkt *packet)
Read the packet's qr bit.
Definition packet.c:49
uint32_t ldns_pkt_querytime(const ldns_pkt *packet)
Return the packet's querytime.
Definition packet.c:192
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's EDNS data
Definition packet.c:279
void ldns_pkt_set_ad(ldns_pkt *packet, signed char ad)
Set the packet's ad bit.
Definition packet.c:564
ldns_rr_list * ldns_pkt_all(const ldns_pkt *packet)
Return the packet's question, answer, authority and additional sections concatenated,...
Definition packet.c:152
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet's edns extended rcode
Definition packet.c:216
uint16_t ldns_pkt_section_count(const ldns_pkt *packet, ldns_pkt_section s)
Return the number of RRs in the given section.
Definition packet.c:423
void ldns_pkt_set_qr(ldns_pkt *packet, signed char qr)
Set the packet's qr bit.
Definition packet.c:504
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet's EDNS data.
Definition packet.c:655
ldns_pkt * ldns_pkt_clone(const ldns_pkt *pkt)
clones the given packet, creating a fully allocated copy
Definition packet.c:1236
ldns_pkt_type ldns_pkt_reply_type(const ldns_pkt *p)
looks inside the packet to determine what kind of packet it is, AUTH, NXDOMAIN, REFERRAL,...
Definition packet.c:1190
signed char ldns_pkt_tc(const ldns_pkt *packet)
Read the packet's tc bit.
Definition packet.c:61
signed char ldns_pkt_rd(const ldns_pkt *packet)
Read the packet's rd bit.
Definition packet.c:67
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
Definition packet.c:115
signed char ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet's edns do bit
Definition packet.c:234
signed char ldns_pkt_safe_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
push an rr_list to a packet, provided the RRs are not already there.
Definition packet.c:757
ldns_rr_list * ldns_pkt_get_section_clone(const ldns_pkt *packet, ldns_pkt_section s)
return all the rr_list's in the packet.
Definition packet.c:463
signed char ldns_pkt_ra(const ldns_pkt *packet)
Read the packet's ra bit.
Definition packet.c:79
void ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
Set the packet's id.
Definition packet.c:490
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
Definition packet.c:103
signed char ldns_pkt_ad(const ldns_pkt *packet)
Read the packet's ad bit.
Definition packet.c:85
ldns_lookup_table ldns_edns_flags[]
EDNS flags.
Definition packet.c:36
void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
Set the packet's edns extended rcode.
Definition packet.c:637
ldns_status ldns_pkt_ixfr_request_new_frm_str(ldns_pkt **p, const char *name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, class.
Definition packet.c:1111
void ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *answerfrom)
Set the packet's answering server.
Definition packet.c:612
void ldns_pkt_set_section_count(ldns_pkt *packet, ldns_pkt_section s, uint16_t count)
Set a packet's section count to x.
Definition packet.c:670
ldns_status ldns_pkt_query_new_frm_str(ldns_pkt **p, const char *name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a query packet for the given name, type, class.
Definition packet.c:1103
uint16_t ldns_pkt_edns_z(const ldns_pkt *packet)
return the packet's edns z value
Definition packet.c:228
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)
return all the rr with a specific type and type from a packet.
Definition packet.c:359
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
Definition packet.c:139
void ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
Set the packet's arcount.
Definition packet.c:600
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's response code.
Definition packet.c:97
void ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
Set the packet's response code.
Definition packet.c:576
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
Definition packet.c:210
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet's edns version.
Definition packet.c:643
void ldns_pkt_set_edns_unassigned(ldns_pkt *packet, uint16_t value)
Set the packet's EDNS header bits that are unassigned.
Definition packet.c:272
enum ldns_enum_pkt_type ldns_pkt_type
Definition packet.h:300
#define LDNS_RA
Definition packet.h:32
#define LDNS_QR
Definition packet.h:27
#define LDNS_CD
Definition packet.h:31
#define LDNS_TC
Definition packet.h:29
enum ldns_enum_pkt_rcode ldns_pkt_rcode
Definition packet.h:69
@ LDNS_PACKET_QUERY
Definition packet.h:47
enum ldns_enum_pkt_opcode ldns_pkt_opcode
Definition packet.h:53
enum ldns_enum_pkt_section ldns_pkt_section
Definition packet.h:287
#define LDNS_AA
Definition packet.h:28
@ LDNS_SECTION_ANY
bogus section, if not interested
Definition packet.h:283
@ LDNS_SECTION_QUESTION
Definition packet.h:278
@ LDNS_SECTION_ANSWER
Definition packet.h:279
@ LDNS_SECTION_ADDITIONAL
Definition packet.h:281
@ LDNS_SECTION_AUTHORITY
Definition packet.h:280
@ LDNS_SECTION_ANY_NOQUESTION
used to get all non-question rrs from a packet
Definition packet.h:285
#define LDNS_RD
Definition packet.h:30
@ LDNS_RCODE_NXDOMAIN
Definition packet.h:60
#define LDNS_AD
Definition packet.h:33
@ LDNS_PACKET_REFERRAL
Definition packet.h:294
@ LDNS_PACKET_UNKNOWN
Definition packet.h:298
@ LDNS_PACKET_NODATA
Definition packet.h:297
@ LDNS_PACKET_NXDOMAIN
Definition packet.h:296
@ LDNS_PACKET_ANSWER
Definition packet.h:295
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
Definition rdata.c:38
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
Definition rdata.c:222
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition rdata.c:230
@ LDNS_RDF_TYPE_INT32
32 bits
Definition rdata.h:56
ldns_rdf * ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value)
returns an rdf that contains the given int32 value.
Definition rdata.c:147
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
Definition rdata.c:24
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
Definition rdata.c:241
void ldns_rr_list_free(ldns_rr_list *rr_list)
frees an rr_list structure.
Definition rr.c:1009
void ldns_rr_list_deep_free(ldns_rr_list *rr_list)
frees an rr_list structure and all rrs contained therein.
Definition rr.c:1018
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
Definition rr.c:81
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
Definition rr.c:802
ldns_rr_list * ldns_rr_list_new(void)
creates a new rr_list structure.
Definition rr.c:998
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
Definition rr.c:30
signed char ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr)
returns true if the given rr is one of the rrs in the list, or if it is equal to one
Definition rr.c:1238
enum ldns_enum_rr_type ldns_rr_type
Definition rr.h:260
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
Definition rr.c:826
@ LDNS_RR_TYPE_A
a host address
Definition rr.h:80
@ LDNS_RR_TYPE_IXFR
Definition rr.h:220
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
Definition rr.h:90
@ LDNS_RR_TYPE_NS
an authoritative name server
Definition rr.h:82
ldns_rr_list * ldns_rr_list_cat_clone(const ldns_rr_list *left, const ldns_rr_list *right)
concatenates two ldns_rr_lists together, but makes clones of the rr's (instead of pointer copying).
Definition rr.c:1057
signed char ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
Definition rr.c:1130
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
Definition rr.c:955
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition rr.c:941
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
Definition rr.c:1438
void ldns_rr_set_question(ldns_rr *rr, signed char question)
sets the question flag in the rr structure.
Definition rr.c:808
enum ldns_enum_rr_class ldns_rr_class
Definition rr.h:61
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
Definition rr.c:988
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
Definition rr.c:832
signed char ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
Definition rr.c:855
ldns_rr_list * ldns_rr_list_clone(const ldns_rr_list *rrlist)
clones an rrlist.
Definition rr.c:1469
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
Definition rr.c:917
@ LDNS_RR_CLASS_IN
the Internet
Definition rr.h:47
ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str)
convert a dname string into wireformat
Definition str2host.c:374
The struct that stores an ordered EDNS option.
Definition edns.h:101
signed char _rd
Recursion desired.
Definition packet.h:204
uint16_t _id
Id of a packet.
Definition packet.h:196
ldns_pkt_opcode _opcode
Query type.
Definition packet.h:212
signed char _cd
Checking disabled.
Definition packet.h:206
signed char _ra
Recursion available.
Definition packet.h:208
uint16_t _ancount
answer sec
Definition packet.h:218
signed char _qr
Query bit (0=query, 1=answer)
Definition packet.h:198
signed char _tc
Packet truncated.
Definition packet.h:202
signed char _ad
Authentic data.
Definition packet.h:210
uint16_t _qdcount
question sec
Definition packet.h:216
uint16_t _arcount
add sec
Definition packet.h:222
uint8_t _rcode
Response code.
Definition packet.h:214
uint16_t _nscount
auth sec
Definition packet.h:220
signed char _aa
Authoritative answer.
Definition packet.h:200
A general purpose lookup table.
Definition util.h:178
DNS packet.
Definition packet.h:235
struct timeval timestamp
Timestamp of the time the packet was sent or created.
Definition packet.h:242
uint8_t _edns_extended_rcode
EDNS0 Extended rcode.
Definition packet.h:252
ldns_rr_list * _authority
Authority section.
Definition packet.h:268
ldns_hdr * _header
Header section.
Definition packet.h:237
uint32_t _querytime
The duration of the query this packet is an answer to.
Definition packet.h:244
uint16_t _edns_udp_size
EDNS0 available buffer size, see RFC2671.
Definition packet.h:250
ldns_rdf * _answerfrom
an rdf (A or AAAA) with the IP address of the server it is from
Definition packet.h:240
uint8_t _edns_present
Definition packet.h:256
uint8_t _edns_version
EDNS Version.
Definition packet.h:254
size_t _size
The size of the wire format of the packet in octets.
Definition packet.h:246
ldns_rr_list * _answer
Answer section.
Definition packet.h:266
ldns_rdf * _edns_data
Arbitrary EDNS rdata.
Definition packet.h:260
ldns_edns_option_list * _edns_list
Structed EDNS data.
Definition packet.h:262
uint16_t _edns_z
Reserved EDNS data bits.
Definition packet.h:258
ldns_rr_list * _additional
Additional section.
Definition packet.h:270
ldns_rr * _tsig_rr
Optional tsig rr.
Definition packet.h:248
ldns_rr_list * _question
Question section.
Definition packet.h:264
Resource record data field.
Definition rdata.h:203
List or Set of Resource Records.
Definition rr.h:355
Resource Record.
Definition rr.h:327
#define LDNS_FREE(ptr)
Definition util.h:60
#define LDNS_MALLOC(type)
Memory management macros.
Definition util.h:49
#define LDNS_XMALLOC(type, count)
Definition util.h:51
uint16_t ldns_get_random(void)
Get random number.
Definition util.c:417