1 #include <stdlib.h>
2 #include "dnsrelated.h"
3 
4 /* http://en.wikipedia.org/wiki/List_of_DNS_record_types */
5 const DNSTypeAndName DNSTypeList[] = {
6 	{1,		"IPv4 Address"},
7 	{5,		"Canonical Name"},
8 	{28,	"IPv6 Address"},
9 	{6,		"start of authority"},
10 	{12,	"Domain pointer"},
11 	{2,		"Name Server"},
12 	{15,	"MX"},
13 	{16,	"TXT"},
14 	{41,	"OPT"},
15 	{255,	"*"},
16 
17 	{18,	"AFSDB"},
18 	{42,	"APL"},
19 	{37,	"CERT"},
20 	{49,	"DHCID"},
21 	{32769,	"DLV"},
22 	{39,	"DNAME"},
23 	{48,	"DNSKEY"},
24 	{43,	"DS"},
25 	{55,	"HIP"},
26 	{45,	"IPSECKEY"},
27 	{25,	"KEY"},
28 	{36,	"KX"},
29 	{29,	"LOC"},
30 	{35,	"NAPTR"},
31 	{47,	"NSEC"},
32 	{50,	"NSEC3"},
33 	{51,	"NSEC3PARAM"},
34 	{46,	"RRSIG"},
35 	{17,	"RP"},
36 	{24,	"SIG"},
37 	{99,	"SPF"},
38 	{33,	"SRV"},
39 	{44,	"SSHFP"},
40 	{32768,	"TA"},
41 	{249,	"TKEY"},
42 	{250,	"TSIG"},
43 	{252,	"AXFR"},
44 	{251,	"IXFR"},
45 	{13,	"Host Information"},
46 	{0,		NULL}
47 };
48 
49 /* http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
50 const DNSSECAlgorithm DNSSECAlgorithmList[] = {
51 	{0,		"(reserved)"},
52 	{1,		"RSA/MD5"},
53 	{2,		"Diffie-Hellman"},
54 	{3,		"DSA/SHA-1"},
55 	{4,		"Elliptic Curve"},
56 	{5,		"RSA/SHA-1"},
57 	{6,		"DSA-NSEC3-SHA1"},
58 	{7,		"RSASHA1-NSEC3-SHA1"},
59 	{8,		"RSA/SHA-256"},
60 	{9,		"(reserved)"},
61 	{10,	"RSA/SHA-512"},
62 	{11,	"(reserved)"},
63 	{12,	"GOST R 34.10-2001"},
64 	{13,	"ECDSA Curve P-256 with SHA-256"},
65 	{14,	"ECDSA Curve P-384 with SHA-384"},
66 
67 	{252,	"Indirect"},
68 	{253,	"Private"},
69 	{254,	"Private"},
70 	{255,	"(reserved)"}
71 };
72 
DNSGetTypeName(uint16_t Num)73 const char *DNSGetTypeName(uint16_t Num)
74 {
75 	int loop;
76 
77 	for(loop = 0; loop != sizeof(DNSTypeList) / sizeof(DNSTypeAndName); ++loop)
78 	{
79 		if( DNSTypeList[loop].Num == Num )
80 		{
81 			return DNSTypeList[loop].Name;
82 		}
83 	}
84 
85 	return "UNKNOWN";
86 }
87 
DNSSECAlgorithm_Compare(DNSSECAlgorithm * Key,DNSSECAlgorithm * Element)88 static int DNSSECAlgorithm_Compare(DNSSECAlgorithm *Key, DNSSECAlgorithm *Element)
89 {
90 	return Key->Num - Element->Num;
91 }
92 
DNSSECGetAlgorithmName(int Num)93 const char *DNSSECGetAlgorithmName(int Num)
94 {
95 	DNSSECAlgorithm Key = {Num, NULL};
96 
97 	DNSSECAlgorithm *Result = NULL;
98 
99 	Result = bsearch(&Key, DNSSECAlgorithmList, sizeof(DNSSECAlgorithmList) / sizeof(DNSSECAlgorithm), sizeof(DNSSECAlgorithm), (int (*)(const void *, const void *))DNSSECAlgorithm_Compare);
100 
101 	if( Result == NULL )
102 	{
103 		return "UNKNOWN";
104 	} else {
105 		return Result->Name;
106 	}
107 }
108