herror.c revision 170244
11556Srgrimes/* 21556Srgrimes * Copyright (c) 1987, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * Redistribution and use in source and binary forms, with or without 61556Srgrimes * modification, are permitted provided that the following conditions 71556Srgrimes * are met: 81556Srgrimes * 1. Redistributions of source code must retain the above copyright 91556Srgrimes * notice, this list of conditions and the following disclaimer. 101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111556Srgrimes * notice, this list of conditions and the following disclaimer in the 121556Srgrimes * documentation and/or other materials provided with the distribution. 131556Srgrimes * 4. Neither the name of the University nor the names of its contributors 141556Srgrimes * may be used to endorse or promote products derived from this software 151556Srgrimes * without specific prior written permission. 161556Srgrimes * 171556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271556Srgrimes * SUCH DAMAGE. 281556Srgrimes */ 291556Srgrimes 301556Srgrimes/* 311556Srgrimes * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 321556Srgrimes * Portions Copyright (c) 1996-1999 by Internet Software Consortium. 331556Srgrimes * 3436150Scharnier * Permission to use, copy, modify, and distribute this software for any 3536150Scharnier * purpose with or without fee is hereby granted, provided that the above 3636150Scharnier * copyright notice and this permission notice appear in all copies. 371556Srgrimes * 3899110Sobrien * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 3999110Sobrien * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 401556Srgrimes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 41100437Stjr * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 4217987Speter * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 43102576Skeramida * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 4417987Speter * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 4545266Scracauer */ 4653891Scracauer 4717987Speter#if defined(LIBC_SCCS) && !defined(lint) 481556Srgrimesstatic const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; 491556Srgrimesstatic const char rcsid[] = "$Id: herror.c,v 1.3.18.1 2005/04/27 05:01:09 sra Exp $"; 501556Srgrimes#endif /* LIBC_SCCS and not lint */ 511556Srgrimes#include <sys/cdefs.h> 521556Srgrimes__FBSDID("$FreeBSD: head/lib/libc/resolv/herror.c 170244 2007-06-03 17:20:27Z ume $"); 531556Srgrimes 541556Srgrimes#include "port_before.h" 551556Srgrimes 561556Srgrimes#include "namespace.h" 571556Srgrimes#include <sys/types.h> 581556Srgrimes#include <sys/param.h> 591556Srgrimes#include <sys/uio.h> 601556Srgrimes 611556Srgrimes#include <netinet/in.h> 621556Srgrimes#include <arpa/nameser.h> 631556Srgrimes 641556Srgrimes#include <netdb.h> 651556Srgrimes#include <resolv.h> 661556Srgrimes#include <string.h> 671556Srgrimes#include <unistd.h> 681556Srgrimes#include "un-namespace.h" 6917987Speter 701556Srgrimes#include "port_after.h" 7117987Speter 721556Srgrimesconst char *h_errlist[] = { 7317987Speter "Resolver Error 0 (no error)", 741556Srgrimes "Unknown host", /*%< 1 HOST_NOT_FOUND */ 751556Srgrimes "Host name lookup failure", /*%< 2 TRY_AGAIN */ 761556Srgrimes "Unknown server error", /*%< 3 NO_RECOVERY */ 771556Srgrimes "No address associated with name", /*%< 4 NO_ADDRESS */ 781556Srgrimes}; 791556Srgrimesconst int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; 801556Srgrimes 811556Srgrimes#undef h_errno 821556Srgrimesint h_errno; 831556Srgrimes 841556Srgrimes/*% 851556Srgrimes * herror -- 861556Srgrimes * print the error indicated by the h_errno value. 871556Srgrimes */ 881556Srgrimesvoid 891556Srgrimesherror(const char *s) { 9017987Speter struct iovec iov[4], *v = iov; 911556Srgrimes char *t; 921556Srgrimes 93149933Sstefanf if (s != NULL && *s != '\0') { 94149933Sstefanf DE_CONST(s, t); 9590111Simp v->iov_base = t; 9690111Simp v->iov_len = strlen(t); 9790111Simp v++; 9890111Simp DE_CONST(": ", t); 9990111Simp v->iov_base = t; 10090111Simp v->iov_len = 2; 1011556Srgrimes v++; 1021556Srgrimes } 1031556Srgrimes DE_CONST(hstrerror(*__h_errno()), t); 1041556Srgrimes v->iov_base = t; 1051556Srgrimes v->iov_len = strlen(v->iov_base); 1061556Srgrimes v++; 1071556Srgrimes DE_CONST("\n", t); 1081556Srgrimes v->iov_base = t; 1091556Srgrimes v->iov_len = 1; 1101556Srgrimes _writev(STDERR_FILENO, iov, (v - iov) + 1); 1111556Srgrimes} 1121556Srgrimes 1131556Srgrimes/*% 1141556Srgrimes * hstrerror -- 1151556Srgrimes * return the string associated with a given "host" errno value. 1161556Srgrimes */ 1171556Srgrimesconst char * 1181556Srgrimeshstrerror(int err) { 1191556Srgrimes if (err < 0) 1201556Srgrimes return ("Resolver internal error"); 1211556Srgrimes else if (err < h_nerr) 1221556Srgrimes return (h_errlist[err]); 1231556Srgrimes return ("Unknown resolver error"); 12446684Skris} 1251556Srgrimes 1261556Srgrimes/*! \file */ 12717987Speter