~ubuntu-branches/ubuntu/dapper/postfix/dapper-security

« back to all changes in this revision

Viewing changes to src/dns/dns_strerror.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

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