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