132631Sbostic /* 232631Sbostic * Copyright (c) 1987 Regents of the University of California. 332631Sbostic * All rights reserved. The Berkeley software License Agreement 432631Sbostic * specifies the terms and conditions for redistribution. 532631Sbostic */ 632631Sbostic 7*32755Skarels #if defined(LIBC_SCCS) && !defined(lint) 8*32755Skarels static char sccsid[] = "@(#)herror.c 6.1 (Berkeley) 12/04/87"; 9*32755Skarels #endif LIBC_SCCS and not lint 1032631Sbostic 1132631Sbostic #include <sys/types.h> 1232631Sbostic #include <sys/uio.h> 1332631Sbostic 1432631Sbostic char *h_errlist[] = { 1532631Sbostic "Error 0", 1632631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 1732631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 1832631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 1932631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 2032631Sbostic }; 2132631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 2232631Sbostic 2332631Sbostic extern int h_errno; 2432631Sbostic 2532631Sbostic /* 2632631Sbostic * herror -- 2732631Sbostic * print the error indicated by the h_errno value. 2832631Sbostic */ 2932631Sbostic herror(s) 3032631Sbostic char *s; 3132631Sbostic { 3232631Sbostic struct iovec iov[4]; 3332631Sbostic register struct iovec *v = iov; 3432631Sbostic 3532631Sbostic if (s && *s) { 3632631Sbostic v->iov_base = s; 3732631Sbostic v->iov_len = strlen(s); 3832631Sbostic v++; 3932631Sbostic v->iov_base = ": "; 4032631Sbostic v->iov_len = 2; 4132631Sbostic v++; 4232631Sbostic } 4332631Sbostic v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error"; 4432631Sbostic v->iov_len = strlen(v->iov_base); 4532631Sbostic v++; 4632631Sbostic v->iov_base = "\n"; 4732631Sbostic v->iov_len = 1; 4832631Sbostic writev(2, iov, (v - iov) + 1); 4932631Sbostic } 50