herror.c revision 156956
1223637Sbz/* 2126258Smlaier * Copyright (c) 1987, 1993 3126258Smlaier * The Regents of the University of California. All rights reserved. 4126258Smlaier * 5126258Smlaier * Redistribution and use in source and binary forms, with or without 6126258Smlaier * modification, are permitted provided that the following conditions 7126258Smlaier * are met: 8126258Smlaier * 1. Redistributions of source code must retain the above copyright 9126258Smlaier * notice, this list of conditions and the following disclaimer. 10126258Smlaier * 2. Redistributions in binary form must reproduce the above copyright 11126258Smlaier * notice, this list of conditions and the following disclaimer in the 12126258Smlaier * documentation and/or other materials provided with the distribution. 13126258Smlaier * 3. All advertising materials mentioning features or use of this software 14126258Smlaier * must display the following acknowledgement: 15126258Smlaier * This product includes software developed by the University of 16126258Smlaier * California, Berkeley and its contributors. 17126258Smlaier * 4. Neither the name of the University nor the names of its contributors 18126258Smlaier * may be used to endorse or promote products derived from this software 19126258Smlaier * without specific prior written permission. 20126258Smlaier * 21126258Smlaier * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22126258Smlaier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23126258Smlaier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24126258Smlaier * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25126258Smlaier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26126258Smlaier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27126258Smlaier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28126258Smlaier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29223637Sbz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30223637Sbz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31223637Sbz * SUCH DAMAGE. 32223637Sbz */ 33223637Sbz 34223637Sbz/* 35223637Sbz * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 36223637Sbz * Portions Copyright (c) 1996-1999 by Internet Software Consortium. 37223637Sbz * 38223637Sbz * Permission to use, copy, modify, and distribute this software for any 39223637Sbz * purpose with or without fee is hereby granted, provided that the above 40223637Sbz * copyright notice and this permission notice appear in all copies. 41223637Sbz * 42223637Sbz * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 43223637Sbz * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 44223637Sbz * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 45126258Smlaier * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 46223637Sbz * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 47126258Smlaier * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 48223637Sbz * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 49223637Sbz */ 50130613Smlaier 51223637Sbz#if defined(LIBC_SCCS) && !defined(lint) 52223637Sbzstatic const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; 53223637Sbzstatic const char rcsid[] = "$Id: herror.c,v 1.2.206.1 2004/03/09 08:33:54 marka Exp $"; 54223637Sbz#endif /* LIBC_SCCS and not lint */ 55223637Sbz#include <sys/cdefs.h> 56223637Sbz__FBSDID("$FreeBSD: head/lib/libc/resolv/herror.c 156956 2006-03-21 15:37:16Z ume $"); 57223637Sbz 58223637Sbz#include "port_before.h" 59223637Sbz 60223637Sbz#include "namespace.h" 61223637Sbz#include <sys/types.h> 62223637Sbz#include <sys/param.h> 63223637Sbz#include <sys/uio.h> 64223637Sbz 65130613Smlaier#include <netinet/in.h> 66223637Sbz#include <arpa/nameser.h> 67223637Sbz 68223637Sbz#include <netdb.h> 69223637Sbz#include <resolv.h> 70223637Sbz#include <string.h> 71223637Sbz#include <unistd.h> 72223637Sbz#include "un-namespace.h" 73223637Sbz 74223637Sbz#include "port_after.h" 75223637Sbz 76223637Sbzconst char *h_errlist[] = { 77223637Sbz "Resolver Error 0 (no error)", 78223637Sbz "Unknown host", /* 1 HOST_NOT_FOUND */ 79130613Smlaier "Host name lookup failure", /* 2 TRY_AGAIN */ 80223637Sbz "Unknown server error", /* 3 NO_RECOVERY */ 81223637Sbz "No address associated with name", /* 4 NO_ADDRESS */ 82223637Sbz}; 83223637Sbzconst int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; 84223637Sbz 85223637Sbz#undef h_errno 86223637Sbzint h_errno; 87223637Sbz 88223637Sbz/* 89223637Sbz * herror -- 90223637Sbz * print the error indicated by the h_errno value. 91223637Sbz */ 92223637Sbzvoid 93223637Sbzherror(const char *s) { 94223637Sbz struct iovec iov[4], *v = iov; 95223637Sbz char *t; 96223637Sbz 97223637Sbz if (s != NULL && *s != '\0') { 98223637Sbz DE_CONST(s, t); 99223637Sbz v->iov_base = t; 100223637Sbz v->iov_len = strlen(t); 101223637Sbz v++; 102223637Sbz DE_CONST(": ", t); 103223637Sbz v->iov_base = t; 104223637Sbz v->iov_len = 2; 105223637Sbz v++; 106223637Sbz } 107223637Sbz DE_CONST(hstrerror(*__h_errno()), t); 108223637Sbz v->iov_base = t; 109223637Sbz v->iov_len = strlen(v->iov_base); 110223637Sbz v++; 111223637Sbz DE_CONST("\n", t); 112223637Sbz v->iov_base = t; 113223637Sbz v->iov_len = 1; 114223637Sbz _writev(STDERR_FILENO, iov, (v - iov) + 1); 115223637Sbz} 116223637Sbz 117130613Smlaier/* 118130613Smlaier * hstrerror -- 119223637Sbz * return the string associated with a given "host" errno value. 120223637Sbz */ 121223637Sbzconst char * 122223637Sbzhstrerror(int err) { 123223637Sbz if (err < 0) 124223637Sbz return ("Resolver internal error"); 125223637Sbz else if (err < h_nerr) 126223637Sbz return (h_errlist[err]); 127130613Smlaier return ("Unknown resolver error"); 128130613Smlaier} 129223637Sbz