xref: /original-bsd/lib/libc/net/herror.c (revision abb30312)
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.6 (Berkeley) 02/24/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/uio.h>
14 #include <netdb.h>
15 #include <unistd.h>
16 #include <string.h>
17 
18 char	*h_errlist[] = {
19 	"Error 0",
20 	"Unknown host",				/* 1 HOST_NOT_FOUND */
21 	"Host name lookup failure",		/* 2 TRY_AGAIN */
22 	"Unknown server error",			/* 3 NO_RECOVERY */
23 	"No address associated with name",	/* 4 NO_ADDRESS */
24 };
25 int	h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
26 
27 extern int	h_errno;
28 
29 /*
30  * herror --
31  *	print the error indicated by the h_errno value.
32  */
33 void
34 herror(s)
35 	const char *s;
36 {
37 	struct iovec iov[4];
38 	register struct iovec *v = iov;
39 
40 	if (s && *s) {
41 		v->iov_base = (char *)s;
42 		v->iov_len = strlen(s);
43 		v++;
44 		v->iov_base = ": ";
45 		v->iov_len = 2;
46 		v++;
47 	}
48 	v->iov_base = (u_int)h_errno < h_nerr ?
49 	    h_errlist[h_errno] : "Unknown error";
50 	v->iov_len = strlen(v->iov_base);
51 	v++;
52 	v->iov_base = "\n";
53 	v->iov_len = 1;
54 	writev(STDERR_FILENO, iov, (v - iov) + 1);
55 }
56