Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / dns / dns.h
blob206208e7a80b2d694876d221bfb52bfc0f6445cb
1 /* $NetBSD$ */
3 #ifndef _DNS_H_INCLUDED_
4 #define _DNS_H_INCLUDED_
6 /*++
7 /* NAME
8 /* dns 3h
9 /* SUMMARY
10 /* domain name service lookup
11 /* SYNOPSIS
12 /* #include <dns.h>
13 /* DESCRIPTION
14 /* .nf
17 * System library.
19 #include <netinet/in.h>
20 #include <arpa/nameser.h>
21 #ifdef RESOLVE_H_NEEDS_STDIO_H
22 #include <stdio.h>
23 #endif
24 #ifdef RESOLVE_H_NEEDS_NAMESER8_COMPAT_H
25 #include <nameser8_compat.h>
26 #endif
27 #include <resolv.h>
30 * Name server compatibility. These undocumented macros appear in the file
31 * <arpa/nameser.h>, but since they are undocumented we should not count on
32 * their presence, and so they are included here just in case.
34 #ifndef GETSHORT
36 #define GETSHORT(s, cp) { \
37 unsigned char *t_cp = (u_char *)(cp); \
38 (s) = ((unsigned)t_cp[0] << 8) \
39 | ((unsigned)t_cp[1]) \
40 ; \
41 (cp) += 2; \
44 #define GETLONG(l, cp) { \
45 unsigned char *t_cp = (u_char *)(cp); \
46 (l) = ((unsigned)t_cp[0] << 24) \
47 | ((unsigned)t_cp[1] << 16) \
48 | ((unsigned)t_cp[2] << 8) \
49 | ((unsigned)t_cp[3]) \
50 ; \
51 (cp) += 4; \
54 #endif
57 * SunOS 4 needs this.
59 #ifndef T_TXT
60 #define T_TXT 16
61 #endif
64 * Utility library.
66 #include <vstring.h>
67 #include <sock_addr.h>
68 #include <myaddrinfo.h>
71 * Structure for fixed resource record data.
73 typedef struct DNS_FIXED {
74 unsigned short type; /* T_A, T_CNAME, etc. */
75 unsigned short class; /* C_IN, etc. */
76 unsigned int ttl; /* always */
77 unsigned length; /* record length */
78 } DNS_FIXED;
81 * Structure of a DNS resource record after expansion. The components are
82 * named after the things one can expect to find in a DNS resource record.
84 typedef struct DNS_RR {
85 char *qname; /* query name, mystrdup()ed */
86 char *rname; /* reply name, mystrdup()ed */
87 unsigned short type; /* T_A, T_CNAME, etc. */
88 unsigned short class; /* C_IN, etc. */
89 unsigned int ttl; /* always */
90 unsigned short pref; /* T_MX only */
91 struct DNS_RR *next; /* linkage */
92 size_t data_len; /* actual data size */
93 char data[1]; /* actually a bunch of data */
94 } DNS_RR;
97 * dns_strerror.c
99 extern const char *dns_strerror(unsigned);
102 * dns_strtype.c
104 extern const char *dns_strtype(unsigned);
105 extern unsigned dns_type(const char *);
108 * dns_rr.c
110 extern DNS_RR *dns_rr_create(const char *, const char *,
111 ushort, ushort,
112 unsigned, unsigned,
113 const char *, size_t);
114 extern void dns_rr_free(DNS_RR *);
115 extern DNS_RR *dns_rr_copy(DNS_RR *);
116 extern DNS_RR *dns_rr_append(DNS_RR *, DNS_RR *);
117 extern DNS_RR *dns_rr_sort(DNS_RR *, int (*) (DNS_RR *, DNS_RR *));
118 extern int dns_rr_compare_pref(DNS_RR *, DNS_RR *);
119 extern DNS_RR *dns_rr_shuffle(DNS_RR *);
120 extern DNS_RR *dns_rr_remove(DNS_RR *, DNS_RR *);
123 * dns_rr_to_pa.c
125 extern const char *dns_rr_to_pa(DNS_RR *, MAI_HOSTADDR_STR *);
128 * dns_sa_to_rr.c
130 extern DNS_RR *dns_sa_to_rr(const char *, unsigned, struct sockaddr *);
133 * dns_rr_to_sa.c
135 extern int dns_rr_to_sa(DNS_RR *, unsigned, struct sockaddr *, SOCKADDR_SIZE *);
138 * dns_rr_eq_sa.c
140 extern int dns_rr_eq_sa(DNS_RR *, struct sockaddr *);
142 #ifdef HAS_IPV6
143 #define DNS_RR_EQ_SA(rr, sa) \
144 ((SOCK_ADDR_IN_FAMILY(sa) == AF_INET && (rr)->type == T_A \
145 && SOCK_ADDR_IN_ADDR(sa).s_addr == IN_ADDR((rr)->data).s_addr) \
146 || (SOCK_ADDR_IN_FAMILY(sa) == AF_INET6 && (rr)->type == T_AAAA \
147 && memcmp((char *) &(SOCK_ADDR_IN6_ADDR(sa)), \
148 (rr)->data, (rr)->data_len) == 0))
149 #else
150 #define DNS_RR_EQ_SA(rr, sa) \
151 (SOCK_ADDR_IN_FAMILY(sa) == AF_INET && (rr)->type == T_A \
152 && SOCK_ADDR_IN_ADDR(sa).s_addr == IN_ADDR((rr)->data).s_addr)
153 #endif
156 * dns_lookup.c
158 extern int dns_lookup(const char *, unsigned, unsigned, DNS_RR **,
159 VSTRING *, VSTRING *);
160 extern int dns_lookup_l(const char *, unsigned, DNS_RR **, VSTRING *,
161 VSTRING *, int,...);
162 extern int dns_lookup_v(const char *, unsigned, DNS_RR **, VSTRING *,
163 VSTRING *, int, unsigned *);
166 * Request flags.
168 #define DNS_REQ_FLAG_STOP_OK (1<<0)
169 #define DNS_REQ_FLAG_STOP_INVAL (1<<1)
170 #define DNS_REQ_FLAG_NONE (0)
173 * Status codes. Failures must have negative codes so they will not collide
174 * with valid counts of answer records etc.
176 #define DNS_INVAL (-5) /* query ok, malformed reply */
177 #define DNS_FAIL (-4) /* query failed, don't retry */
178 #define DNS_NOTFOUND (-3) /* query ok, data not found */
179 #define DNS_RETRY (-2) /* query failed, try again */
180 #define DNS_RECURSE (-1) /* recursion needed */
181 #define DNS_OK 0 /* query succeeded */
184 * How long can a DNS name or single text value be?
186 #define DNS_NAME_LEN 1024
188 /* LICENSE
189 /* .ad
190 /* .fi
191 /* The Secure Mailer license must be distributed with this software.
192 /* AUTHOR(S)
193 /* Wietse Venema
194 /* IBM T.J. Watson Research
195 /* P.O. Box 704
196 /* Yorktown Heights, NY 10598, USA
197 /*--*/
199 #endif