xref: /csrg-svn/lib/libc/net/herror.c (revision 61150)
161023Skarels /*-
2*61150Sbostic  * Copyright (c) 1987, 1993
3*61150Sbostic  *	The Regents of the University of California.  All rights reserved.
433679Sbostic  *
542626Sbostic  * %sccs.include.redist.c%
661023Skarels  * -
761023Skarels  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
861023Skarels  *
961023Skarels  * Permission to use, copy, modify, and distribute this software for any
1061023Skarels  * purpose with or without fee is hereby granted, provided that the above
1161023Skarels  * copyright notice and this permission notice appear in all copies, and that
1261023Skarels  * the name of Digital Equipment Corporation not be used in advertising or
1361023Skarels  * publicity pertaining to distribution of the document or software without
1461023Skarels  * specific, written prior permission.
1561023Skarels  *
1661023Skarels  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
1761023Skarels  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
1861023Skarels  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
1961023Skarels  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
2061023Skarels  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
2161023Skarels  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
2261023Skarels  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2361023Skarels  * SOFTWARE.
2461023Skarels  * -
2561023Skarels  * --Copyright--
2632631Sbostic  */
2732631Sbostic 
2832755Skarels #if defined(LIBC_SCCS) && !defined(lint)
29*61150Sbostic static char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 06/04/93";
3061023Skarels 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
herror(s)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 }
7761023Skarels 
7861023Skarels char *
hstrerror(err)7961023Skarels hstrerror(err)
8061023Skarels 	int err;
8161023Skarels {
8261023Skarels 	return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error";
8361023Skarels }
84