/*-1* SPDX-License-Identifier: (BSD-3-Clause AND ISC)2*3* Copyright (c) 1987, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031/*32* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")33* Portions Copyright (c) 1996-1999 by Internet Software Consortium.34*35* Permission to use, copy, modify, and distribute this software for any36* purpose with or without fee is hereby granted, provided that the above37* copyright notice and this permission notice appear in all copies.38*39* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES40* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF41* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR42* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES43* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN44* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT45* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.46*/4748#include "port_before.h"4950#include "namespace.h"51#include <sys/param.h>52#include <sys/uio.h>5354#include <netinet/in.h>55#include <arpa/nameser.h>5657#include <netdb.h>58#include <resolv.h>59#include <string.h>60#include <unistd.h>61#include "un-namespace.h"6263#include "port_after.h"6465const char *h_errlist[] = {66"Resolver Error 0 (no error)",67"Unknown host", /*%< 1 HOST_NOT_FOUND */68"Host name lookup failure", /*%< 2 TRY_AGAIN */69"Unknown server error", /*%< 3 NO_RECOVERY */70"No address associated with name", /*%< 4 NO_ADDRESS */71};72const int h_nerr = { nitems(h_errlist) };7374#undef h_errno75int h_errno;7677/*%78* herror --79* print the error indicated by the h_errno value.80*/81void82herror(const char *s) {83struct iovec iov[4], *v = iov;84char *t;8586if (s != NULL && *s != '\0') {87DE_CONST(s, t);88v->iov_base = t;89v->iov_len = strlen(t);90v++;91DE_CONST(": ", t);92v->iov_base = t;93v->iov_len = 2;94v++;95}96DE_CONST(hstrerror(*__h_errno()), t);97v->iov_base = t;98v->iov_len = strlen(v->iov_base);99v++;100DE_CONST("\n", t);101v->iov_base = t;102v->iov_len = 1;103_writev(STDERR_FILENO, iov, (v - iov) + 1);104}105106/*%107* hstrerror --108* return the string associated with a given "host" errno value.109*/110const char *111hstrerror(int err) {112if (err < 0)113return ("Resolver internal error");114else if (err < h_nerr)115return (h_errlist[err]);116return ("Unknown resolver error");117}118119/*! \file */120121122