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