132631Sbostic /* 232631Sbostic * Copyright (c) 1987 Regents of the University of California. 333679Sbostic * All rights reserved. 433679Sbostic * 5*42626Sbostic * %sccs.include.redist.c% 632631Sbostic */ 732631Sbostic 832755Skarels #if defined(LIBC_SCCS) && !defined(lint) 9*42626Sbostic static char sccsid[] = "@(#)herror.c 6.5 (Berkeley) 06/01/90"; 1033679Sbostic #endif /* LIBC_SCCS and not lint */ 1132631Sbostic 1232631Sbostic #include <sys/types.h> 1332631Sbostic #include <sys/uio.h> 1432631Sbostic 1532631Sbostic char *h_errlist[] = { 1632631Sbostic "Error 0", 1732631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 1832631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 1932631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 2032631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 2132631Sbostic }; 2232631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 2332631Sbostic 2432631Sbostic extern int h_errno; 2532631Sbostic 2632631Sbostic /* 2732631Sbostic * herror -- 2832631Sbostic * print the error indicated by the h_errno value. 2932631Sbostic */ 3032631Sbostic herror(s) 3132631Sbostic char *s; 3232631Sbostic { 3332631Sbostic struct iovec iov[4]; 3432631Sbostic register struct iovec *v = iov; 3532631Sbostic 3632631Sbostic if (s && *s) { 3732631Sbostic v->iov_base = s; 3832631Sbostic v->iov_len = strlen(s); 3932631Sbostic v++; 4032631Sbostic v->iov_base = ": "; 4132631Sbostic v->iov_len = 2; 4232631Sbostic v++; 4332631Sbostic } 4436183Sbostic v->iov_base = (u_int)h_errno < h_nerr ? 4536183Sbostic h_errlist[h_errno] : "Unknown error"; 4632631Sbostic v->iov_len = strlen(v->iov_base); 4732631Sbostic v++; 4832631Sbostic v->iov_base = "\n"; 4932631Sbostic v->iov_len = 1; 5032631Sbostic writev(2, iov, (v - iov) + 1); 5132631Sbostic } 52