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)) |
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... | |
void | dnsGenerateIpv4ReverseName (Ipv4Addr ipv4Addr, char_t *buffer) |
Generate domain name for reverse DNS lookup (IPv4) More... | |
void | dnsGenerateIpv6ReverseName (const Ipv6Addr *ipv6Addr, char_t *buffer) |
Generate domain name for reverse DNS lookup (IPv6) More... | |
Variables | |
typedef | __packed_struct |
DNS message header. More... | |
uint8_t | rd |
uint8_t | tc |
uint8_t | aa |
uint8_t | opcode |
uint8_t | qr |
uint8_t | rcode |
uint8_t | z |
uint8_t | ra |
uint16_t | qdcount |
uint16_t | ancount |
uint16_t | nscount |
uint16_t | arcount |
uint8_t | questions [] |
DnsHeader | |
uint16_t | qclass |
DnsQuestion | |
uint16_t | rclass |
uint32_t | ttl |
uint16_t | rdlength |
uint8_t | rdata [] |
DnsResourceRecord | |
DnsIpv4AddrResourceRecord | |
DnsIpv6AddrResourceRecord | |
uint16_t | priority |
uint16_t | weight |
uint16_t | port |
uint8_t | target [] |
DnsSrvResourceRecord | |
Detailed Description
Common DNS routines.
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2024 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.
- Version
- 2.4.4
Definition in file dns_common.h.
Macro Definition Documentation
◆ DNS_CLR_NSEC_BITMAP
Definition at line 67 of file dns_common.h.
◆ DNS_COMPRESSION_TAG
#define DNS_COMPRESSION_TAG 0xC0 |
Definition at line 60 of file dns_common.h.
◆ DNS_GET_QUESTION
#define DNS_GET_QUESTION | ( | message, | |
offset | |||
) | (DnsQuestion *) ((uint8_t *) (message) + (offset)) |
Definition at line 63 of file dns_common.h.
◆ DNS_GET_RESOURCE_RECORD
#define DNS_GET_RESOURCE_RECORD | ( | message, | |
offset | |||
) | (DnsResourceRecord *) ((uint8_t *) (message) + (offset)) |
Definition at line 64 of file dns_common.h.
◆ DNS_LABEL_MAX_SIZE
#define DNS_LABEL_MAX_SIZE 63 |
Definition at line 49 of file dns_common.h.
◆ DNS_MAX_IPV4_REVERSE_NAME_LEN
#define DNS_MAX_IPV4_REVERSE_NAME_LEN 15 |
Definition at line 52 of file dns_common.h.
◆ DNS_MAX_IPV6_REVERSE_NAME_LEN
#define DNS_MAX_IPV6_REVERSE_NAME_LEN 63 |
Definition at line 54 of file dns_common.h.
◆ DNS_MESSAGE_MAX_SIZE
#define DNS_MESSAGE_MAX_SIZE 512 |
Definition at line 45 of file dns_common.h.
◆ DNS_NAME_MAX_RECURSION
#define DNS_NAME_MAX_RECURSION 4 |
Definition at line 39 of file dns_common.h.
◆ DNS_NAME_MAX_SIZE
#define DNS_NAME_MAX_SIZE 255 |
Definition at line 47 of file dns_common.h.
◆ DNS_PORT
#define DNS_PORT 53 |
Definition at line 57 of file dns_common.h.
◆ DNS_SET_NSEC_BITMAP
Definition at line 66 of file dns_common.h.
Enumeration Type Documentation
◆ DnsOpcode
enum DnsOpcode |
DNS opcodes.
Enumerator | |
---|---|
DNS_OPCODE_QUERY | Query. |
DNS_OPCODE_IQUERY | Inverse query. |
DNS_OPCODE_STATUS | Status. |
DNS_OPCODE_NOTIFY | Notify. |
DNS_OPCODE_UPDATE | Update. |
Definition at line 79 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 122 of file dns_common.h.
◆ DnsResourceRecordType
DNS resource record types.
Definition at line 135 of file dns_common.h.
◆ DnsResponseCode
enum DnsResponseCode |
DNS response codes.
Definition at line 93 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] message1 Pointer to the first DNS message [in] length1 Length of the first DNS message [in] pos1 Offset of the encoded domain name within the first message [in] message2 Pointer to the second DNS message [in] length2 Length of the second DNS message [in] pos2 Offset of the encoded domain name within the second message [in] level Current 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 341 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] message Pointer to the DNS message [in] length Length of the DNS message [in] pos Offset of the encoded domain name [in] name NULL-terminated string that holds a domain name [in] level Current 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 242 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] src Pointer to the domain name to encode [out] dest Pointer to the encoded domain name (optional parameter)
- Returns
- Length of the encoded domain name
Definition at line 58 of file dns_common.c.
◆ dnsGenerateIpv4ReverseName()
Generate domain name for reverse DNS lookup (IPv4)
- Parameters
-
[in] ipv4Addr IPv4 address [out] buffer Output buffer where to store the resulting domain name
Definition at line 479 of file dns_common.c.
◆ dnsGenerateIpv6ReverseName()
Generate domain name for reverse DNS lookup (IPv6)
- Parameters
-
[in] ipv6Addr IPv6 address [out] buffer Output buffer where to store the resulting domain name
Definition at line 498 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] message Pointer to the DNS message [in] length Length of the DNS message [in] pos Offset of the name to decode [out] dest Pointer to the decoded name (optional) [in] level Current level of recursion
- Returns
- The position of the resource record that immediately follows the domain name
Definition at line 132 of file dns_common.c.
Variable Documentation
◆ __packed_struct
typedef __packed_struct |
DNS message header.
SRV resource record format.
AAAA resource record format.
A resource record format.
Resource record format.
Question format.
Definition at line 172 of file dns_common.h.
◆ aa
uint8_t aa |
Definition at line 187 of file dns_common.h.
◆ ancount
uint16_t ancount |
Definition at line 195 of file dns_common.h.
◆ arcount
uint16_t arcount |
Definition at line 197 of file dns_common.h.
◆ DnsHeader
DnsHeader |
Definition at line 199 of file dns_common.h.
◆ DnsIpv4AddrResourceRecord
DnsIpv4AddrResourceRecord |
Definition at line 238 of file dns_common.h.
◆ DnsIpv6AddrResourceRecord
DnsIpv6AddrResourceRecord |
Definition at line 252 of file dns_common.h.
◆ DnsQuestion
DnsQuestion |
Definition at line 210 of file dns_common.h.
◆ DnsResourceRecord
DnsResourceRecord |
Definition at line 224 of file dns_common.h.
◆ DnsSrvResourceRecord
DnsSrvResourceRecord |
Definition at line 269 of file dns_common.h.
◆ nscount
uint16_t nscount |
Definition at line 196 of file dns_common.h.
◆ opcode
uint8_t opcode |
Definition at line 188 of file dns_common.h.
◆ port
uint16_t port |
Definition at line 267 of file dns_common.h.
◆ priority
uint16_t priority |
Definition at line 265 of file dns_common.h.
◆ qclass
uint16_t qclass |
Definition at line 209 of file dns_common.h.
◆ qdcount
uint16_t qdcount |
Definition at line 194 of file dns_common.h.
◆ qr
uint8_t qr |
Definition at line 189 of file dns_common.h.
◆ questions
uint8_t questions[] |
Definition at line 198 of file dns_common.h.
◆ ra
uint8_t ra |
Definition at line 192 of file dns_common.h.
◆ rclass
uint16_t rclass |
Definition at line 220 of file dns_common.h.
◆ rcode
uint8_t rcode |
Definition at line 190 of file dns_common.h.
◆ rd
uint8_t rd |
Definition at line 185 of file dns_common.h.
◆ rdata
uint8_t rdata |
Definition at line 223 of file dns_common.h.
◆ rdlength
uint16_t rdlength |
Definition at line 222 of file dns_common.h.
◆ target
uint8_t target[] |
Definition at line 268 of file dns_common.h.
◆ tc
uint8_t tc |
Definition at line 186 of file dns_common.h.
◆ ttl
uint32_t ttl |
Definition at line 221 of file dns_common.h.
◆ weight
uint16_t weight |
Definition at line 266 of file dns_common.h.
◆ z
uint8_t z |
Definition at line 191 of file dns_common.h.