std/net/dns
std/dns — host resolution and IP-literal utilities.
Free functions in this module — no stateful object is needed;
the module namespace (use std::dns::*) is the grouping mechanism.
• resolve a hostname to its first IP for a connect() call.
• check reachability with a real TCP probe + timeout.
• classify literal IP strings without DNS round-trips.
Free functions
| Type | Method and description |
|---|---|
| dnsResolve(host : string) : string Resolves host to its first IP address. |
| dnsResolveAsync(host : string) : Future<string> Async twin of dnsResolve — the lookup runs on a worker thread;the future resolves to the first IP ( "" when none). |
| dnsResolveAny(host : string) : bool Whether host resolves to at least one IP address. |
| isReachable(host : string, port : i32, timeoutMillis : i32) : bool TCP reachability probe: opens a connection on port and closes it.timeoutMillis is enforced on both the DNS leg and the connect. Useport 80 / 443 for HTTP probes, 22 for SSH, etc. |
| __isDecimalByte(c : i32) : bool Whether byte c is an ASCII decimal digit. |
| __hexDigitValue(c : i32) : i32 The value of the hex digit byte c, or -1 when it is not one. |
| __ipv4SpanValue(s : string, lo : i64, hi : i64) : i64 The dotted-quad in s[lo..hi) as one 32-bit value, or -1 when thespan is not one. A leading zero is refused. 010 is an octal reading to some resolversand a decimal one to others, so accepting the text here would let one spelling name two different addresses. |
| __spanHasDot(s : string, lo : i64, hi : i64) : bool Whether s[lo..hi) carries a ., which is what marks a group as anembedded dotted-quad rather than hex. |
| __hexGroupValue(s : string, lo : i64, hi : i64) : i64 The hex group in s[lo..hi), or -1 when the span is not one to fourhex digits. |
| __readIpv6Run(s : string, lo : i64, hi : i64, allowV4Tail : bool, out : i32[], at : i64) : i64 Read the colon-separated groups of s[lo..hi) into out, starting atat, and answer how many were written — -1 when the span is not arun of groups. allowV4Tail says whether this side ends the address. A dotted-quadis only ever an address's last element, so 1.2.3.4:: is refused hererather than read as a leading group. |
| __parseIpv6(s : string, out : i32[]) : bool Read the IPv6 literal s into the eight slots of out, answeringwhether it is one. The values are produced rather than a yes-or-no, because the literal test and the loopback test are then one parser: a second reading of the same text would be a second chance for the two to disagree about what an address is. |
| __isLocalhostName(host : string) : bool Whether host is the name localhost, in any ASCII casing. |
| isIpv4Literal(s : string) : bool Whether s is a valid IPv4 dotted-quad literal (no DNS lookup). |
| isIpv6Literal(s : string) : bool Whether s is a valid IPv6 literal (no DNS lookup). |
| isLoopback(host : string) : bool Whether host names the loopback — 127.0.0.0/8, ::1, or "localhost". |
Method detail
#dnsResolve
Resolves host to its first IP address.
host hostname or IP literal to resolve"" if none resolvedIOException on a resolver failure#dnsResolveAsync
Async twin of dnsResolve — the lookup runs on a worker thread;
the future resolves to the first IP ("" when none).
host hostname or IP literal to resolveFuture<string> that resolves to the first IP, or "" on no resultIOException on a resolver failure (raised at the await site)#dnsResolveAny
Whether host resolves to at least one IP address.
host hostname or IP literal to probetrue if at least one address resolves, false otherwise#isReachable
TCP reachability probe: opens a connection on port and closes it.timeoutMillis is enforced on both the DNS leg and the connect. Use
port 80 / 443 for HTTP probes, 22 for SSH, etc.
host hostname or IP literal to probeport TCP port to attempt the connection on, 1..65535timeoutMillis connection timeout in millisecondstrue if the TCP connection succeeded within the deadline#__isDecimalByte
Whether byte c is an ASCII decimal digit.
#__hexDigitValue
The value of the hex digit byte c, or -1 when it is not one.
c candidate byte#__ipv4SpanValue
The dotted-quad in s[lo..hi) as one 32-bit value, or -1 when the
span is not one.
A leading zero is refused. 010 is an octal reading to some resolvers
and a decimal one to others, so accepting the text here would let one
spelling name two different addresses.
s text the span indexes intolo first byte of the spanhi one past its last byte-1#__spanHasDot
Whether s[lo..hi) carries a ., which is what marks a group as an
embedded dotted-quad rather than hex.
s text the span indexes intolo first byte of the spanhi one past its last byte#__hexGroupValue
The hex group in s[lo..hi), or -1 when the span is not one to four
hex digits.
s text the span indexes intolo first byte of the spanhi one past its last byte#__readIpv6Run
Read the colon-separated groups of s[lo..hi) into out, starting atat, and answer how many were written — -1 when the span is not a
run of groups.allowV4Tail says whether this side ends the address. A dotted-quad
is only ever an address's last element, so 1.2.3.4:: is refused here
rather than read as a leading group.
s text the span indexes intolo first byte of the spanhi one past its last byteallowV4Tail whether a trailing dotted-quad is acceptedout eight-slot destination for the group valuesat first slot to write-1#__parseIpv6
Read the IPv6 literal s into the eight slots of out, answering
whether it is one.
The values are produced rather than a yes-or-no, because the literal
test and the loopback test are then one parser: a second reading of the
same text would be a second chance for the two to disagree about what
an address is.
s candidate literalout eight-slot destination for the group values#__isLocalhostName
Whether host is the name localhost, in any ASCII casing.
host candidate name#isIpv4Literal
Whether s is a valid IPv4 dotted-quad literal (no DNS lookup).
s candidate IP string to classifytrue if s parses as a valid IPv4 address (e.g. "192.168.1.1")#isIpv6Literal
Whether s is a valid IPv6 literal (no DNS lookup).
s candidate IP string to classifytrue if s parses as a valid IPv6 address (e.g. "::1", "2001:db8::1")#isLoopback
Whether host names the loopback — 127.0.0.0/8, ::1, or "localhost".
host hostname or IP literal to testtrue for any loopback address or the literal string "localhost"