14ecbd6dmarkm/*
233f661cstas * Copyright (c) 1995 - 2002 Kungliga Tekniska H��gskolan
34ecbd6dmarkm * (Royal Institute of Technology, Stockholm, Sweden).
44ecbd6dmarkm * All rights reserved.
533f661cstas *
64ecbd6dmarkm * Redistribution and use in source and binary forms, with or without
74ecbd6dmarkm * modification, are permitted provided that the following conditions
84ecbd6dmarkm * are met:
933f661cstas *
104ecbd6dmarkm * 1. Redistributions of source code must retain the above copyright
114ecbd6dmarkm *    notice, this list of conditions and the following disclaimer.
1233f661cstas *
134ecbd6dmarkm * 2. Redistributions in binary form must reproduce the above copyright
144ecbd6dmarkm *    notice, this list of conditions and the following disclaimer in the
154ecbd6dmarkm *    documentation and/or other materials provided with the distribution.
1633f661cstas *
174ecbd6dmarkm * 3. Neither the name of the Institute nor the names of its contributors
184ecbd6dmarkm *    may be used to endorse or promote products derived from this software
194ecbd6dmarkm *    without specific prior written permission.
2033f661cstas *
214ecbd6dmarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
224ecbd6dmarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
234ecbd6dmarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
244ecbd6dmarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
254ecbd6dmarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
264ecbd6dmarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
274ecbd6dmarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
284ecbd6dmarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
294ecbd6dmarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
304ecbd6dmarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
314ecbd6dmarkm * SUCH DAMAGE.
324ecbd6dmarkm */
334ecbd6dmarkm
3433f661cstas/* $Id$ */
354ecbd6dmarkm
364ecbd6dmarkm#ifndef __RESOLVE_H__
374ecbd6dmarkm#define __RESOLVE_H__
384ecbd6dmarkm
3951b6601dfr#ifndef ROKEN_LIB_FUNCTION
4051b6601dfr#ifdef _WIN32
4133f661cstas#define ROKEN_LIB_FUNCTION
4233f661cstas#define ROKEN_LIB_CALL     __cdecl
4351b6601dfr#else
4451b6601dfr#define ROKEN_LIB_FUNCTION
4533f661cstas#define ROKEN_LIB_CALL
4651b6601dfr#endif
4751b6601dfr#endif
4851b6601dfr
4933f661cstasenum {
5033f661cstas    rk_ns_c_in = 1
5133f661cstas};
5233f661cstas
5333f661cstasenum {
5451b6601dfr	rk_ns_t_invalid = 0,	/* Cookie. */
5551b6601dfr	rk_ns_t_a = 1,		/* Host address. */
5651b6601dfr	rk_ns_t_ns = 2,		/* Authoritative server. */
5751b6601dfr	rk_ns_t_md = 3,		/* Mail destination. */
5851b6601dfr	rk_ns_t_mf = 4,		/* Mail forwarder. */
5951b6601dfr	rk_ns_t_cname = 5,	/* Canonical name. */
6051b6601dfr	rk_ns_t_soa = 6,	/* Start of authority zone. */
6151b6601dfr	rk_ns_t_mb = 7,		/* Mailbox domain name. */
6251b6601dfr	rk_ns_t_mg = 8,		/* Mail group member. */
6351b6601dfr	rk_ns_t_mr = 9,		/* Mail rename name. */
6451b6601dfr	rk_ns_t_null = 10,	/* Null resource record. */
6551b6601dfr	rk_ns_t_wks = 11,	/* Well known service. */
6651b6601dfr	rk_ns_t_ptr = 12,	/* Domain name pointer. */
6751b6601dfr	rk_ns_t_hinfo = 13,	/* Host information. */
6851b6601dfr	rk_ns_t_minfo = 14,	/* Mailbox information. */
6951b6601dfr	rk_ns_t_mx = 15,	/* Mail routing information. */
7051b6601dfr	rk_ns_t_txt = 16,	/* Text strings. */
7151b6601dfr	rk_ns_t_rp = 17,	/* Responsible person. */
7251b6601dfr	rk_ns_t_afsdb = 18,	/* AFS cell database. */
7351b6601dfr	rk_ns_t_x25 = 19,	/* X_25 calling address. */
7451b6601dfr	rk_ns_t_isdn = 20,	/* ISDN calling address. */
7551b6601dfr	rk_ns_t_rt = 21,	/* Router. */
7651b6601dfr	rk_ns_t_nsap = 22,	/* NSAP address. */
7751b6601dfr	rk_ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
7851b6601dfr	rk_ns_t_sig = 24,	/* Security signature. */
7951b6601dfr	rk_ns_t_key = 25,	/* Security key. */
8051b6601dfr	rk_ns_t_px = 26,	/* X.400 mail mapping. */
8151b6601dfr	rk_ns_t_gpos = 27,	/* Geographical position (withdrawn). */
8251b6601dfr	rk_ns_t_aaaa = 28,	/* Ip6 Address. */
8351b6601dfr	rk_ns_t_loc = 29,	/* Location Information. */
8451b6601dfr	rk_ns_t_nxt = 30,	/* Next domain (security). */
8551b6601dfr	rk_ns_t_eid = 31,	/* Endpoint identifier. */
8651b6601dfr	rk_ns_t_nimloc = 32,	/* Nimrod Locator. */
8751b6601dfr	rk_ns_t_srv = 33,	/* Server Selection. */
8851b6601dfr	rk_ns_t_atma = 34,	/* ATM Address */
8951b6601dfr	rk_ns_t_naptr = 35,	/* Naming Authority PoinTeR */
9051b6601dfr	rk_ns_t_kx = 36,	/* Key Exchange */
9151b6601dfr	rk_ns_t_cert = 37,	/* Certification record */
9251b6601dfr	rk_ns_t_a6 = 38,	/* IPv6 address (deprecates AAAA) */
9351b6601dfr	rk_ns_t_dname = 39,	/* Non-terminal DNAME (for IPv6) */
9451b6601dfr	rk_ns_t_sink = 40,	/* Kitchen sink (experimentatl) */
9551b6601dfr	rk_ns_t_opt = 41,	/* EDNS0 option (meta-RR) */
9651b6601dfr	rk_ns_t_apl = 42,	/* Address prefix list (RFC 3123) */
9751b6601dfr	rk_ns_t_ds = 43,	/* Delegation Signer (RFC 3658) */
9851b6601dfr	rk_ns_t_sshfp = 44,	/* SSH fingerprint */
9951b6601dfr	rk_ns_t_tkey = 249,	/* Transaction key */
10051b6601dfr	rk_ns_t_tsig = 250,	/* Transaction signature. */
10151b6601dfr	rk_ns_t_ixfr = 251,	/* Incremental zone transfer. */
10251b6601dfr	rk_ns_t_axfr = 252,	/* Transfer zone of authority. */
10351b6601dfr	rk_ns_t_mailb = 253,	/* Transfer mailbox records. */
10451b6601dfr	rk_ns_t_maila = 254,	/* Transfer mail agent records. */
10551b6601dfr	rk_ns_t_any = 255,	/* Wildcard match. */
10651b6601dfr	rk_ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
10751b6601dfr	rk_ns_t_max = 65536
10833f661cstas};
10951b6601dfr
11051b6601dfr#ifndef MAXDNAME
11151b6601dfr#define MAXDNAME	1025
11251b6601dfr#endif
1134ecbd6dmarkm
114a77dba0nectar#define mx_record		rk_mx_record
115a77dba0nectar#define srv_record		rk_srv_record
116a77dba0nectar#define key_record		rk_key_record
117a77dba0nectar#define sig_record		rk_sig_record
118a77dba0nectar#define cert_record		rk_cert_record
11951b6601dfr#define sshfp_record		rk_sshfp_record
120a77dba0nectar
12133f661cstasstruct rk_dns_query{
1224ecbd6dmarkm    char *domain;
1234ecbd6dmarkm    unsigned type;
1244ecbd6dmarkm    unsigned class;
1254ecbd6dmarkm};
1264ecbd6dmarkm
12733f661cstasstruct rk_mx_record{
1284ecbd6dmarkm    unsigned  preference;
1294ecbd6dmarkm    char domain[1];
1304ecbd6dmarkm};
1314ecbd6dmarkm
13233f661cstasstruct rk_srv_record{
1334ecbd6dmarkm    unsigned priority;
1344ecbd6dmarkm    unsigned weight;
1354ecbd6dmarkm    unsigned port;
1364ecbd6dmarkm    char target[1];
1374ecbd6dmarkm};
1384ecbd6dmarkm
13933f661cstasstruct rk_key_record {
140ebfe6dcassar    unsigned flags;
141ebfe6dcassar    unsigned protocol;
142ebfe6dcassar    unsigned algorithm;
143ebfe6dcassar    size_t   key_len;
144ebfe6dcassar    u_char   key_data[1];
145ebfe6dcassar};
146ebfe6dcassar
14733f661cstasstruct rk_sig_record {
148ebfe6dcassar    unsigned type;
149ebfe6dcassar    unsigned algorithm;
150ebfe6dcassar    unsigned labels;
151ebfe6dcassar    unsigned orig_ttl;
152ebfe6dcassar    unsigned sig_expiration;
153ebfe6dcassar    unsigned sig_inception;
154ebfe6dcassar    unsigned key_tag;
155ebfe6dcassar    char     *signer;
15633f661cstas    size_t   sig_len;
157ebfe6dcassar    char     sig_data[1];	/* also includes signer */
158ebfe6dcassar};
159ebfe6dcassar
16033f661cstasstruct rk_cert_record {
161ebfe6dcassar    unsigned type;
162ebfe6dcassar    unsigned tag;
163ebfe6dcassar    unsigned algorithm;
164ebfe6dcassar    size_t   cert_len;
165ebfe6dcassar    u_char   cert_data[1];
166ebfe6dcassar};
167ebfe6dcassar
16833f661cstasstruct rk_sshfp_record {
16951b6601dfr    unsigned algorithm;
17051b6601dfr    unsigned type;
17151b6601dfr    size_t   sshfp_len;
17251b6601dfr    u_char   sshfp_data[1];
17351b6601dfr};
17451b6601dfr
17533f661cstasstruct rk_ds_record {
17651b6601dfr    unsigned key_tag;
17751b6601dfr    unsigned algorithm;
17851b6601dfr    unsigned digest_type;
17933f661cstas    size_t digest_len;
18051b6601dfr    u_char digest_data[1];
18151b6601dfr};
18251b6601dfr
18333f661cstasstruct rk_resource_record{
1844ecbd6dmarkm    char *domain;
1854ecbd6dmarkm    unsigned type;
1864ecbd6dmarkm    unsigned class;
1874ecbd6dmarkm    unsigned ttl;
1884ecbd6dmarkm    unsigned size;
1894ecbd6dmarkm    union {
1904ecbd6dmarkm	void *data;
19133f661cstas	struct rk_mx_record *mx;
19233f661cstas	struct rk_mx_record *afsdb; /* mx and afsdb are identical */
19333f661cstas	struct rk_srv_record *srv;
1944ecbd6dmarkm	struct in_addr *a;
1954ecbd6dmarkm	char *txt;
19633f661cstas	struct rk_key_record *key;
19733f661cstas	struct rk_cert_record *cert;
19833f661cstas	struct rk_sig_record *sig;
19933f661cstas	struct rk_sshfp_record *sshfp;
20033f661cstas	struct rk_ds_record *ds;
2014ecbd6dmarkm    }u;
20233f661cstas    struct rk_resource_record *next;
2034ecbd6dmarkm};
2044ecbd6dmarkm
20551b6601dfr#define rk_DNS_MAX_PACKET_SIZE		0xffff
20651b6601dfr
20733f661cstasstruct rk_dns_header {
20851b6601dfr    unsigned id;
20951b6601dfr    unsigned flags;
21051b6601dfr#define rk_DNS_HEADER_RESPONSE_FLAG		1
21151b6601dfr#define rk_DNS_HEADER_AUTHORITIVE_ANSWER	2
21251b6601dfr#define rk_DNS_HEADER_TRUNCATED_MESSAGE		4
21351b6601dfr#define rk_DNS_HEADER_RECURSION_DESIRED		8
21451b6601dfr#define rk_DNS_HEADER_RECURSION_AVAILABLE	16
21551b6601dfr#define rk_DNS_HEADER_AUTHENTIC_DATA		32
21651b6601dfr#define rk_DNS_HEADER_CHECKING_DISABLED		64
21751b6601dfr    unsigned opcode;
21851b6601dfr    unsigned response_code;
21951b6601dfr    unsigned qdcount;
22051b6601dfr    unsigned ancount;
22151b6601dfr    unsigned nscount;
22251b6601dfr    unsigned arcount;
22351b6601dfr};
2244ecbd6dmarkm
22533f661cstasstruct rk_dns_reply{
22633f661cstas    struct rk_dns_header h;
22733f661cstas    struct rk_dns_query q;
22833f661cstas    struct rk_resource_record *head;
2294ecbd6dmarkm};
2304ecbd6dmarkm
2314ecbd6dmarkm
23233f661cstas#ifdef __cplusplus
23333f661cstasextern "C" {
23433f661cstas#endif
23533f661cstas
23633f661cstasROKEN_LIB_FUNCTION struct rk_dns_reply* ROKEN_LIB_CALL
23733f661cstas	rk_dns_lookup(const char *, const char *);
23833f661cstasROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
23933f661cstas	rk_dns_free_data(struct rk_dns_reply *);
24033f661cstasROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
24133f661cstas	rk_dns_string_to_type(const char *name);
24233f661cstasROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
24333f661cstas	rk_dns_type_to_string(int type);
24433f661cstasROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
24533f661cstas	rk_dns_srv_order(struct rk_dns_reply*);
24633f661cstas
24733f661cstas#ifdef __cplusplus
24833f661cstas}
24933f661cstas#endif
2504ecbd6dmarkm
2514ecbd6dmarkm#endif /* __RESOLVE_H__ */
252