132631Sbostic /* 232631Sbostic * Copyright (c) 1987 Regents of the University of California. 333679Sbostic * All rights reserved. 433679Sbostic * 542626Sbostic * %sccs.include.redist.c% 632631Sbostic */ 732631Sbostic 832755Skarels #if defined(LIBC_SCCS) && !defined(lint) 9*46604Sbostic static char sccsid[] = "@(#)herror.c 6.6 (Berkeley) 02/24/91"; 1033679Sbostic #endif /* LIBC_SCCS and not lint */ 1132631Sbostic 1232631Sbostic #include <sys/types.h> 1332631Sbostic #include <sys/uio.h> 14*46604Sbostic #include <netdb.h> 15*46604Sbostic #include <unistd.h> 16*46604Sbostic #include <string.h> 1732631Sbostic 1832631Sbostic char *h_errlist[] = { 1932631Sbostic "Error 0", 2032631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 2132631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 2232631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 2332631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 2432631Sbostic }; 2532631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 2632631Sbostic 2732631Sbostic extern int h_errno; 2832631Sbostic 2932631Sbostic /* 3032631Sbostic * herror -- 3132631Sbostic * print the error indicated by the h_errno value. 3232631Sbostic */ 33*46604Sbostic void 3432631Sbostic herror(s) 35*46604Sbostic const char *s; 3632631Sbostic { 3732631Sbostic struct iovec iov[4]; 3832631Sbostic register struct iovec *v = iov; 3932631Sbostic 4032631Sbostic if (s && *s) { 41*46604Sbostic v->iov_base = (char *)s; 4232631Sbostic v->iov_len = strlen(s); 4332631Sbostic v++; 4432631Sbostic v->iov_base = ": "; 4532631Sbostic v->iov_len = 2; 4632631Sbostic v++; 4732631Sbostic } 4836183Sbostic v->iov_base = (u_int)h_errno < h_nerr ? 4936183Sbostic h_errlist[h_errno] : "Unknown error"; 5032631Sbostic v->iov_len = strlen(v->iov_base); 5132631Sbostic v++; 5232631Sbostic v->iov_base = "\n"; 5332631Sbostic v->iov_len = 1; 54*46604Sbostic writev(STDERR_FILENO, iov, (v - iov) + 1); 5532631Sbostic } 56