xref: /original-bsd/lib/libc/net/herror.c (revision a4d3ae46)
1 /*
2  * Copyright (c) 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #if defined(LIBC_SCCS) && !defined(lint)
14 static char sccsid[] = "@(#)herror.c	6.2 (Berkeley) 03/07/88";
15 #endif /* LIBC_SCCS and not lint */
16 
17 #include <sys/types.h>
18 #include <sys/uio.h>
19 
20 char	*h_errlist[] = {
21 	"Error 0",
22 	"Unknown host",				/* 1 HOST_NOT_FOUND */
23 	"Host name lookup failure",		/* 2 TRY_AGAIN */
24 	"Unknown server error",			/* 3 NO_RECOVERY */
25 	"No address associated with name",	/* 4 NO_ADDRESS */
26 };
27 int	h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
28 
29 extern int	h_errno;
30 
31 /*
32  * herror --
33  *	print the error indicated by the h_errno value.
34  */
35 herror(s)
36 	char *s;
37 {
38 	struct iovec iov[4];
39 	register struct iovec *v = iov;
40 
41 	if (s && *s) {
42 		v->iov_base = s;
43 		v->iov_len = strlen(s);
44 		v++;
45 		v->iov_base = ": ";
46 		v->iov_len = 2;
47 		v++;
48 	}
49 	v->iov_base = h_errno < h_nerr ? 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(2, iov, (v - iov) + 1);
55 }
56