1*32631Sbostic /* 2*32631Sbostic * Copyright (c) 1987 Regents of the University of California. 3*32631Sbostic * All rights reserved. The Berkeley software License Agreement 4*32631Sbostic * specifies the terms and conditions for redistribution. 5*32631Sbostic */ 6*32631Sbostic 7*32631Sbostic #ifndef lint 8*32631Sbostic char copyright[] = 9*32631Sbostic "@(#) Copyright (c) 1987 Regents of the University of California.\n\ 10*32631Sbostic All rights reserved.\n"; 11*32631Sbostic #endif /* !lint */ 12*32631Sbostic 13*32631Sbostic #ifndef lint 14*32631Sbostic static char sccsid[] = "@(#)herror.c 1.1 (Berkeley) 11/17/87"; 15*32631Sbostic #endif /* !lint */ 16*32631Sbostic 17*32631Sbostic #include <sys/types.h> 18*32631Sbostic #include <sys/uio.h> 19*32631Sbostic 20*32631Sbostic char *h_errlist[] = { 21*32631Sbostic "Error 0", 22*32631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 23*32631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 24*32631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 25*32631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 26*32631Sbostic }; 27*32631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 28*32631Sbostic 29*32631Sbostic extern int h_errno; 30*32631Sbostic 31*32631Sbostic /* 32*32631Sbostic * herror -- 33*32631Sbostic * print the error indicated by the h_errno value. 34*32631Sbostic */ 35*32631Sbostic herror(s) 36*32631Sbostic char *s; 37*32631Sbostic { 38*32631Sbostic struct iovec iov[4]; 39*32631Sbostic register struct iovec *v = iov; 40*32631Sbostic 41*32631Sbostic if (s && *s) { 42*32631Sbostic v->iov_base = s; 43*32631Sbostic v->iov_len = strlen(s); 44*32631Sbostic v++; 45*32631Sbostic v->iov_base = ": "; 46*32631Sbostic v->iov_len = 2; 47*32631Sbostic v++; 48*32631Sbostic } 49*32631Sbostic v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error"; 50*32631Sbostic v->iov_len = strlen(v->iov_base); 51*32631Sbostic v++; 52*32631Sbostic v->iov_base = "\n"; 53*32631Sbostic v->iov_len = 1; 54*32631Sbostic writev(2, iov, (v - iov) + 1); 55*32631Sbostic } 56