3 #ifndef _DNS_H_INCLUDED_
4 #define _DNS_H_INCLUDED_
10 /* domain name service lookup
19 #include <netinet/in.h>
20 #include <arpa/nameser.h>
21 #ifdef RESOLVE_H_NEEDS_STDIO_H
24 #ifdef RESOLVE_H_NEEDS_NAMESER8_COMPAT_H
25 #include <nameser8_compat.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.
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]) \
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]) \
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 */
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 */
99 extern const char *dns_strerror(unsigned);
104 extern const char *dns_strtype(unsigned);
105 extern unsigned dns_type(const char *);
110 extern DNS_RR
*dns_rr_create(const char *, const char *,
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
*);
125 extern const char *dns_rr_to_pa(DNS_RR
*, MAI_HOSTADDR_STR
*);
130 extern DNS_RR
*dns_sa_to_rr(const char *, unsigned, struct sockaddr
*);
135 extern int dns_rr_to_sa(DNS_RR
*, unsigned, struct sockaddr
*, SOCKADDR_SIZE
*);
140 extern int dns_rr_eq_sa(DNS_RR
*, struct sockaddr
*);
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))
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)
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
*,
162 extern int dns_lookup_v(const char *, unsigned, DNS_RR
**, VSTRING
*,
163 VSTRING
*, int, unsigned *);
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
191 /* The Secure Mailer license must be distributed with this software.
194 /* IBM T.J. Watson Research
196 /* Yorktown Heights, NY 10598, USA