commit be54eea9c21f24b37a5fd2385eb6eda927c571cf
parent 4c2d5ff1162be816f0498f79804333a802a75a70
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 28 Nov 2021 16:54:29 +0100
net::ip: add LOCAL_V4, LOCAL_V6
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/dns/query.ha b/net/dns/query.ha
@@ -20,10 +20,7 @@ export fn query(query: *message, servers: ip::addr...) (*message | error) = {
};
if (len(servers) == 0) {
// Fall back to localhost
- servers = [
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]: ip::addr6,
- [127, 0, 0, 1]: ip::addr4,
- ];
+ servers = [ip::LOCAL_V6, ip::LOCAL_V4];
};
let socket4 = udp::listen(ip::ANY_V4, 0)?;
diff --git a/net/ip/ip.ha b/net/ip/ip.ha
@@ -29,6 +29,12 @@ export const ANY_V4: addr4 = [0, 0, 0, 0];
// address will listen on all available IPv6 interfaces on most systems.
export const ANY_V6: addr6 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+// An IPv4 address which represents the loopback address, i.e. "127.0.0.1".
+export const LOCAL_V4: addr4 = [127, 0, 0, 1];
+
+// An IPv6 address which represents the loopback address, i.e. "::1".
+export const LOCAL_V6: addr6 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
+
// Invalid parse result.
export type invalid = !void;