1 /*
2 * Portions Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7 *
8 * See the COPYRIGHT file distributed with this work for additional
9 * information regarding copyright ownership.
10 */
11
12 /*
13 * Copyright (c) 1987, 1993
14 * The Regents of the University of California. All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 */
40
41 /*! \file herror.c
42 lwres_herror() prints the string s on stderr followed by the string
43 generated by lwres_hstrerror() for the error code stored in the global
44 variable lwres_h_errno.
45
46 lwres_hstrerror() returns an appropriate string for the error code
47 gievn by err. The values of the error codes and messages are as
48 follows:
49
50 \li #NETDB_SUCCESS: Resolver Error 0 (no error)
51
52 \li #HOST_NOT_FOUND: Unknown host
53
54 \li #TRY_AGAIN: Host name lookup failure
55
56 \li #NO_RECOVERY: Unknown server error
57
58 \li #NO_DATA: No address associated with name
59
60 */
61
62 #include <config.h>
63
64 #include <stdio.h>
65
66 #include <isc/print.h>
67
68 #include <lwres/netdb.h>
69 #include <lwres/platform.h>
70
71 LIBLWRES_EXTERNAL_DATA int lwres_h_errno;
72
73 /*!
74 * these have never been declared in any header file so make them static
75 */
76
77 static const char *h_errlist[] = {
78 "Resolver Error 0 (no error)", /*%< 0 no error */
79 "Unknown host", /*%< 1 HOST_NOT_FOUND */
80 "Host name lookup failure", /*%< 2 TRY_AGAIN */
81 "Unknown server error", /*%< 3 NO_RECOVERY */
82 "No address associated with name", /*%< 4 NO_ADDRESS */
83 };
84
85 static int h_nerr = sizeof(h_errlist) / sizeof(h_errlist[0]);
86
87
88 /*!
89 * herror --
90 * print the error indicated by the h_errno value.
91 */
92 void
lwres_herror(const char * s)93 lwres_herror(const char *s) {
94 fprintf(stderr, "%s: %s\n", s, lwres_hstrerror(lwres_h_errno));
95 }
96
97 /*!
98 * hstrerror --
99 * return the string associated with a given "host" errno value.
100 */
101 const char *
lwres_hstrerror(int err)102 lwres_hstrerror(int err) {
103 if (err < 0)
104 return ("Resolver internal error");
105 else if (err < h_nerr)
106 return (h_errlist[err]);
107 return ("Unknown resolver error");
108 }
109