Dotted-decimal IPv4 literal parser.
parseIpv4Literal
(host -- address valid) Parses host as a dotted-decimal IPv4 literal and returns its address and whether host is such a literal.hostis aText,String, orStringView.- A literal is four octets separated by dots, and nothing else; an octet is a number from 0 to 255 in ASCII digits without leading zeros.
addressis a host-orderNat32with the first dotted octet in the most significant byte:1.2.3.4gives0x01020304n32.validis aCond; when it isFALSE,addresshas no meaning.
Examples
Example: valid and invalid literals
The address of a literal is printed; a leading zero, an octet above 255, and a missing octet are refused.
"String" use
"control" use
"ipAddressUtils" use
show: [
host:;
address: valid: host parseIpv4Literal;;
valid [(host " = " address LF) printList] [(host " is not an IPv4 literal" LF) printList] if
];
{} Int32 {} [
"1.2.3.4" show
"01.2.3.4" show
"256.1.1.1" show
"1.2.3" show
0
] "main" exportFunction
Expected Output
1.2.3.4 = 16909060
01.2.3.4 is not an IPv4 literal
256.1.1.1 is not an IPv4 literal
1.2.3 is not an IPv4 literal
See also
- sync/DnsResolver: Hostname resolver that returns IPv4 addresses.
- sync/sync: Cross-platform scheduling, sleep, time, IPv4 formatting, and TCP helpers.