xref: /original-bsd/lib/libc/net/herror.c (revision e811aa08)
1 /*-
2  * Copyright (c) 1987, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  * -
7  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies, and that
12  * the name of Digital Equipment Corporation not be used in advertising or
13  * publicity pertaining to distribution of the document or software without
14  * specific, written prior permission.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
17  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
19  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
21  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
22  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23  * SOFTWARE.
24  * -
25  * --Copyright--
26  */
27 
28 #if defined(LIBC_SCCS) && !defined(lint)
29 static char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 06/04/93";
30 static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel $";
31 #endif /* LIBC_SCCS and not lint */
32 
33 #include <sys/types.h>
34 #include <sys/uio.h>
35 #include <netdb.h>
36 #include <unistd.h>
37 #include <string.h>
38 
39 char	*h_errlist[] = {
40 	"Error 0",
41 	"Unknown host",				/* 1 HOST_NOT_FOUND */
42 	"Host name lookup failure",		/* 2 TRY_AGAIN */
43 	"Unknown server error",			/* 3 NO_RECOVERY */
44 	"No address associated with name",	/* 4 NO_ADDRESS */
45 };
46 int	h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
47 
48 extern int	h_errno;
49 
50 /*
51  * herror --
52  *	print the error indicated by the h_errno value.
53  */
54 void
55 herror(s)
56 	const char *s;
57 {
58 	struct iovec iov[4];
59 	register struct iovec *v = iov;
60 
61 	if (s && *s) {
62 		v->iov_base = (char *)s;
63 		v->iov_len = strlen(s);
64 		v++;
65 		v->iov_base = ": ";
66 		v->iov_len = 2;
67 		v++;
68 	}
69 	v->iov_base = (u_int)h_errno < h_nerr ?
70 	    h_errlist[h_errno] : "Unknown error";
71 	v->iov_len = strlen(v->iov_base);
72 	v++;
73 	v->iov_base = "\n";
74 	v->iov_len = 1;
75 	writev(STDERR_FILENO, iov, (v - iov) + 1);
76 }
77 
78 char *
79 hstrerror(err)
80 	int err;
81 {
82 	return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error";
83 }
84