-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.c
81 lines (73 loc) · 2.61 KB
/
error.c
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
/*
* Copyright (c) Regents of The University of Michigan
* See COPYING.
*/
#include <inttypes.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <sys/time.h>
#include "denser.h"
#include "internal.h"
struct dnsr_error {
int e_errno;
char *e_string;
};
static struct dnsr_error dnsr_error_txt[ DNSR_MAX_ERRNO + 2 ] = {
{DNSR_ERROR_NONE, "no error"}, {DNSR_ERROR_FORMAT, "format error"},
{DNSR_ERROR_SERVER, "server failure"},
{DNSR_ERROR_NAME, "domain name does not exist"},
{DNSR_ERROR_NOT_IMPLEMENTED, "query not supported"},
{DNSR_ERROR_REFUSED, "refused"}, {6, "reserved"}, {7, "reserved"},
{DNSR_ERROR_CONFIG, "config file"},
{DNSR_ERROR_NO_QUERY, "no query sent"}, {DNSR_ERROR_TIMEOUT, "timeout"},
{DNSR_ERROR_ID_WRONG, "wrong response ID"},
{DNSR_ERROR_NOT_RESPONSE, "no response"},
{DNSR_ERROR_NO_RECURSION, "recursion not available"},
{DNSR_ERROR_QUESTION_WRONG, "invalid question in result"},
{DNSR_ERROR_NO_ANSWER, "no answer"},
{DNSR_ERROR_TRUNCATION, "message truncated"},
{DNSR_ERROR_SYSTEM, "system error"},
{DNSR_ERROR_SIZELIMIT_EXCEEDED, "sizelimit exceeded"},
{DNSR_ERROR_NS_INVALID, "invalid name server"},
{DNSR_ERROR_NS_DEAD, "name server down"},
{DNSR_ERROR_TV, "invalid time value"},
{DNSR_ERROR_FD_SET, "wrong FD set"}, {DNSR_ERROR_PARSE, "parse failed"},
{DNSR_ERROR_STATE, "unknown state"}, {DNSR_ERROR_TYPE, "unknown type"},
{DNSR_ERROR_RCODE, "unknown rcode"},
{DNSR_ERROR_TOGGLE, "unknown toggle"},
{DNSR_ERROR_FLAG, "unknown flag"}, {DNSR_ERROR_CLASS, "unknown class"},
{DNSR_ERROR_Z, "Z code not zero"},
{DNSR_ERROR_CONNECTION_CLOSED, "connection closes"},
{DNSR_ERROR_UNKNOWN, "unknown"}};
int
dnsr_errno(DNSR *dnsr) {
return (dnsr->d_errno);
}
void
dnsr_errclear(DNSR *dnsr) {
dnsr->d_errno = DNSR_ERROR_NONE;
return;
}
char *
dnsr_err2string(int dnsr_errno) {
/* check if < 0 or > max, and then just return as offest */
if (dnsr_errno < 0 || dnsr_errno > DNSR_MAX_ERRNO) {
return (dnsr_error_txt[ DNSR_ERROR_UNKNOWN ].e_string);
} else {
return (dnsr_error_txt[ dnsr_errno ].e_string);
}
}
void
dnsr_perror(DNSR *dnsr, const char *s) {
if (dnsr != NULL) {
if (dnsr->d_errno == DNSR_ERROR_SYSTEM) {
perror(s);
} else {
fprintf(stderr, "%s: %s\n", s, dnsr_err2string(dnsr->d_errno));
}
} else {
fprintf(stderr, "%s: dnsr_perror: dnsr is NULL\n", s);
}
}