xref: /dragonfly/lib/libc/resolv/herror.c (revision fbfb85d2)
1ee65b806SJan Lentfer /*
2*fbfb85d2SSascha Wildner  * @(#)herror.c	8.1 (Berkeley) 6/4/93
3*fbfb85d2SSascha Wildner  * $Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp $
4*fbfb85d2SSascha Wildner  */
5*fbfb85d2SSascha Wildner 
6*fbfb85d2SSascha Wildner /*
7ee65b806SJan Lentfer  * Copyright (c) 1987, 1993
8ee65b806SJan Lentfer  *    The Regents of the University of California.  All rights reserved.
9ee65b806SJan Lentfer  *
10ee65b806SJan Lentfer  * Redistribution and use in source and binary forms, with or without
11ee65b806SJan Lentfer  * modification, are permitted provided that the following conditions
12ee65b806SJan Lentfer  * are met:
13ee65b806SJan Lentfer  * 1. Redistributions of source code must retain the above copyright
14ee65b806SJan Lentfer  *    notice, this list of conditions and the following disclaimer.
15ee65b806SJan Lentfer  * 2. Redistributions in binary form must reproduce the above copyright
16ee65b806SJan Lentfer  *    notice, this list of conditions and the following disclaimer in the
17ee65b806SJan Lentfer  *    documentation and/or other materials provided with the distribution.
180f0f9bbdSzrj  * 3. Neither the name of the University nor the names of its contributors
19ee65b806SJan Lentfer  *    may be used to endorse or promote products derived from this software
20ee65b806SJan Lentfer  *    without specific prior written permission.
21ee65b806SJan Lentfer  *
22ee65b806SJan Lentfer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23ee65b806SJan Lentfer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ee65b806SJan Lentfer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ee65b806SJan Lentfer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26ee65b806SJan Lentfer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ee65b806SJan Lentfer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ee65b806SJan Lentfer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ee65b806SJan Lentfer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ee65b806SJan Lentfer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ee65b806SJan Lentfer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ee65b806SJan Lentfer  * SUCH DAMAGE.
33ee65b806SJan Lentfer  */
34ee65b806SJan Lentfer 
35ee65b806SJan Lentfer /*
36ee65b806SJan Lentfer  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
37ee65b806SJan Lentfer  * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
38ee65b806SJan Lentfer  *
39ee65b806SJan Lentfer  * Permission to use, copy, modify, and distribute this software for any
40ee65b806SJan Lentfer  * purpose with or without fee is hereby granted, provided that the above
41ee65b806SJan Lentfer  * copyright notice and this permission notice appear in all copies.
42ee65b806SJan Lentfer  *
43ee65b806SJan Lentfer  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
44ee65b806SJan Lentfer  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
45ee65b806SJan Lentfer  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
46ee65b806SJan Lentfer  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47ee65b806SJan Lentfer  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
48ee65b806SJan Lentfer  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
49ee65b806SJan Lentfer  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50ee65b806SJan Lentfer  */
51ee65b806SJan Lentfer 
52ee65b806SJan Lentfer #include "port_before.h"
53ee65b806SJan Lentfer 
54ee65b806SJan Lentfer #ifdef _LIBC
55ee65b806SJan Lentfer #include "namespace.h"
56ee65b806SJan Lentfer #endif
57ee65b806SJan Lentfer 
58ee65b806SJan Lentfer #include <sys/types.h>
59ee65b806SJan Lentfer #include <sys/param.h>
60ee65b806SJan Lentfer #include <sys/uio.h>
61ee65b806SJan Lentfer 
62ee65b806SJan Lentfer #include <netinet/in.h>
63ee65b806SJan Lentfer #include <arpa/nameser.h>
64ee65b806SJan Lentfer 
65ee65b806SJan Lentfer #include <netdb.h>
66ee65b806SJan Lentfer #include <resolv.h>
67ee65b806SJan Lentfer #include <string.h>
68ee65b806SJan Lentfer #include <unistd.h>
69ee65b806SJan Lentfer #ifndef _LIBC
70ee65b806SJan Lentfer #include <irs.h>
71ee65b806SJan Lentfer #else
72ee65b806SJan Lentfer #include "un-namespace.h"
73ee65b806SJan Lentfer #endif
74ee65b806SJan Lentfer 
75ee65b806SJan Lentfer #include "port_after.h"
76ee65b806SJan Lentfer 
77ee65b806SJan Lentfer const char *h_errlist[] = {
78ee65b806SJan Lentfer 	"Resolver Error 0 (no error)",
79ee65b806SJan Lentfer 	"Unknown host",				/*%< 1 HOST_NOT_FOUND */
80ee65b806SJan Lentfer 	"Host name lookup failure",		/*%< 2 TRY_AGAIN */
81ee65b806SJan Lentfer 	"Unknown server error",			/*%< 3 NO_RECOVERY */
82ee65b806SJan Lentfer 	"No address associated with name",	/*%< 4 NO_ADDRESS */
83ee65b806SJan Lentfer };
841448a966SSascha Wildner int	h_nerr = { NELEM(h_errlist) };
85ee65b806SJan Lentfer 
86ee65b806SJan Lentfer #if !(__GLIBC__ > 2 || __GLIBC__ == 2 &&  __GLIBC_MINOR__ >= 3)
87ee65b806SJan Lentfer #undef	h_errno
88ee65b806SJan Lentfer int	h_errno;
89ee65b806SJan Lentfer #endif
90ee65b806SJan Lentfer 
91ee65b806SJan Lentfer /*%
92ee65b806SJan Lentfer  * herror --
93ee65b806SJan Lentfer  *	print the error indicated by the h_errno value.
94ee65b806SJan Lentfer  */
95ee65b806SJan Lentfer void
herror(const char * s)96ee65b806SJan Lentfer herror(const char *s) {
97ee65b806SJan Lentfer 	struct iovec iov[4], *v = iov;
98ee65b806SJan Lentfer 	char *t;
99ee65b806SJan Lentfer 
100ee65b806SJan Lentfer 	if (s != NULL && *s != '\0') {
101ee65b806SJan Lentfer 		DE_CONST(s, t);
102ee65b806SJan Lentfer 		v->iov_base = t;
103ee65b806SJan Lentfer 		v->iov_len = strlen(t);
104ee65b806SJan Lentfer 		v++;
105ee65b806SJan Lentfer 		DE_CONST(": ", t);
106ee65b806SJan Lentfer 		v->iov_base = t;
107ee65b806SJan Lentfer 		v->iov_len = 2;
108ee65b806SJan Lentfer 		v++;
109ee65b806SJan Lentfer 	}
110ee65b806SJan Lentfer 	DE_CONST(hstrerror(*__h_errno()), t);
111ee65b806SJan Lentfer 	v->iov_base = t;
112ee65b806SJan Lentfer 	v->iov_len = strlen(v->iov_base);
113ee65b806SJan Lentfer 	v++;
114ee65b806SJan Lentfer 	DE_CONST("\n", t);
115ee65b806SJan Lentfer 	v->iov_base = t;
116ee65b806SJan Lentfer 	v->iov_len = 1;
117ee65b806SJan Lentfer #ifndef _LIBC
118ee65b806SJan Lentfer 	writev(STDERR_FILENO, iov, (v - iov) + 1);
119ee65b806SJan Lentfer #else
120ee65b806SJan Lentfer 	_writev(STDERR_FILENO, iov, (v - iov) + 1);
121ee65b806SJan Lentfer #endif
122ee65b806SJan Lentfer }
123ee65b806SJan Lentfer 
124ee65b806SJan Lentfer /*%
125ee65b806SJan Lentfer  * hstrerror --
126ee65b806SJan Lentfer  *	return the string associated with a given "host" errno value.
127ee65b806SJan Lentfer  */
128ee65b806SJan Lentfer const char *
hstrerror(int err)129ee65b806SJan Lentfer hstrerror(int err) {
130ee65b806SJan Lentfer 	if (err < 0)
131ee65b806SJan Lentfer 		return ("Resolver internal error");
132ee65b806SJan Lentfer 	else if (err < h_nerr)
133ee65b806SJan Lentfer 		return (h_errlist[err]);
134ee65b806SJan Lentfer 	return ("Unknown resolver error");
135ee65b806SJan Lentfer }
136ee65b806SJan Lentfer 
137ee65b806SJan Lentfer /*! \file */
138