xref: /csrg-svn/lib/libc/net/herror.c (revision 42626)
1 /*
2  * Copyright (c) 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)herror.c	6.5 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/uio.h>
14 
15 char	*h_errlist[] = {
16 	"Error 0",
17 	"Unknown host",				/* 1 HOST_NOT_FOUND */
18 	"Host name lookup failure",		/* 2 TRY_AGAIN */
19 	"Unknown server error",			/* 3 NO_RECOVERY */
20 	"No address associated with name",	/* 4 NO_ADDRESS */
21 };
22 int	h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
23 
24 extern int	h_errno;
25 
26 /*
27  * herror --
28  *	print the error indicated by the h_errno value.
29  */
30 herror(s)
31 	char *s;
32 {
33 	struct iovec iov[4];
34 	register struct iovec *v = iov;
35 
36 	if (s && *s) {
37 		v->iov_base = s;
38 		v->iov_len = strlen(s);
39 		v++;
40 		v->iov_base = ": ";
41 		v->iov_len = 2;
42 		v++;
43 	}
44 	v->iov_base = (u_int)h_errno < h_nerr ?
45 	    h_errlist[h_errno] : "Unknown error";
46 	v->iov_len = strlen(v->iov_base);
47 	v++;
48 	v->iov_base = "\n";
49 	v->iov_len = 1;
50 	writev(2, iov, (v - iov) + 1);
51 }
52