dns_common.h File Reference

Common DNS routines. More...

#include "core/net.h"

Go to the source code of this file.

Macros

#define DNS_NAME_MAX_RECURSION   4
 
#define DNS_MESSAGE_MAX_SIZE   512
 
#define DNS_NAME_MAX_SIZE   255
 
#define DNS_LABEL_MAX_SIZE   63
 
#define DNS_MAX_IPV4_REVERSE_NAME_LEN   15
 
#define DNS_MAX_IPV6_REVERSE_NAME_LEN   63
 
#define DNS_PORT   53
 
#define DNS_COMPRESSION_TAG   0xC0
 
#define DNS_GET_QUESTION(message, offset)   (DnsQuestion *) ((uint8_t *) (message) + (offset))
 
#define DNS_GET_RESOURCE_RECORD(message, offset)   (DnsResourceRecord *) ((uint8_t *) (message) + (offset))
 
#define DNS_SET_NSEC_BITMAP(bitmap, type)   bitmap[(type) / 8] |= 0x80 >> ((type) % 8)
 
#define DNS_CLR_NSEC_BITMAP(bitmap, type)   bitmap[(type) / 8] &= ~(0x80 >> ((type) % 8))
 

Typedefs

struct {
   uint16_t   id
 
   uint16_t   rd: 1
 
   uint16_t   tc: 1
 
   uint16_t   aa: 1
 
   uint16_t   opcode: 4
 
   uint16_t   qr: 1
 
   uint16_t   rcode: 4
 
   uint16_t   z: 3
 
   uint16_t   ra: 1
 
   uint16_t   qdcount
 
   uint16_t   ancount
 
   uint16_t   nscount
 
   uint16_t   arcount
 
   uint8_t   questions []
 
DnsHeader
 DNS message header. More...
 
struct {
   uint16_t   qtype
 
   uint16_t   qclass
 
DnsQuestion
 Question format. More...
 
struct {
   uint16_t   rtype
 
   uint16_t   rclass
 
   uint32_t   ttl
 
   uint16_t   rdlength
 
   uint8_t   rdata []
 
DnsResourceRecord
 Resource record format. More...
 
struct {
   uint16_t   rtype
 
   uint16_t   rclass
 
   uint32_t   ttl
 
   uint16_t   rdlength
 
   uint16_t   priority
 
   uint16_t   weight
 
   uint16_t   port
 
   uint8_t   target []
 
DnsSrvResourceRecord
 SRV resource record format. More...
 

Enumerations

enum  DnsOpcode {
  DNS_OPCODE_QUERY = 0, DNS_OPCODE_INVERSE_QUERY = 1, DNS_OPCODE_STATUS = 2, DNS_OPCODE_NOTIFY = 4,
  DNS_OPCODE_UPDATE = 5
}
 DNS opcodes. More...
 
enum  DnsReturnCode {
  DNS_RCODE_NO_ERROR = 0, DNS_RCODE_FORMAT_ERROR = 1, DNS_RCODE_SERVER_FAILURE = 2, DNS_RCODE_NAME_ERROR = 3,
  DNS_RCODE_NOT_IMPLEMENTED = 4, DNS_RCODE_QUERY_REFUSED = 5
}
 DNS return codes. More...
 
enum  DnsResourceRecordClass { DNS_RR_CLASS_IN = 1, DNS_RR_CLASS_CH = 3, DNS_RR_CLASS_HS = 4, DNS_RR_CLASS_ANY = 255 }
 DNS resource record classes. More...
 
enum  DnsResourceRecordType {
  DNS_RR_TYPE_A = 1, DNS_RR_TYPE_NS = 2, DNS_RR_TYPE_CNAME = 5, DNS_RR_TYPE_SOA = 6,
  DNS_RR_TYPE_WKS = 11, DNS_RR_TYPE_PTR = 12, DNS_RR_TYPE_HINFO = 13, DNS_RR_TYPE_MINFO = 14,
  DNS_RR_TYPE_MX = 15, DNS_RR_TYPE_TXT = 16, DNS_RR_TYPE_AAAA = 28, DNS_RR_TYPE_NB = 32,
  DNS_RR_TYPE_SRV = 33, DNS_RR_TYPE_NAPTR = 35, DNS_RR_TYPE_NSEC = 47, DNS_RR_TYPE_EUI48 = 108,
  DNS_RR_TYPE_EUI64 = 109, DNS_RR_TYPE_AXFR = 252, DNS_RR_TYPE_ANY = 255, DNS_RR_TYPE_URI = 256
}
 DNS resource record types. More...
 

Functions

size_t dnsEncodeName (const char_t *src, uint8_t *dest)
 Encode a domain name using the DNS name notation. More...
 
size_t dnsParseName (const DnsHeader *message, size_t length, size_t pos, char_t *dest, uint_t level)
 Decode a domain name that uses the DNS name encoding. More...
 
int_t dnsCompareName (const DnsHeader *message, size_t length, size_t pos, const char_t *name, uint_t level)
 Compare domain names. More...
 
int_t dnsCompareEncodedName (const DnsHeader *message1, size_t length1, size_t pos1, const DnsHeader *message2, size_t length2, size_t pos2, uint_t level)
 Compare domain names encoded with DNS notation. More...
 

Detailed Description

Common DNS routines.

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file dns_common.h.

Macro Definition Documentation

◆ DNS_CLR_NSEC_BITMAP

#define DNS_CLR_NSEC_BITMAP (   bitmap,
  type 
)    bitmap[(type) / 8] &= ~(0x80 >> ((type) % 8))

Definition at line 65 of file dns_common.h.

◆ DNS_COMPRESSION_TAG

#define DNS_COMPRESSION_TAG   0xC0

Definition at line 58 of file dns_common.h.

◆ DNS_GET_QUESTION

#define DNS_GET_QUESTION (   message,
  offset 
)    (DnsQuestion *) ((uint8_t *) (message) + (offset))

Definition at line 61 of file dns_common.h.

◆ DNS_GET_RESOURCE_RECORD

#define DNS_GET_RESOURCE_RECORD (   message,
  offset 
)    (DnsResourceRecord *) ((uint8_t *) (message) + (offset))

Definition at line 62 of file dns_common.h.

◆ DNS_LABEL_MAX_SIZE

#define DNS_LABEL_MAX_SIZE   63

Definition at line 47 of file dns_common.h.

◆ DNS_MAX_IPV4_REVERSE_NAME_LEN

#define DNS_MAX_IPV4_REVERSE_NAME_LEN   15

Definition at line 50 of file dns_common.h.

◆ DNS_MAX_IPV6_REVERSE_NAME_LEN

#define DNS_MAX_IPV6_REVERSE_NAME_LEN   63

Definition at line 52 of file dns_common.h.

◆ DNS_MESSAGE_MAX_SIZE

#define DNS_MESSAGE_MAX_SIZE   512

Definition at line 43 of file dns_common.h.

◆ DNS_NAME_MAX_RECURSION

#define DNS_NAME_MAX_RECURSION   4

Definition at line 37 of file dns_common.h.

◆ DNS_NAME_MAX_SIZE

#define DNS_NAME_MAX_SIZE   255

Definition at line 45 of file dns_common.h.

◆ DNS_PORT

#define DNS_PORT   53

Definition at line 55 of file dns_common.h.

◆ DNS_SET_NSEC_BITMAP

#define DNS_SET_NSEC_BITMAP (   bitmap,
  type 
)    bitmap[(type) / 8] |= 0x80 >> ((type) % 8)

Definition at line 64 of file dns_common.h.

Typedef Documentation

◆ DnsHeader

typedef { ... } DnsHeader

DNS message header.

◆ DnsQuestion

typedef { ... } DnsQuestion

Question format.

◆ DnsResourceRecord

typedef { ... } DnsResourceRecord

Resource record format.

◆ DnsSrvResourceRecord

typedef { ... } DnsSrvResourceRecord

SRV resource record format.

Enumeration Type Documentation

◆ DnsOpcode

enum DnsOpcode

DNS opcodes.

Enumerator
DNS_OPCODE_QUERY 
DNS_OPCODE_INVERSE_QUERY 
DNS_OPCODE_STATUS 
DNS_OPCODE_NOTIFY 
DNS_OPCODE_UPDATE 

Definition at line 77 of file dns_common.h.

◆ DnsResourceRecordClass

DNS resource record classes.

Enumerator
DNS_RR_CLASS_IN 

Internet.

DNS_RR_CLASS_CH 

Chaos.

DNS_RR_CLASS_HS 

Hesiod.

DNS_RR_CLASS_ANY 

Any class.

Definition at line 106 of file dns_common.h.

◆ DnsResourceRecordType

DNS resource record types.

Enumerator
DNS_RR_TYPE_A 

Host address.

DNS_RR_TYPE_NS 

Authoritative name server.

DNS_RR_TYPE_CNAME 

Canonical name for an alias.

DNS_RR_TYPE_SOA 

Start of a zone of authority.

DNS_RR_TYPE_WKS 

Well known service description.

DNS_RR_TYPE_PTR 

Domain name pointer.

DNS_RR_TYPE_HINFO 

Host information.

DNS_RR_TYPE_MINFO 

Mailbox or mail list information.

DNS_RR_TYPE_MX 

Mail exchange.

DNS_RR_TYPE_TXT 

Text strings.

DNS_RR_TYPE_AAAA 

IPv6 address.

DNS_RR_TYPE_NB 

NetBIOS name service.

DNS_RR_TYPE_SRV 

Server selection.

DNS_RR_TYPE_NAPTR 

Naming authority pointer.

DNS_RR_TYPE_NSEC 

NSEC record.

DNS_RR_TYPE_EUI48 

EUI-48 address.

DNS_RR_TYPE_EUI64 

EUI-64 address.

DNS_RR_TYPE_AXFR 

Transfer of an entire zone.

DNS_RR_TYPE_ANY 

A request for all records.

DNS_RR_TYPE_URI 

Uniform resource identifier.

Definition at line 119 of file dns_common.h.

◆ DnsReturnCode

DNS return codes.

Enumerator
DNS_RCODE_NO_ERROR 
DNS_RCODE_FORMAT_ERROR 
DNS_RCODE_SERVER_FAILURE 
DNS_RCODE_NAME_ERROR 
DNS_RCODE_NOT_IMPLEMENTED 
DNS_RCODE_QUERY_REFUSED 

Definition at line 91 of file dns_common.h.

Function Documentation

◆ dnsCompareEncodedName()

int_t dnsCompareEncodedName ( const DnsHeader message1,
size_t  length1,
size_t  pos1,
const DnsHeader message2,
size_t  length2,
size_t  pos2,
uint_t  level 
)

Compare domain names encoded with DNS notation.

Parameters
[in]message1Pointer to the first DNS message
[in]length1Length of the first DNS message
[in]pos1Offset of the encoded domain name within the first message
[in]message2Pointer to the second DNS message
[in]length2Length of the second DNS message
[in]pos2Offset of the encoded domain name within the second message
[in]levelCurrent level of recursion
Returns
The function returns 0 if the domain names match, -1 if the first domain name lexicographically precedes the second name, or 1 if the second domain name lexicographically precedes the first name

Definition at line 337 of file dns_common.c.

◆ dnsCompareName()

int_t dnsCompareName ( const DnsHeader message,
size_t  length,
size_t  pos,
const char_t name,
uint_t  level 
)

Compare domain names.

Parameters
[in]messagePointer to the DNS message
[in]lengthLength of the DNS message
[in]posOffset of the encoded domain name
[in]nameNULL-terminated string that holds a domain name
[in]levelCurrent level of recursion
Returns
The function returns 0 if the domain names match, -1 if the first domain name lexicographically precedes the second name, or 1 if the second domain name lexicographically precedes the first name

Definition at line 238 of file dns_common.c.

◆ dnsEncodeName()

size_t dnsEncodeName ( const char_t src,
uint8_t *  dest 
)

Encode a domain name using the DNS name notation.

Parameters
[in]srcPointer to the domain name to encode
[out]destPointer to the encoded domain name (optional parameter)
Returns
Length of the encoded domain name

Definition at line 54 of file dns_common.c.

◆ dnsParseName()

size_t dnsParseName ( const DnsHeader message,
size_t  length,
size_t  pos,
char_t dest,
uint_t  level 
)

Decode a domain name that uses the DNS name encoding.

Parameters
[in]messagePointer to the DNS message
[in]lengthLength of the DNS message
[in]posOffset of the name to decode
[out]destPointer to the decoded name (optional)
[in]levelCurrent level of recursion
Returns
The position of the resource record that immediately follows the domain name

Definition at line 128 of file dns_common.c.

Variable Documentation

◆ aa

uint16_t aa

Definition at line 169 of file dns_common.h.

◆ ancount

uint16_t ancount

Definition at line 177 of file dns_common.h.

◆ arcount

uint16_t arcount

Definition at line 179 of file dns_common.h.

◆ id

uint16_t id

Definition at line 156 of file dns_common.h.

◆ nscount

uint16_t nscount

Definition at line 178 of file dns_common.h.

◆ opcode

uint16_t opcode

Definition at line 170 of file dns_common.h.

◆ port

uint16_t port

Definition at line 221 of file dns_common.h.

◆ priority

uint16_t priority

Definition at line 219 of file dns_common.h.

◆ qclass

uint16_t qclass

Definition at line 191 of file dns_common.h.

◆ qdcount

uint16_t qdcount

Definition at line 176 of file dns_common.h.

◆ qr

uint16_t qr

Definition at line 171 of file dns_common.h.

◆ qtype

uint16_t qtype

Definition at line 190 of file dns_common.h.

◆ questions

uint8_t questions[]

Definition at line 180 of file dns_common.h.

◆ ra

uint16_t ra

Definition at line 174 of file dns_common.h.

◆ rclass

uint16_t rclass

Definition at line 202 of file dns_common.h.

◆ rcode

uint16_t rcode

Definition at line 172 of file dns_common.h.

◆ rd

uint16_t rd

Definition at line 167 of file dns_common.h.

◆ rdata

uint8_t rdata[]

Definition at line 205 of file dns_common.h.

◆ rdlength

uint16_t rdlength

Definition at line 204 of file dns_common.h.

◆ rtype

uint16_t rtype

Definition at line 201 of file dns_common.h.

◆ target

uint8_t target[]

Definition at line 222 of file dns_common.h.

◆ tc

uint16_t tc

Definition at line 168 of file dns_common.h.

◆ ttl

uint32_t ttl

Definition at line 203 of file dns_common.h.

◆ weight

uint16_t weight

Definition at line 220 of file dns_common.h.

◆ z

uint16_t z

Definition at line 173 of file dns_common.h.