chiark / gitweb /
f427dcd7f173182db74096f99483a37edac69d57
[adns.git] / src / types.c
1 /**/
2
3 #include "internal.h"
4
5 #define TYRRSZ(rrtype,size,func) { (rrtype), (size), (func) }
6
7 #define TYRRSZ(sizememb) (sizeof(((adns_answer*)0)->rrs.sizememb))
8
9 static const typeinfo typeinfos[] = {
10   /* Must be in ascending order of rrtype ! */
11   
12   {    adns_r_a,               TYRR(inaddr),       rpf_inaddr           },
13   {    adns_r_ns_raw,          TYRR(str),          rpf_domain_raw       },
14   {    adns_r_cname,           TYRR(str),          rpf_domain_raw       },
15   {    adns_r_soa_raw,         TYRR(soa),          rpf_soa              },
16   {    adns_r_null,            0,                  rpf_null             },
17   {    adns_r_ptr_raw,         TYRR(str),          rpf_domain_raw       },
18   {    adns_r_hinfo,           TYRR(strpair),      rpf_hinfo            },
19   {    adns_r_mx_raw,          TYRR(intstr),       rpf_mx_raw           },
20   {    adns_r_txt,             TYRR(str),          rpf_txt              },
21   {    adns_r_rp_raw,          TYRR(strpair),      rpf_rp               },
22
23   {    adns_r_ns,              TYRR(dmaddr),       rpf_dmaddr           },
24   {    adns_r_ptr,             TYRR(str),          rpf_ptr              },
25   {    adns_r_mx,              TYRR(intdmaddr),    rpf_mx               },
26
27   {    adns_r_soa,             TYRR(soa),          rpf_soa              },
28   {    adns_r_rp,              TYRR(strpair),      rpf_rp               },
29 };
30
31 const typeinfo adns__findtype(adns_rrtype type) {
32   const typeinfo *begin, *end;
33
34   begin= typeinfos;  end= typeinfos+(sizeof(typeinfos)/sizeof(typeinfo));
35
36   while (begin < end) {
37     mid= begin + ((end-begin)>>1);
38     if (mid->type == type) return mid;
39     if (type > mid->type) begin= mid+1;
40     else end= mid;
41   }
42   return 0;
43 }