authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-15 21:08:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:50-07:00
log90fdd21df6663d0ad99379cd056c8940e3a3e267
tree1ba9c0a0c77a37c2999ec690829881c5eeb0f933
parentbf841bb4ae6d6c7cf9494ccc45282b704b40e7f6

std: move DNS record enum to a better namespace


5 files changed, 19 insertions(+), 18 deletions(-)

lib/std/Io/Threaded.zig+9-9
......@@ -3130,9 +3130,9 @@ fn lookupDns(
31303130 options: HostName.LookupOptions,
31313131) HostName.LookupError!void {
31323132 const t_io = t.io();
3133 const family_records: [2]struct { af: IpAddress.Family, rr: u8 } = .{
3134 .{ .af = .ip6, .rr = std.posix.RR.A },
3135 .{ .af = .ip4, .rr = std.posix.RR.AAAA },
3133 const family_records: [2]struct { af: IpAddress.Family, rr: HostName.DnsRecord } = .{
3134 .{ .af = .ip6, .rr = .A },
3135 .{ .af = .ip4, .rr = .AAAA },
31363136 };
31373137 var query_buffers: [2][280]u8 = undefined;
31383138 var answer_buffer: [2 * 512]u8 = undefined;
......@@ -3280,7 +3280,7 @@ fn lookupDns(
32803280 // Here we could potentially add diagnostics to the results queue.
32813281 continue;
32823282 }) |record| switch (record.rr) {
3283 std.posix.RR.A => {
3283 .A => {
32843284 const data = record.packet[record.data_off..][0..record.data_len];
32853285 if (data.len != 4) return error.InvalidDnsARecord;
32863286 try resolved.putOne(t_io, .{ .address = .{ .ip4 = .{
......@@ -3289,7 +3289,7 @@ fn lookupDns(
32893289 } } });
32903290 addresses_len += 1;
32913291 },
3292 std.posix.RR.AAAA => {
3292 .AAAA => {
32933293 const data = record.packet[record.data_off..][0..record.data_len];
32943294 if (data.len != 16) return error.InvalidDnsAAAARecord;
32953295 try resolved.putOne(t_io, .{ .address = .{ .ip6 = .{
......@@ -3298,11 +3298,11 @@ fn lookupDns(
32983298 } } });
32993299 addresses_len += 1;
33003300 },
3301 std.posix.RR.CNAME => {
3301 .CNAME => {
33023302 _, canonical_name = HostName.expand(record.packet, record.data_off, options.canonical_name_buffer) catch
33033303 return error.InvalidDnsCnameRecord;
33043304 },
3305 else => continue,
3305 _ => continue,
33063306 };
33073307 }
33083308
......@@ -3413,7 +3413,7 @@ fn lookupHostsReader(
34133413}
34143414
34153415/// Writes DNS resolution query packet data to `w`; at most 280 bytes.
3416fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: u8, entropy: [2]u8) usize {
3416fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: HostName.DnsRecord, entropy: [2]u8) usize {
34173417 // This implementation is ported from musl libc.
34183418 // A more idiomatic "ziggy" implementation would be welcome.
34193419 var name = dname;
......@@ -3437,7 +3437,7 @@ fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: u
34373437 if (j - i - 1 > 62) unreachable;
34383438 q[i - 1] = @intCast(j - i);
34393439 }
3440 q[i + 1] = ty;
3440 q[i + 1] = @intFromEnum(ty);
34413441 q[i + 3] = class;
34423442 return n;
34433443}
lib/std/Io/net/HostName.zig+9-2
......@@ -147,13 +147,20 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [
147147 return error.InvalidDnsPacket;
148148}
149149
150pub const DnsRecord = enum(u8) {
151 A = 1,
152 CNAME = 5,
153 AAAA = 28,
154 _,
155};
156
150157pub const DnsResponse = struct {
151158 bytes: []const u8,
152159 bytes_index: u32,
153160 answers_remaining: u16,
154161
155162 pub const Answer = struct {
156 rr: u8,
163 rr: DnsRecord,
157164 packet: []const u8,
158165 data_off: u32,
159166 data_len: u16,
......@@ -190,7 +197,7 @@ pub const DnsResponse = struct {
190197 if (i + 10 + len > r.len) return error.InvalidDnsPacket;
191198 defer dr.bytes_index = i + 10 + len;
192199 return .{
193 .rr = r[i + 1],
200 .rr = @enumFromInt(r[i + 1]),
194201 .packet = r,
195202 .data_off = i + 10,
196203 .data_len = len,
lib/std/os/linux.zig-6
......@@ -7096,12 +7096,6 @@ pub const IPPROTO = struct {
70967096 pub const MAX = 256;
70977097};
70987098
7099pub const RR = struct {
7100 pub const A = 1;
7101 pub const CNAME = 5;
7102 pub const AAAA = 28;
7103};
7104
71057099pub const tcp_repair_opt = extern struct {
71067100 opt_code: u32,
71077101 opt_val: u32,
lib/std/posix.zig-1
......@@ -98,7 +98,6 @@ pub const POSIX_FADV = system.POSIX_FADV;
9898pub const PR = system.PR;
9999pub const PROT = system.PROT;
100100pub const RLIM = system.RLIM;
101pub const RR = system.RR;
102101pub const S = system.S;
103102pub const SA = system.SA;
104103pub const SC = system.SC;
src/main.zig+1
......@@ -5062,6 +5062,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
50625062 // Prevents bootstrap from depending on a bunch of unnecessary stuff.
50635063 var http_client: if (dev.env.supports(.fetch_command)) std.http.Client else struct {
50645064 allocator: Allocator,
5065 io: Io,
50655066 fn deinit(_: @This()) void {}
50665067 } = .{ .allocator = gpa, .io = io };
50675068 defer http_client.deinit();