Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
DNS

DNS and hostname validation utilities. More...

Functions

SOURCEMETA_CORE_DNS_EXPORT auto sourcemeta::core::is_hostname (const std::string_view value) -> bool
SOURCEMETA_CORE_DNS_EXPORT auto sourcemeta::core::is_idn_hostname (const std::string_view value) -> bool
SOURCEMETA_CORE_DNS_EXPORT auto sourcemeta::core::is_idn_hostname_uts46 (const std::string_view value) -> bool

Detailed Description

DNS and hostname validation utilities.

This functionality is included as follows:

#include <sourcemeta/core/dns.h>

Function Documentation

◆ is_hostname()

SOURCEMETA_CORE_DNS_EXPORT auto sourcemeta::core::is_hostname ( const std::string_view value) -> bool

Check whether the given string is a valid Internet host name per RFC 1123 Section 2.1, which relaxes the first-character rule of RFC 952 to allow either a letter or a digit. For example:

#include <sourcemeta/core/dns.h>
#include <cassert>
assert(sourcemeta::core::is_hostname("www.example.com"));
assert(!sourcemeta::core::is_hostname("example."));
SOURCEMETA_CORE_DNS_EXPORT auto is_hostname(const std::string_view value) -> bool

This function operates on ASCII input only and caps the total length at 255 octets. Labels matching the case-insensitive "xn--" prefix are additionally validated as RFC 5890 A-labels, so the Punycode body must decode and round-trip.

◆ is_idn_hostname()

SOURCEMETA_CORE_DNS_EXPORT auto sourcemeta::core::is_idn_hostname ( const std::string_view value) -> bool

Check whether the given string is a valid internationalized host name per RFC 5891 Section 4. Each label is validated as an RFC 5890 A-label or U-label (with RFC 5892 ContextJ and ContextO contextual rules and the RFC 5891 ยง4.1.2.A NFC requirement), and the RFC 5893 Bidi rule is enforced on every label of a Bidi domain name. The total length is capped at 253 octets in A-label form. For example:

#include <sourcemeta/core/dns.h>
#include <cassert>
assert(sourcemeta::core::is_idn_hostname("www.example.com"));
"\xec\x8b\xa4\xeb\xa1\x80.\xed\x85\x8c\xec\x8a\xa4\xed\x8a\xb8"));
SOURCEMETA_CORE_DNS_EXPORT auto is_idn_hostname(const std::string_view value) -> bool

◆ is_idn_hostname_uts46()

SOURCEMETA_CORE_DNS_EXPORT auto sourcemeta::core::is_idn_hostname_uts46 ( const std::string_view value) -> bool

Check whether the given string is a valid internationalized host name after UTS #46 processing. The input is first mapped and normalised to NFC under UTS #46 Nontransitional Processing, then the mapped result is validated with the same IDNA 2008 per-label rules as a strict host name. This is the lookup-side behaviour: human-typed forms such as uppercase ASCII and fullwidth characters are folded before validation rather than rejected. See https://www.unicode.org/reports/tr46/ for the algorithm. For example:

#include <sourcemeta/core/dns.h>
#include <cassert>
assert(sourcemeta::core::is_idn_hostname_uts46("www.example.com"));
// Uppercase and fullwidth input is mapped before validation
assert(sourcemeta::core::is_idn_hostname_uts46("WWW.EXAMPLE.COM"));
SOURCEMETA_CORE_DNS_EXPORT auto is_idn_hostname_uts46(const std::string_view value) -> bool