1195972f6Sopenharmony_ci/**
2195972f6Sopenharmony_ci * @file
3195972f6Sopenharmony_ci * DNS - host name to IP address resolver.
4195972f6Sopenharmony_ci */
5195972f6Sopenharmony_ci
6195972f6Sopenharmony_ci/*
7195972f6Sopenharmony_ci * Port to lwIP from uIP
8195972f6Sopenharmony_ci * by Jim Pettinato April 2007
9195972f6Sopenharmony_ci *
10195972f6Sopenharmony_ci * security fixes and more by Simon Goldschmidt
11195972f6Sopenharmony_ci *
12195972f6Sopenharmony_ci * uIP version Copyright (c) 2002-2003, Adam Dunkels.
13195972f6Sopenharmony_ci * All rights reserved.
14195972f6Sopenharmony_ci *
15195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
16195972f6Sopenharmony_ci * modification, are permitted provided that the following conditions
17195972f6Sopenharmony_ci * are met:
18195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
19195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
20195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
21195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
22195972f6Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
23195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote
24195972f6Sopenharmony_ci *    products derived from this software without specific prior
25195972f6Sopenharmony_ci *    written permission.
26195972f6Sopenharmony_ci *
27195972f6Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
28195972f6Sopenharmony_ci * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29195972f6Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30195972f6Sopenharmony_ci * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
31195972f6Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32195972f6Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33195972f6Sopenharmony_ci * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34195972f6Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35195972f6Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36195972f6Sopenharmony_ci * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37195972f6Sopenharmony_ci * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38195972f6Sopenharmony_ci */
39195972f6Sopenharmony_ci
40195972f6Sopenharmony_ci#ifndef LWIP_HDR_PROT_DNS_H
41195972f6Sopenharmony_ci#define LWIP_HDR_PROT_DNS_H
42195972f6Sopenharmony_ci
43195972f6Sopenharmony_ci#include "lwip/arch.h"
44195972f6Sopenharmony_ci
45195972f6Sopenharmony_ci#ifdef __cplusplus
46195972f6Sopenharmony_ciextern "C" {
47195972f6Sopenharmony_ci#endif
48195972f6Sopenharmony_ci
49195972f6Sopenharmony_ci/** DNS server port address */
50195972f6Sopenharmony_ci#ifndef DNS_SERVER_PORT
51195972f6Sopenharmony_ci#define DNS_SERVER_PORT           53
52195972f6Sopenharmony_ci#endif
53195972f6Sopenharmony_ci
54195972f6Sopenharmony_ci/* DNS field TYPE used for "Resource Records" */
55195972f6Sopenharmony_ci#define DNS_RRTYPE_A              1     /* a host address */
56195972f6Sopenharmony_ci#define DNS_RRTYPE_NS             2     /* an authoritative name server */
57195972f6Sopenharmony_ci#define DNS_RRTYPE_MD             3     /* a mail destination (Obsolete - use MX) */
58195972f6Sopenharmony_ci#define DNS_RRTYPE_MF             4     /* a mail forwarder (Obsolete - use MX) */
59195972f6Sopenharmony_ci#define DNS_RRTYPE_CNAME          5     /* the canonical name for an alias */
60195972f6Sopenharmony_ci#define DNS_RRTYPE_SOA            6     /* marks the start of a zone of authority */
61195972f6Sopenharmony_ci#define DNS_RRTYPE_MB             7     /* a mailbox domain name (EXPERIMENTAL) */
62195972f6Sopenharmony_ci#define DNS_RRTYPE_MG             8     /* a mail group member (EXPERIMENTAL) */
63195972f6Sopenharmony_ci#define DNS_RRTYPE_MR             9     /* a mail rename domain name (EXPERIMENTAL) */
64195972f6Sopenharmony_ci#define DNS_RRTYPE_NULL           10    /* a null RR (EXPERIMENTAL) */
65195972f6Sopenharmony_ci#define DNS_RRTYPE_WKS            11    /* a well known service description */
66195972f6Sopenharmony_ci#define DNS_RRTYPE_PTR            12    /* a domain name pointer */
67195972f6Sopenharmony_ci#define DNS_RRTYPE_HINFO          13    /* host information */
68195972f6Sopenharmony_ci#define DNS_RRTYPE_MINFO          14    /* mailbox or mail list information */
69195972f6Sopenharmony_ci#define DNS_RRTYPE_MX             15    /* mail exchange */
70195972f6Sopenharmony_ci#define DNS_RRTYPE_TXT            16    /* text strings */
71195972f6Sopenharmony_ci#define DNS_RRTYPE_AAAA           28    /* IPv6 address */
72195972f6Sopenharmony_ci#define DNS_RRTYPE_SRV            33    /* service location */
73195972f6Sopenharmony_ci#define DNS_RRTYPE_ANY            255   /* any type */
74195972f6Sopenharmony_ci
75195972f6Sopenharmony_ci/* DNS field CLASS used for "Resource Records" */
76195972f6Sopenharmony_ci#define DNS_RRCLASS_IN            1     /* the Internet */
77195972f6Sopenharmony_ci#define DNS_RRCLASS_CS            2     /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */
78195972f6Sopenharmony_ci#define DNS_RRCLASS_CH            3     /* the CHAOS class */
79195972f6Sopenharmony_ci#define DNS_RRCLASS_HS            4     /* Hesiod [Dyer 87] */
80195972f6Sopenharmony_ci#define DNS_RRCLASS_ANY           255   /* any class */
81195972f6Sopenharmony_ci#define DNS_RRCLASS_FLUSH         0x800 /* Flush bit */
82195972f6Sopenharmony_ci
83195972f6Sopenharmony_ci/* DNS protocol flags */
84195972f6Sopenharmony_ci#define DNS_FLAG1_RESPONSE        0x80
85195972f6Sopenharmony_ci#define DNS_FLAG1_OPCODE_STATUS   0x10
86195972f6Sopenharmony_ci#define DNS_FLAG1_OPCODE_INVERSE  0x08
87195972f6Sopenharmony_ci#define DNS_FLAG1_OPCODE_STANDARD 0x00
88195972f6Sopenharmony_ci#define DNS_FLAG1_AUTHORATIVE     0x04
89195972f6Sopenharmony_ci#define DNS_FLAG1_TRUNC           0x02
90195972f6Sopenharmony_ci#define DNS_FLAG1_RD              0x01
91195972f6Sopenharmony_ci#define DNS_FLAG2_RA              0x80
92195972f6Sopenharmony_ci#define DNS_FLAG2_ERR_MASK        0x0f
93195972f6Sopenharmony_ci#define DNS_FLAG2_ERR_NONE        0x00
94195972f6Sopenharmony_ci#define DNS_FLAG2_ERR_NAME        0x03
95195972f6Sopenharmony_ci
96195972f6Sopenharmony_ci#define DNS_HDR_GET_OPCODE(hdr) ((((hdr)->flags1) >> 3) & 0xF)
97195972f6Sopenharmony_ci
98195972f6Sopenharmony_ci#ifdef PACK_STRUCT_USE_INCLUDES
99195972f6Sopenharmony_ci#  include "arch/bpstruct.h"
100195972f6Sopenharmony_ci#endif
101195972f6Sopenharmony_ciPACK_STRUCT_BEGIN
102195972f6Sopenharmony_ci/** DNS message header */
103195972f6Sopenharmony_cistruct dns_hdr {
104195972f6Sopenharmony_ci  PACK_STRUCT_FIELD(u16_t id);
105195972f6Sopenharmony_ci  PACK_STRUCT_FLD_8(u8_t flags1);
106195972f6Sopenharmony_ci  PACK_STRUCT_FLD_8(u8_t flags2);
107195972f6Sopenharmony_ci  PACK_STRUCT_FIELD(u16_t numquestions);
108195972f6Sopenharmony_ci  PACK_STRUCT_FIELD(u16_t numanswers);
109195972f6Sopenharmony_ci  PACK_STRUCT_FIELD(u16_t numauthrr);
110195972f6Sopenharmony_ci  PACK_STRUCT_FIELD(u16_t numextrarr);
111195972f6Sopenharmony_ci} PACK_STRUCT_STRUCT;
112195972f6Sopenharmony_ciPACK_STRUCT_END
113195972f6Sopenharmony_ci#ifdef PACK_STRUCT_USE_INCLUDES
114195972f6Sopenharmony_ci#  include "arch/epstruct.h"
115195972f6Sopenharmony_ci#endif
116195972f6Sopenharmony_ci#define SIZEOF_DNS_HDR 12
117195972f6Sopenharmony_ci
118195972f6Sopenharmony_ci
119195972f6Sopenharmony_ci/* Multicast DNS definitions */
120195972f6Sopenharmony_ci
121195972f6Sopenharmony_ci/** UDP port for multicast DNS queries */
122195972f6Sopenharmony_ci#ifndef DNS_MQUERY_PORT
123195972f6Sopenharmony_ci#define DNS_MQUERY_PORT             5353
124195972f6Sopenharmony_ci#endif
125195972f6Sopenharmony_ci
126195972f6Sopenharmony_ci/* IPv4 group for multicast DNS queries: 224.0.0.251 */
127195972f6Sopenharmony_ci#ifndef DNS_MQUERY_IPV4_GROUP_INIT
128195972f6Sopenharmony_ci#define DNS_MQUERY_IPV4_GROUP_INIT  IPADDR4_INIT_BYTES(224,0,0,251)
129195972f6Sopenharmony_ci#endif
130195972f6Sopenharmony_ci
131195972f6Sopenharmony_ci/* IPv6 group for multicast DNS queries: FF02::FB */
132195972f6Sopenharmony_ci#ifndef DNS_MQUERY_IPV6_GROUP_INIT
133195972f6Sopenharmony_ci#define DNS_MQUERY_IPV6_GROUP_INIT  IPADDR6_INIT_HOST(0xFF020000,0,0,0xFB)
134195972f6Sopenharmony_ci#endif
135195972f6Sopenharmony_ci
136195972f6Sopenharmony_ci#ifdef __cplusplus
137195972f6Sopenharmony_ci}
138195972f6Sopenharmony_ci#endif
139195972f6Sopenharmony_ci
140195972f6Sopenharmony_ci#endif /* LWIP_HDR_PROT_DNS_H */
141