1*61023Skarels /*- 232631Sbostic * Copyright (c) 1987 Regents of the University of California. 333679Sbostic * All rights reserved. 433679Sbostic * 542626Sbostic * %sccs.include.redist.c% 6*61023Skarels * - 7*61023Skarels * Portions Copyright (c) 1993 by Digital Equipment Corporation. 8*61023Skarels * 9*61023Skarels * Permission to use, copy, modify, and distribute this software for any 10*61023Skarels * purpose with or without fee is hereby granted, provided that the above 11*61023Skarels * copyright notice and this permission notice appear in all copies, and that 12*61023Skarels * the name of Digital Equipment Corporation not be used in advertising or 13*61023Skarels * publicity pertaining to distribution of the document or software without 14*61023Skarels * specific, written prior permission. 15*61023Skarels * 16*61023Skarels * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 17*61023Skarels * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 18*61023Skarels * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 19*61023Skarels * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 20*61023Skarels * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 21*61023Skarels * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 22*61023Skarels * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 23*61023Skarels * SOFTWARE. 24*61023Skarels * - 25*61023Skarels * --Copyright-- 2632631Sbostic */ 2732631Sbostic 2832755Skarels #if defined(LIBC_SCCS) && !defined(lint) 29*61023Skarels static char sccsid[] = "@(#)herror.c 6.7 (Berkeley) 06/02/93"; 30*61023Skarels static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel $"; 3133679Sbostic #endif /* LIBC_SCCS and not lint */ 3232631Sbostic 3332631Sbostic #include <sys/types.h> 3432631Sbostic #include <sys/uio.h> 3546604Sbostic #include <netdb.h> 3646604Sbostic #include <unistd.h> 3746604Sbostic #include <string.h> 3832631Sbostic 3932631Sbostic char *h_errlist[] = { 4032631Sbostic "Error 0", 4132631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 4232631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 4332631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 4432631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 4532631Sbostic }; 4632631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 4732631Sbostic 4832631Sbostic extern int h_errno; 4932631Sbostic 5032631Sbostic /* 5132631Sbostic * herror -- 5232631Sbostic * print the error indicated by the h_errno value. 5332631Sbostic */ 5446604Sbostic void 5532631Sbostic herror(s) 5646604Sbostic const char *s; 5732631Sbostic { 5832631Sbostic struct iovec iov[4]; 5932631Sbostic register struct iovec *v = iov; 6032631Sbostic 6132631Sbostic if (s && *s) { 6246604Sbostic v->iov_base = (char *)s; 6332631Sbostic v->iov_len = strlen(s); 6432631Sbostic v++; 6532631Sbostic v->iov_base = ": "; 6632631Sbostic v->iov_len = 2; 6732631Sbostic v++; 6832631Sbostic } 6936183Sbostic v->iov_base = (u_int)h_errno < h_nerr ? 7036183Sbostic h_errlist[h_errno] : "Unknown error"; 7132631Sbostic v->iov_len = strlen(v->iov_base); 7232631Sbostic v++; 7332631Sbostic v->iov_base = "\n"; 7432631Sbostic v->iov_len = 1; 7546604Sbostic writev(STDERR_FILENO, iov, (v - iov) + 1); 7632631Sbostic } 77*61023Skarels 78*61023Skarels char * 79*61023Skarels hstrerror(err) 80*61023Skarels int err; 81*61023Skarels { 82*61023Skarels return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error"; 83*61023Skarels } 84