| 1 | /*	$NetBSD: resolve.h,v 1.2 2017/01/28 21:31:50 christos Exp $	*/ | 
| 2 |  | 
| 3 | /* | 
| 4 |  * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan | 
| 5 |  * (Royal Institute of Technology, Stockholm, Sweden). | 
| 6 |  * All rights reserved. | 
| 7 |  * | 
| 8 |  * Redistribution and use in source and binary forms, with or without | 
| 9 |  * modification, are permitted provided that the following conditions | 
| 10 |  * are met: | 
| 11 |  * | 
| 12 |  * 1. Redistributions of source code must retain the above copyright | 
| 13 |  *    notice, this list of conditions and the following disclaimer. | 
| 14 |  * | 
| 15 |  * 2. Redistributions in binary form must reproduce the above copyright | 
| 16 |  *    notice, this list of conditions and the following disclaimer in the | 
| 17 |  *    documentation and/or other materials provided with the distribution. | 
| 18 |  * | 
| 19 |  * 3. Neither the name of the Institute nor the names of its contributors | 
| 20 |  *    may be used to endorse or promote products derived from this software | 
| 21 |  *    without specific prior written permission. | 
| 22 |  * | 
| 23 |  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND | 
| 24 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| 25 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
| 26 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE | 
| 27 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| 28 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
| 29 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
| 30 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
| 31 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 
| 32 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
| 33 |  * SUCH DAMAGE. | 
| 34 |  */ | 
| 35 |  | 
| 36 | /* Id */ | 
| 37 |  | 
| 38 | #ifndef __RESOLVE_H__ | 
| 39 | #define __RESOLVE_H__ | 
| 40 |  | 
| 41 | #ifndef ROKEN_LIB_FUNCTION | 
| 42 | #ifdef _WIN32 | 
| 43 | #define ROKEN_LIB_FUNCTION | 
| 44 | #define ROKEN_LIB_CALL     __cdecl | 
| 45 | #else | 
| 46 | #define ROKEN_LIB_FUNCTION | 
| 47 | #define ROKEN_LIB_CALL | 
| 48 | #endif | 
| 49 | #endif | 
| 50 |  | 
| 51 | enum { | 
| 52 |     rk_ns_c_in = 1 | 
| 53 | }; | 
| 54 |  | 
| 55 | enum { | 
| 56 | 	rk_ns_t_invalid = 0,	/* Cookie. */ | 
| 57 | 	rk_ns_t_a = 1,		/* Host address. */ | 
| 58 | 	rk_ns_t_ns = 2,		/* Authoritative server. */ | 
| 59 | 	rk_ns_t_md = 3,		/* Mail destination. */ | 
| 60 | 	rk_ns_t_mf = 4,		/* Mail forwarder. */ | 
| 61 | 	rk_ns_t_cname = 5,	/* Canonical name. */ | 
| 62 | 	rk_ns_t_soa = 6,	/* Start of authority zone. */ | 
| 63 | 	rk_ns_t_mb = 7,		/* Mailbox domain name. */ | 
| 64 | 	rk_ns_t_mg = 8,		/* Mail group member. */ | 
| 65 | 	rk_ns_t_mr = 9,		/* Mail rename name. */ | 
| 66 | 	rk_ns_t_null = 10,	/* Null resource record. */ | 
| 67 | 	rk_ns_t_wks = 11,	/* Well known service. */ | 
| 68 | 	rk_ns_t_ptr = 12,	/* Domain name pointer. */ | 
| 69 | 	rk_ns_t_hinfo = 13,	/* Host information. */ | 
| 70 | 	rk_ns_t_minfo = 14,	/* Mailbox information. */ | 
| 71 | 	rk_ns_t_mx = 15,	/* Mail routing information. */ | 
| 72 | 	rk_ns_t_txt = 16,	/* Text strings. */ | 
| 73 | 	rk_ns_t_rp = 17,	/* Responsible person. */ | 
| 74 | 	rk_ns_t_afsdb = 18,	/* AFS cell database. */ | 
| 75 | 	rk_ns_t_x25 = 19,	/* X_25 calling address. */ | 
| 76 | 	rk_ns_t_isdn = 20,	/* ISDN calling address. */ | 
| 77 | 	rk_ns_t_rt = 21,	/* Router. */ | 
| 78 | 	rk_ns_t_nsap = 22,	/* NSAP address. */ | 
| 79 | 	rk_ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */ | 
| 80 | 	rk_ns_t_sig = 24,	/* Security signature. */ | 
| 81 | 	rk_ns_t_key = 25,	/* Security key. */ | 
| 82 | 	rk_ns_t_px = 26,	/* X.400 mail mapping. */ | 
| 83 | 	rk_ns_t_gpos = 27,	/* Geographical position (withdrawn). */ | 
| 84 | 	rk_ns_t_aaaa = 28,	/* Ip6 Address. */ | 
| 85 | 	rk_ns_t_loc = 29,	/* Location Information. */ | 
| 86 | 	rk_ns_t_nxt = 30,	/* Next domain (security). */ | 
| 87 | 	rk_ns_t_eid = 31,	/* Endpoint identifier. */ | 
| 88 | 	rk_ns_t_nimloc = 32,	/* Nimrod Locator. */ | 
| 89 | 	rk_ns_t_srv = 33,	/* Server Selection. */ | 
| 90 | 	rk_ns_t_atma = 34,	/* ATM Address */ | 
| 91 | 	rk_ns_t_naptr = 35,	/* Naming Authority PoinTeR */ | 
| 92 | 	rk_ns_t_kx = 36,	/* Key Exchange */ | 
| 93 | 	rk_ns_t_cert = 37,	/* Certification record */ | 
| 94 | 	rk_ns_t_a6 = 38,	/* IPv6 address (deprecates AAAA) */ | 
| 95 | 	rk_ns_t_dname = 39,	/* Non-terminal DNAME (for IPv6) */ | 
| 96 | 	rk_ns_t_sink = 40,	/* Kitchen sink (experimentatl) */ | 
| 97 | 	rk_ns_t_opt = 41,	/* EDNS0 option (meta-RR) */ | 
| 98 | 	rk_ns_t_apl = 42,	/* Address prefix list (RFC 3123) */ | 
| 99 | 	rk_ns_t_ds = 43,	/* Delegation Signer (RFC 3658) */ | 
| 100 | 	rk_ns_t_sshfp = 44,	/* SSH fingerprint */ | 
| 101 | 	rk_ns_t_tkey = 249,	/* Transaction key */ | 
| 102 | 	rk_ns_t_tsig = 250,	/* Transaction signature. */ | 
| 103 | 	rk_ns_t_ixfr = 251,	/* Incremental zone transfer. */ | 
| 104 | 	rk_ns_t_axfr = 252,	/* Transfer zone of authority. */ | 
| 105 | 	rk_ns_t_mailb = 253,	/* Transfer mailbox records. */ | 
| 106 | 	rk_ns_t_maila = 254,	/* Transfer mail agent records. */ | 
| 107 | 	rk_ns_t_any = 255,	/* Wildcard match. */ | 
| 108 | 	rk_ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */ | 
| 109 | 	rk_ns_t_max = 65536 | 
| 110 | }; | 
| 111 |  | 
| 112 | #ifndef MAXDNAME | 
| 113 | #define MAXDNAME	1025 | 
| 114 | #endif | 
| 115 |  | 
| 116 | #define mx_record		rk_mx_record | 
| 117 | #define srv_record		rk_srv_record | 
| 118 | #define key_record		rk_key_record | 
| 119 | #define sig_record		rk_sig_record | 
| 120 | #define cert_record		rk_cert_record | 
| 121 | #define sshfp_record		rk_sshfp_record | 
| 122 |  | 
| 123 | struct rk_dns_query{ | 
| 124 |     char *domain; | 
| 125 |     unsigned type; | 
| 126 |     unsigned class; | 
| 127 | }; | 
| 128 |  | 
| 129 | struct rk_mx_record{ | 
| 130 |     unsigned  preference; | 
| 131 |     char domain[1]; | 
| 132 | }; | 
| 133 |  | 
| 134 | struct rk_srv_record{ | 
| 135 |     unsigned priority; | 
| 136 |     unsigned weight; | 
| 137 |     unsigned port; | 
| 138 |     char target[1]; | 
| 139 | }; | 
| 140 |  | 
| 141 | struct rk_key_record { | 
| 142 |     unsigned flags; | 
| 143 |     unsigned protocol; | 
| 144 |     unsigned algorithm; | 
| 145 |     size_t   key_len; | 
| 146 |     u_char   key_data[1]; | 
| 147 | }; | 
| 148 |  | 
| 149 | struct rk_sig_record { | 
| 150 |     unsigned type; | 
| 151 |     unsigned algorithm; | 
| 152 |     unsigned labels; | 
| 153 |     unsigned orig_ttl; | 
| 154 |     unsigned sig_expiration; | 
| 155 |     unsigned sig_inception; | 
| 156 |     unsigned key_tag; | 
| 157 |     char     *signer; | 
| 158 |     size_t   sig_len; | 
| 159 |     char     sig_data[1];	/* also includes signer */ | 
| 160 | }; | 
| 161 |  | 
| 162 | struct rk_cert_record { | 
| 163 |     unsigned type; | 
| 164 |     unsigned tag; | 
| 165 |     unsigned algorithm; | 
| 166 |     size_t   cert_len; | 
| 167 |     u_char   cert_data[1]; | 
| 168 | }; | 
| 169 |  | 
| 170 | struct rk_sshfp_record { | 
| 171 |     unsigned algorithm; | 
| 172 |     unsigned type; | 
| 173 |     size_t   sshfp_len; | 
| 174 |     u_char   sshfp_data[1]; | 
| 175 | }; | 
| 176 |  | 
| 177 | struct rk_ds_record { | 
| 178 |     unsigned key_tag; | 
| 179 |     unsigned algorithm; | 
| 180 |     unsigned digest_type; | 
| 181 |     size_t digest_len; | 
| 182 |     u_char digest_data[1]; | 
| 183 | }; | 
| 184 |  | 
| 185 | struct rk_resource_record{ | 
| 186 |     char *domain; | 
| 187 |     unsigned type; | 
| 188 |     unsigned class; | 
| 189 |     unsigned ttl; | 
| 190 |     unsigned size; | 
| 191 |     union { | 
| 192 | 	void *data; | 
| 193 | 	struct rk_mx_record *mx; | 
| 194 | 	struct rk_mx_record *afsdb; /* mx and afsdb are identical */ | 
| 195 | 	struct rk_srv_record *srv; | 
| 196 | 	struct in_addr *a; | 
| 197 | 	char *txt; | 
| 198 | 	struct rk_key_record *key; | 
| 199 | 	struct rk_cert_record *cert; | 
| 200 | 	struct rk_sig_record *sig; | 
| 201 | 	struct rk_sshfp_record *sshfp; | 
| 202 | 	struct rk_ds_record *ds; | 
| 203 |     }u; | 
| 204 |     struct rk_resource_record *next; | 
| 205 | }; | 
| 206 |  | 
| 207 | #define rk_DNS_MAX_PACKET_SIZE		0xffff | 
| 208 |  | 
| 209 | struct  { | 
| 210 |     unsigned ; | 
| 211 |     unsigned ; | 
| 212 | #define 		1 | 
| 213 | #define 	2 | 
| 214 | #define 		4 | 
| 215 | #define 		8 | 
| 216 | #define 	16 | 
| 217 | #define 		32 | 
| 218 | #define 		64 | 
| 219 |     unsigned ; | 
| 220 |     unsigned ; | 
| 221 |     unsigned ; | 
| 222 |     unsigned ; | 
| 223 |     unsigned ; | 
| 224 |     unsigned ; | 
| 225 | }; | 
| 226 |  | 
| 227 | struct rk_dns_reply{ | 
| 228 |     struct rk_dns_header h; | 
| 229 |     struct rk_dns_query q; | 
| 230 |     struct rk_resource_record *head; | 
| 231 | }; | 
| 232 |  | 
| 233 |  | 
| 234 | #ifdef __cplusplus | 
| 235 | extern "C"  { | 
| 236 | #endif | 
| 237 |  | 
| 238 | ROKEN_LIB_FUNCTION struct rk_dns_reply* ROKEN_LIB_CALL | 
| 239 | 	rk_dns_lookup(const char *, const char *); | 
| 240 | ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL | 
| 241 | 	rk_dns_free_data(struct rk_dns_reply *); | 
| 242 | ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL | 
| 243 | 	rk_dns_string_to_type(const char *name); | 
| 244 | ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL | 
| 245 | 	rk_dns_type_to_string(int type); | 
| 246 | ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL | 
| 247 | 	rk_dns_srv_order(struct rk_dns_reply*); | 
| 248 |  | 
| 249 | #ifdef __cplusplus | 
| 250 | } | 
| 251 | #endif | 
| 252 |  | 
| 253 | #endif /* __RESOLVE_H__ */ | 
| 254 |  |