dns_common.c File Reference

Common DNS routines. More...

#include "core/net.h"
#include "dns/dns_client.h"
#include "dns/dns_common.h"
#include "mdns/mdns_client.h"
#include "mdns/mdns_responder.h"
#include "mdns/mdns_common.h"
#include "llmnr/llmnr_client.h"
#include "llmnr/llmnr_responder.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   DNS_TRACE_LEVEL
 

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...
 

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.

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

Definition in file dns_common.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   DNS_TRACE_LEVEL

Definition at line 32 of file dns_common.c.

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 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]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 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]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 58 of file dns_common.c.

◆ dnsGenerateIpv4ReverseName()

void dnsGenerateIpv4ReverseName ( Ipv4Addr  ipv4Addr,
char_t buffer 
)

Generate domain name for reverse DNS lookup (IPv4)

Parameters
[in]ipv4AddrIPv4 address
[out]bufferOutput buffer where to store the resulting domain name

Definition at line 479 of file dns_common.c.

◆ dnsGenerateIpv6ReverseName()

void dnsGenerateIpv6ReverseName ( const Ipv6Addr ipv6Addr,
char_t buffer 
)

Generate domain name for reverse DNS lookup (IPv6)

Parameters
[in]ipv6AddrIPv6 address
[out]bufferOutput 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]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 132 of file dns_common.c.