1156952Sume/* 2156952Sume * Copyright (c) 1987, 1993 3156952Sume * The Regents of the University of California. All rights reserved. 4156952Sume * 5156952Sume * Redistribution and use in source and binary forms, with or without 6156952Sume * modification, are permitted provided that the following conditions 7156952Sume * are met: 8156952Sume * 1. Redistributions of source code must retain the above copyright 9156952Sume * notice, this list of conditions and the following disclaimer. 10156952Sume * 2. Redistributions in binary form must reproduce the above copyright 11156952Sume * notice, this list of conditions and the following disclaimer in the 12156952Sume * documentation and/or other materials provided with the distribution. 13156952Sume * 4. Neither the name of the University nor the names of its contributors 14156952Sume * may be used to endorse or promote products derived from this software 15156952Sume * without specific prior written permission. 16156952Sume * 17156952Sume * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18156952Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19156952Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20156952Sume * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21156952Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22156952Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23156952Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24156952Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25156952Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26156952Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27156952Sume * SUCH DAMAGE. 28156952Sume */ 29156952Sume 30156952Sume/* 31156952Sume * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 32156952Sume * Portions Copyright (c) 1996-1999 by Internet Software Consortium. 33156952Sume * 34156952Sume * Permission to use, copy, modify, and distribute this software for any 35156952Sume * purpose with or without fee is hereby granted, provided that the above 36156952Sume * copyright notice and this permission notice appear in all copies. 37156952Sume * 38156952Sume * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 39156952Sume * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 40156952Sume * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 41156952Sume * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 42156952Sume * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 43156952Sume * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 44156952Sume * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 45156952Sume */ 46156952Sume 47156952Sume#if defined(LIBC_SCCS) && !defined(lint) 48156952Sumestatic const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; 49270838Sumestatic const char rcsid[] = "$Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp $"; 50156952Sume#endif /* LIBC_SCCS and not lint */ 51156956Sume#include <sys/cdefs.h> 52156956Sume__FBSDID("$FreeBSD: releng/10.2/lib/libc/resolv/herror.c 270838 2014-08-30 10:16:25Z ume $"); 53156952Sume 54156952Sume#include "port_before.h" 55156952Sume 56156956Sume#include "namespace.h" 57156952Sume#include <sys/types.h> 58156952Sume#include <sys/param.h> 59156952Sume#include <sys/uio.h> 60156952Sume 61156952Sume#include <netinet/in.h> 62156952Sume#include <arpa/nameser.h> 63156952Sume 64156952Sume#include <netdb.h> 65156952Sume#include <resolv.h> 66156952Sume#include <string.h> 67156952Sume#include <unistd.h> 68156956Sume#include "un-namespace.h" 69156952Sume 70156952Sume#include "port_after.h" 71156952Sume 72156952Sumeconst char *h_errlist[] = { 73156952Sume "Resolver Error 0 (no error)", 74170244Sume "Unknown host", /*%< 1 HOST_NOT_FOUND */ 75170244Sume "Host name lookup failure", /*%< 2 TRY_AGAIN */ 76170244Sume "Unknown server error", /*%< 3 NO_RECOVERY */ 77170244Sume "No address associated with name", /*%< 4 NO_ADDRESS */ 78156952Sume}; 79156956Sumeconst int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; 80156952Sume 81156952Sume#undef h_errno 82156952Sumeint h_errno; 83156952Sume 84170244Sume/*% 85156952Sume * herror -- 86156952Sume * print the error indicated by the h_errno value. 87156952Sume */ 88156952Sumevoid 89156952Sumeherror(const char *s) { 90156952Sume struct iovec iov[4], *v = iov; 91156952Sume char *t; 92156952Sume 93156952Sume if (s != NULL && *s != '\0') { 94156952Sume DE_CONST(s, t); 95156952Sume v->iov_base = t; 96156952Sume v->iov_len = strlen(t); 97156952Sume v++; 98156952Sume DE_CONST(": ", t); 99156952Sume v->iov_base = t; 100156952Sume v->iov_len = 2; 101156952Sume v++; 102156952Sume } 103156952Sume DE_CONST(hstrerror(*__h_errno()), t); 104156952Sume v->iov_base = t; 105156952Sume v->iov_len = strlen(v->iov_base); 106156952Sume v++; 107156952Sume DE_CONST("\n", t); 108156952Sume v->iov_base = t; 109156952Sume v->iov_len = 1; 110156956Sume _writev(STDERR_FILENO, iov, (v - iov) + 1); 111156952Sume} 112156952Sume 113170244Sume/*% 114156952Sume * hstrerror -- 115156952Sume * return the string associated with a given "host" errno value. 116156952Sume */ 117156952Sumeconst char * 118156952Sumehstrerror(int err) { 119156952Sume if (err < 0) 120156952Sume return ("Resolver internal error"); 121156952Sume else if (err < h_nerr) 122156952Sume return (h_errlist[err]); 123156952Sume return ("Unknown resolver error"); 124156952Sume} 125170244Sume 126170244Sume/*! \file */ 127