132631Sbostic /* 232631Sbostic * Copyright (c) 1987 Regents of the University of California. 3*33679Sbostic * All rights reserved. 4*33679Sbostic * 5*33679Sbostic * Redistribution and use in source and binary forms are permitted 6*33679Sbostic * provided that this notice is preserved and that due credit is given 7*33679Sbostic * to the University of California at Berkeley. The name of the University 8*33679Sbostic * may not be used to endorse or promote products derived from this 9*33679Sbostic * software without specific prior written permission. This software 10*33679Sbostic * is provided ``as is'' without express or implied warranty. 1132631Sbostic */ 1232631Sbostic 1332755Skarels #if defined(LIBC_SCCS) && !defined(lint) 14*33679Sbostic static char sccsid[] = "@(#)herror.c 6.2 (Berkeley) 03/07/88"; 15*33679Sbostic #endif /* LIBC_SCCS and not lint */ 1632631Sbostic 1732631Sbostic #include <sys/types.h> 1832631Sbostic #include <sys/uio.h> 1932631Sbostic 2032631Sbostic char *h_errlist[] = { 2132631Sbostic "Error 0", 2232631Sbostic "Unknown host", /* 1 HOST_NOT_FOUND */ 2332631Sbostic "Host name lookup failure", /* 2 TRY_AGAIN */ 2432631Sbostic "Unknown server error", /* 3 NO_RECOVERY */ 2532631Sbostic "No address associated with name", /* 4 NO_ADDRESS */ 2632631Sbostic }; 2732631Sbostic int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 2832631Sbostic 2932631Sbostic extern int h_errno; 3032631Sbostic 3132631Sbostic /* 3232631Sbostic * herror -- 3332631Sbostic * print the error indicated by the h_errno value. 3432631Sbostic */ 3532631Sbostic herror(s) 3632631Sbostic char *s; 3732631Sbostic { 3832631Sbostic struct iovec iov[4]; 3932631Sbostic register struct iovec *v = iov; 4032631Sbostic 4132631Sbostic if (s && *s) { 4232631Sbostic v->iov_base = s; 4332631Sbostic v->iov_len = strlen(s); 4432631Sbostic v++; 4532631Sbostic v->iov_base = ": "; 4632631Sbostic v->iov_len = 2; 4732631Sbostic v++; 4832631Sbostic } 4932631Sbostic v->iov_base = h_errno < h_nerr ? 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; 5432631Sbostic writev(2, iov, (v - iov) + 1); 5532631Sbostic } 56