Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / dns / dns_strerror.c
blobf95255e4f4ebf982b4d0e0881bac5736ff4cc731
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* dns_strerror 3
6 /* SUMMARY
7 /* name service lookup error code to string
8 /* SYNOPSIS
9 /* #include <dhs.h>
11 /* const char *dns_strerror(code)
12 /* int code;
13 /* DESCRIPTION
14 /* dns_strerror() maps a name service lookup error to printable string.
15 /* The result is for read-only purposes, and unknown codes share a
16 /* common string buffer.
17 /* LICENSE
18 /* .ad
19 /* .fi
20 /* The Secure Mailer license must be distributed with this software.
21 /* AUTHOR(S)
22 /* Wietse Venema
23 /* IBM T.J. Watson Research
24 /* P.O. Box 704
25 /* Yorktown Heights, NY 10598, USA
26 /*--*/
28 /* System library. */
30 #include <sys_defs.h>
31 #include <netdb.h>
33 /* Utility library. */
35 #include <vstring.h>
37 /* DNS library. */
39 #include "dns.h"
42 * Mapping from error code to printable string. The herror() routine does
43 * something similar, but has output only to the stderr stream.
45 struct dns_error_map {
46 unsigned error;
47 const char *text;
50 static struct dns_error_map dns_error_map[] = {
51 HOST_NOT_FOUND, "Host not found",
52 TRY_AGAIN, "Host not found, try again",
53 NO_RECOVERY, "Non-recoverable error",
54 NO_DATA, "Host found but no data record of requested type",
57 /* dns_strerror - map resolver error code to printable string */
59 const char *dns_strerror(unsigned error)
61 static VSTRING *unknown = 0;
62 unsigned i;
64 for (i = 0; i < sizeof(dns_error_map) / sizeof(dns_error_map[0]); i++)
65 if (dns_error_map[i].error == error)
66 return (dns_error_map[i].text);
67 if (unknown == 0)
68 unknown = vstring_alloc(sizeof("Unknown error XXXXXX"));
69 vstring_sprintf(unknown, "Unknown error %u", error);
70 return (vstring_str(unknown));