xref: /minix/external/bsd/bind/dist/lib/lwres/herror.c (revision 00b67f09)
1*00b67f09SDavid van Moolenbroek /*	$NetBSD: herror.c,v 1.6 2014/12/10 04:38:02 christos Exp $	*/
2*00b67f09SDavid van Moolenbroek 
3*00b67f09SDavid van Moolenbroek /*
4*00b67f09SDavid van Moolenbroek  * Portions Copyright (C) 2004, 2005, 2007, 2011, 2012, 2014  Internet Systems Consortium, Inc. ("ISC")
5*00b67f09SDavid van Moolenbroek  * Portions Copyright (C) 2000, 2001, 2003  Internet Software Consortium.
6*00b67f09SDavid van Moolenbroek  *
7*00b67f09SDavid van Moolenbroek  * Permission to use, copy, modify, and/or distribute this software for any
8*00b67f09SDavid van Moolenbroek  * purpose with or without fee is hereby granted, provided that the above
9*00b67f09SDavid van Moolenbroek  * copyright notice and this permission notice appear in all copies.
10*00b67f09SDavid van Moolenbroek  *
11*00b67f09SDavid van Moolenbroek  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12*00b67f09SDavid van Moolenbroek  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13*00b67f09SDavid van Moolenbroek  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14*00b67f09SDavid van Moolenbroek  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15*00b67f09SDavid van Moolenbroek  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16*00b67f09SDavid van Moolenbroek  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*00b67f09SDavid van Moolenbroek  * PERFORMANCE OF THIS SOFTWARE.
18*00b67f09SDavid van Moolenbroek  */
19*00b67f09SDavid van Moolenbroek 
20*00b67f09SDavid van Moolenbroek /*
21*00b67f09SDavid van Moolenbroek  * Copyright (c) 1987, 1993
22*00b67f09SDavid van Moolenbroek  *    The Regents of the University of California.  All rights reserved.
23*00b67f09SDavid van Moolenbroek  *
24*00b67f09SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
25*00b67f09SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
26*00b67f09SDavid van Moolenbroek  * are met:
27*00b67f09SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
28*00b67f09SDavid van Moolenbroek  *    notice, this list of conditions and the following disclaimer.
29*00b67f09SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce the above copyright
30*00b67f09SDavid van Moolenbroek  *    notice, this list of conditions and the following disclaimer in the
31*00b67f09SDavid van Moolenbroek  *    documentation and/or other materials provided with the distribution.
32*00b67f09SDavid van Moolenbroek  * 3. Neither the name of the University nor the names of its contributors
33*00b67f09SDavid van Moolenbroek  *    may be used to endorse or promote products derived from this software
34*00b67f09SDavid van Moolenbroek  *    without specific prior written permission.
35*00b67f09SDavid van Moolenbroek  *
36*00b67f09SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
37*00b67f09SDavid van Moolenbroek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38*00b67f09SDavid van Moolenbroek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39*00b67f09SDavid van Moolenbroek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40*00b67f09SDavid van Moolenbroek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41*00b67f09SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42*00b67f09SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43*00b67f09SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44*00b67f09SDavid van Moolenbroek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45*00b67f09SDavid van Moolenbroek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46*00b67f09SDavid van Moolenbroek  * SUCH DAMAGE.
47*00b67f09SDavid van Moolenbroek  */
48*00b67f09SDavid van Moolenbroek 
49*00b67f09SDavid van Moolenbroek /*! \file herror.c
50*00b67f09SDavid van Moolenbroek    lwres_herror() prints the string s on stderr followed by the string
51*00b67f09SDavid van Moolenbroek    generated by lwres_hstrerror() for the error code stored in the global
52*00b67f09SDavid van Moolenbroek    variable lwres_h_errno.
53*00b67f09SDavid van Moolenbroek 
54*00b67f09SDavid van Moolenbroek    lwres_hstrerror() returns an appropriate string for the error code
55*00b67f09SDavid van Moolenbroek    gievn by err. The values of the error codes and messages are as
56*00b67f09SDavid van Moolenbroek    follows:
57*00b67f09SDavid van Moolenbroek 
58*00b67f09SDavid van Moolenbroek \li   #NETDB_SUCCESS: Resolver Error 0 (no error)
59*00b67f09SDavid van Moolenbroek 
60*00b67f09SDavid van Moolenbroek \li   #HOST_NOT_FOUND: Unknown host
61*00b67f09SDavid van Moolenbroek 
62*00b67f09SDavid van Moolenbroek \li #TRY_AGAIN: Host name lookup failure
63*00b67f09SDavid van Moolenbroek 
64*00b67f09SDavid van Moolenbroek \li   #NO_RECOVERY: Unknown server error
65*00b67f09SDavid van Moolenbroek 
66*00b67f09SDavid van Moolenbroek \li   #NO_DATA: No address associated with name
67*00b67f09SDavid van Moolenbroek 
68*00b67f09SDavid van Moolenbroek  */
69*00b67f09SDavid van Moolenbroek 
70*00b67f09SDavid van Moolenbroek #if defined(LIBC_SCCS) && !defined(lint)
71*00b67f09SDavid van Moolenbroek static const char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 6/4/93";
72*00b67f09SDavid van Moolenbroek static const char rcsid[] =
73*00b67f09SDavid van Moolenbroek 	"Id";
74*00b67f09SDavid van Moolenbroek #endif /* LIBC_SCCS and not lint */
75*00b67f09SDavid van Moolenbroek 
76*00b67f09SDavid van Moolenbroek #include <config.h>
77*00b67f09SDavid van Moolenbroek 
78*00b67f09SDavid van Moolenbroek #include <stdio.h>
79*00b67f09SDavid van Moolenbroek 
80*00b67f09SDavid van Moolenbroek #include <lwres/netdb.h>
81*00b67f09SDavid van Moolenbroek #include <lwres/platform.h>
82*00b67f09SDavid van Moolenbroek 
83*00b67f09SDavid van Moolenbroek LIBLWRES_EXTERNAL_DATA int	lwres_h_errno;
84*00b67f09SDavid van Moolenbroek 
85*00b67f09SDavid van Moolenbroek /*!
86*00b67f09SDavid van Moolenbroek  * these have never been declared in any header file so make them static
87*00b67f09SDavid van Moolenbroek  */
88*00b67f09SDavid van Moolenbroek 
89*00b67f09SDavid van Moolenbroek static const char *h_errlist[] = {
90*00b67f09SDavid van Moolenbroek 	"Resolver Error 0 (no error)",		/*%< 0 no error */
91*00b67f09SDavid van Moolenbroek 	"Unknown host",				/*%< 1 HOST_NOT_FOUND */
92*00b67f09SDavid van Moolenbroek 	"Host name lookup failure",		/*%< 2 TRY_AGAIN */
93*00b67f09SDavid van Moolenbroek 	"Unknown server error",			/*%< 3 NO_RECOVERY */
94*00b67f09SDavid van Moolenbroek 	"No address associated with name",	/*%< 4 NO_ADDRESS */
95*00b67f09SDavid van Moolenbroek };
96*00b67f09SDavid van Moolenbroek 
97*00b67f09SDavid van Moolenbroek static int	h_nerr = sizeof(h_errlist) / sizeof(h_errlist[0]);
98*00b67f09SDavid van Moolenbroek 
99*00b67f09SDavid van Moolenbroek 
100*00b67f09SDavid van Moolenbroek /*!
101*00b67f09SDavid van Moolenbroek  * herror --
102*00b67f09SDavid van Moolenbroek  *	print the error indicated by the h_errno value.
103*00b67f09SDavid van Moolenbroek  */
104*00b67f09SDavid van Moolenbroek void
lwres_herror(const char * s)105*00b67f09SDavid van Moolenbroek lwres_herror(const char *s) {
106*00b67f09SDavid van Moolenbroek 	fprintf(stderr, "%s: %s\n", s, lwres_hstrerror(lwres_h_errno));
107*00b67f09SDavid van Moolenbroek }
108*00b67f09SDavid van Moolenbroek 
109*00b67f09SDavid van Moolenbroek /*!
110*00b67f09SDavid van Moolenbroek  * hstrerror --
111*00b67f09SDavid van Moolenbroek  *	return the string associated with a given "host" errno value.
112*00b67f09SDavid van Moolenbroek  */
113*00b67f09SDavid van Moolenbroek const char *
lwres_hstrerror(int err)114*00b67f09SDavid van Moolenbroek lwres_hstrerror(int err) {
115*00b67f09SDavid van Moolenbroek 	if (err < 0)
116*00b67f09SDavid van Moolenbroek 		return ("Resolver internal error");
117*00b67f09SDavid van Moolenbroek 	else if (err < h_nerr)
118*00b67f09SDavid van Moolenbroek 		return (h_errlist[err]);
119*00b67f09SDavid van Moolenbroek 	return ("Unknown resolver error");
120*00b67f09SDavid van Moolenbroek }
121