1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
** Copyright 1998 - 1999 Double Precision, Inc.
** See COPYING for distribution information.
*/
#include "rfc1035.h"
#include <string.h>
static struct { const char *name; int num; } typetab[]={
{"A", 1},
{"NS", 2},
{"MD", 3},
{"MF", 4},
{"CNAME", 5},
{"SOA", 6},
{"MB", 7},
{"MG", 8},
{"MR", 9},
{"NULL", 10},
{"WKS", 11},
{"PTR", 12},
{"HINFO", 13},
{"MINFO", 14},
{"MX", 15},
{"TXT", 16},
{"AAAA", 28},
{"RRSIG", 46},
{"AXFR", 252},
{"MAILB", 253},
{"MAILA", 254},
{"ANY", 255}},
classtab[]={
{"IN", 1},
{"CSNET", 2},
{"CHAOS", 3},
{"HESIOD", 4},
{"ANY", 255}},
opcodetab[]={
{"QUERY", 0},
{"IQUERY", 1},
{"STATUS", 2}},
rcodetab[]={
{"NOERROR", 0},
{"FORMAT", 1},
{"SERVFAIL", 2},
{"NXDOMAIN", 3},
{"UNIMPLEMENTED", 4},
{"REFUSED", 5}};
#if HAVE_STRCASECMP
#define COMPARE(a,b) strcasecmp((a), (b))
#else
#define COMPARE(a,b) stricmp((a), (b))
#endif
void rfc1035_type_itostr(int n, void (*func)(const char *, void *), void *arg)
{
unsigned i;
char buf[30];
for (i=0; i<sizeof(typetab)/sizeof(typetab[0]); i++)
if (typetab[i].num == n)
{
(*func)(typetab[i].name, arg);
return;
}
snprintf(buf, sizeof(buf), "TYPE%d", n);
buf[sizeof(buf)-1]=0;
(*func)(buf, arg);
}
int rfc1035_type_strtoi(const char *n)
{
unsigned i;
for (i=0; i<sizeof(typetab)/sizeof(typetab[0]); i++)
if (COMPARE(typetab[i].name, n) == 0) return (typetab[i].num);
return (-1);
}
const char *rfc1035_class_itostr(int n)
{
unsigned i;
for (i=0; i<sizeof(classtab)/sizeof(classtab[0]); i++)
if (classtab[i].num == n) return (classtab[i].name);
return ("unknown");
}
int rfc1035_class_strtoi(const char *n)
{
unsigned i;
for (i=0; i<sizeof(classtab)/sizeof(classtab[0]); i++)
if (COMPARE(classtab[i].name, n) == 0) return (classtab[i].num);
return (-1);
}
const char *rfc1035_opcode_itostr(int n)
{
unsigned i;
for (i=0; i<sizeof(opcodetab)/sizeof(opcodetab[0]); i++)
if (opcodetab[i].num == n) return (opcodetab[i].name);
return ("unknown");
}
int rfc1035_opcode_strtoi(const char *n)
{
unsigned i;
for (i=0; i<sizeof(opcodetab)/sizeof(opcodetab[0]); i++)
if (COMPARE(opcodetab[i].name, n) == 0)
return (opcodetab[i].num);
return (-1);
}
const char *rfc1035_rcode_itostr(int n)
{
unsigned i;
for (i=0; i<sizeof(rcodetab)/sizeof(rcodetab[0]); i++)
if (rcodetab[i].num == n) return (rcodetab[i].name);
return ("unknown");
}
int rfc1035_rcode_strtoi(const char *n)
{
unsigned i;
for (i=0; i<sizeof(rcodetab)/sizeof(rcodetab[0]); i++)
if (COMPARE(rcodetab[i].name, n) == 0)
return (rcodetab[i].num);
return (-1);
}
|