commit 8eb27c2bda1efd3a39ceb1a78a4646f0c7afed8d
parent f22695bc446baeb1bff9e1bd5e17009e0c7f9bae
Author: Alexey Yerin <yyp@disroot.org>
Date: Tue, 21 Feb 2023 23:53:26 +0300
net::ip: export parsev4 and parsev6
These can be useful when parsing a format that expects a certain
version. One example is URIs, which expect only IPv6 inside [ ... ]
(https://[1.2.3.4] is not allowed)
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/ip/ip.ha b/net/ip/ip.ha
@@ -65,7 +65,8 @@ export fn equal(l: addr, r: addr) bool = {
};
};
-fn parsev4(st: str) (addr4 | invalid) = {
+// Parses an IPv4 address.
+export fn parsev4(st: str) (addr4 | invalid) = {
let ret: addr4 = [0...];
let tok = strings::tokenize(st, ".");
let i = 0z;
@@ -87,7 +88,8 @@ fn parsev4(st: str) (addr4 | invalid) = {
return ret;
};
-fn parsev6(st: str) (addr6 | invalid) = {
+// Parses an IPv6 address.
+export fn parsev6(st: str) (addr6 | invalid) = {
let ret: addr6 = [0...];
if (st == "::") {
return ret;