xref: /onnv-gate/usr/src/lib/libresolv2/common/resolv/herror.c (revision 11038:74b12212b8a2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright (c) 1987, 1993
30Sstevel@tonic-gate  *    The Regents of the University of California.  All rights reserved.
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
60Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
70Sstevel@tonic-gate  * are met:
80Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
90Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
100Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
110Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
120Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
130Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
140Sstevel@tonic-gate  *    must display the following acknowledgement:
150Sstevel@tonic-gate  * 	This product includes software developed by the University of
160Sstevel@tonic-gate  * 	California, Berkeley and its contributors.
170Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
180Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
190Sstevel@tonic-gate  *    without specific prior written permission.
200Sstevel@tonic-gate  *
210Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
220Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
230Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
240Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
250Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
260Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
270Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
280Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
290Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
300Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
310Sstevel@tonic-gate  * SUCH DAMAGE.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate /*
35*11038SRao.Shoaib@Sun.COM  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
360Sstevel@tonic-gate  * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software for any
390Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
400Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
410Sstevel@tonic-gate  *
42*11038SRao.Shoaib@Sun.COM  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
43*11038SRao.Shoaib@Sun.COM  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
44*11038SRao.Shoaib@Sun.COM  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
45*11038SRao.Shoaib@Sun.COM  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
46*11038SRao.Shoaib@Sun.COM  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
47*11038SRao.Shoaib@Sun.COM  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
48*11038SRao.Shoaib@Sun.COM  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #if defined(LIBC_SCCS) && !defined(lint)
520Sstevel@tonic-gate static const char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 6/4/93";
53*11038SRao.Shoaib@Sun.COM static const char rcsid[] = "$Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp $";
540Sstevel@tonic-gate #endif /* LIBC_SCCS and not lint */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #include "port_before.h"
570Sstevel@tonic-gate 
580Sstevel@tonic-gate #include <sys/types.h>
590Sstevel@tonic-gate #include <sys/param.h>
600Sstevel@tonic-gate #include <sys/uio.h>
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #include <netinet/in.h>
630Sstevel@tonic-gate #include <arpa/nameser.h>
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #include <netdb.h>
660Sstevel@tonic-gate #include <resolv.h>
670Sstevel@tonic-gate #include <string.h>
680Sstevel@tonic-gate #include <unistd.h>
690Sstevel@tonic-gate #include <irs.h>
700Sstevel@tonic-gate 
710Sstevel@tonic-gate #include "port_after.h"
720Sstevel@tonic-gate 
730Sstevel@tonic-gate const char *h_errlist[] = {
740Sstevel@tonic-gate 	"Resolver Error 0 (no error)",
75*11038SRao.Shoaib@Sun.COM 	"Unknown host",				/*%< 1 HOST_NOT_FOUND */
76*11038SRao.Shoaib@Sun.COM 	"Host name lookup failure",		/*%< 2 TRY_AGAIN */
77*11038SRao.Shoaib@Sun.COM 	"Unknown server error",			/*%< 3 NO_RECOVERY */
78*11038SRao.Shoaib@Sun.COM 	"No address associated with name",	/*%< 4 NO_ADDRESS */
790Sstevel@tonic-gate };
800Sstevel@tonic-gate int	h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
810Sstevel@tonic-gate 
82*11038SRao.Shoaib@Sun.COM #if !(__GLIBC__ > 2 || __GLIBC__ == 2 &&  __GLIBC_MINOR__ >= 3)
83*11038SRao.Shoaib@Sun.COM #undef	h_errno
840Sstevel@tonic-gate int	h_errno;
85*11038SRao.Shoaib@Sun.COM #endif
860Sstevel@tonic-gate 
87*11038SRao.Shoaib@Sun.COM /*%
880Sstevel@tonic-gate  * herror --
890Sstevel@tonic-gate  *	print the error indicated by the h_errno value.
900Sstevel@tonic-gate  */
910Sstevel@tonic-gate void
herror(const char * s)920Sstevel@tonic-gate herror(const char *s) {
930Sstevel@tonic-gate 	struct iovec iov[4], *v = iov;
940Sstevel@tonic-gate 	char *t;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	if (s != NULL && *s != '\0') {
970Sstevel@tonic-gate 		DE_CONST(s, t);
980Sstevel@tonic-gate 		v->iov_base = t;
990Sstevel@tonic-gate 		v->iov_len = strlen(t);
1000Sstevel@tonic-gate 		v++;
1010Sstevel@tonic-gate 		DE_CONST(": ", t);
1020Sstevel@tonic-gate 		v->iov_base = t;
1030Sstevel@tonic-gate 		v->iov_len = 2;
1040Sstevel@tonic-gate 		v++;
1050Sstevel@tonic-gate 	}
1060Sstevel@tonic-gate 	DE_CONST(hstrerror(*__h_errno()), t);
1070Sstevel@tonic-gate 	v->iov_base = t;
1080Sstevel@tonic-gate 	v->iov_len = strlen(v->iov_base);
1090Sstevel@tonic-gate 	v++;
1100Sstevel@tonic-gate 	DE_CONST("\n", t);
1110Sstevel@tonic-gate 	v->iov_base = t;
1120Sstevel@tonic-gate 	v->iov_len = 1;
1130Sstevel@tonic-gate 	writev(STDERR_FILENO, iov, (v - iov) + 1);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
116*11038SRao.Shoaib@Sun.COM /*%
1170Sstevel@tonic-gate  * hstrerror --
1180Sstevel@tonic-gate  *	return the string associated with a given "host" errno value.
1190Sstevel@tonic-gate  */
1200Sstevel@tonic-gate const char *
hstrerror(int err)1210Sstevel@tonic-gate hstrerror(int err) {
1220Sstevel@tonic-gate 	if (err < 0)
1230Sstevel@tonic-gate 		return ("Resolver internal error");
1240Sstevel@tonic-gate 	else if (err < h_nerr)
1250Sstevel@tonic-gate 		return (h_errlist[err]);
1260Sstevel@tonic-gate 	return ("Unknown resolver error");
1270Sstevel@tonic-gate }
128*11038SRao.Shoaib@Sun.COM 
129*11038SRao.Shoaib@Sun.COM /*! \file */
130