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