blob: a1f94ad642deb8b72cf78233fb18523680e85815 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * Copyright (c) 1987 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20#define __FORCE_GLIBC
21#include <features.h>
22#include <stdio.h>
23#include <string.h>
24#include <netdb.h>
25
26
27static const char error_msg[] = "Resolver error";
28static const char *const h_errlist[] = {
29 "Error 0",
30 "Unknown host", /* 1 HOST_NOT_FOUND */
31 "Host name lookup failure", /* 2 TRY_AGAIN */
32 "Unknown server error", /* 3 NO_RECOVERY */
33 "No address associated with name", /* 4 NO_ADDRESS */
34};
35static const int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
36
37/*
38 * herror -- print the error indicated by the h_errno value.
39 */
40void herror(const char *s)
41{
42 static const char colon_space[] = ": ";
43 const char *p;
44 const char *c;
45
46 c = colon_space;
47 if (!s || !*s) {
48 c += 2;
49 }
50 p = error_msg;
51 if ((h_errno >= 0) && (h_errno < h_nerr)) {
52 p = h_errlist[h_errno];
53 }
54 fprintf(stderr, "%s%s%s\n", s, c, p);
55}
56libc_hidden_def(herror)
57
58
59const char *hstrerror(int err)
60{
61 if ((unsigned)err < h_nerr)
62 return(h_errlist[err]);
63
64 return error_msg;
65}