1 /* -*- mode: C; c-basic-offset: 8; indent-tabs-mode: nil; tab-width: 8 -*- */ 2 3 #include "config.h" 4 5 #include <stdio.h> 6 #include <sys/types.h> 7 #include <sys/uio.h> 8 #include <netdb.h> 9 #include <unistd.h> 10 #include <string.h> 11 12 char *h_errlist[] = { 13 "Error 0", 14 "Unknown host", 15 "Host name lookup failure", 16 "Unknown server error", 17 "No address associated with name", 18 }; 19 int h_nerr = 5; 20 21 /* 22 * herror -- 23 * print the error indicated by the h_errno value. 24 */ 25 void herror(s)26herror(s) 27 const char *s; 28 { 29 struct iovec iov[4]; 30 register struct iovec *v = iov; 31 int error = h_errno; 32 33 if (s && *s) { 34 v->iov_base = (char *)s; 35 v->iov_len = strlen(s); 36 v++; 37 v->iov_base = ": "; 38 v->iov_len = 2; 39 v++; 40 } 41 v->iov_base = ((unsigned int)(error) < h_nerr) ? 42 h_errlist[error] : "Unknown error"; 43 v->iov_len = strlen(v->iov_base); 44 v++; 45 v->iov_base = "\n"; 46 v->iov_len = 1; 47 writev(STDERR_FILENO, iov, (v - iov) + 1); 48 } 49 50 char * hstrerror(err)51hstrerror(err) 52 int err; 53 { 54 return ((unsigned int)(err) < h_nerr) ? h_errlist[err] 55 : "Unknown error"; 56 } 57 58 59 60