authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-04 18:17:31 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-04 18:17:31 -08:00
log71519d1b76afc034fd01745bf3b2ea57f987d02f
tree797069dcd0e9c32ae5a07c73ba16270887b63348
parent16f8b814eb500b657e6cbd1ebe2d20c81a500d92

add getaddrinfo


2 files changed, 13 insertions(+), 0 deletions(-)

mod.zig+12
......@@ -1478,6 +1478,10 @@ pub const libc = struct {
14781478 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/fsync.html
14791479 pub extern fn fsync(fd: c_int) c_int;
14801480
1481 /// int getaddrinfo(const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints, struct addrinfo **restrict res);
1482 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/getaddrinfo.html
1483 pub extern fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias req: ?*const struct_addrinfo, noalias pai: **const struct_addrinfo) c_int;
1484
14811485 /// int getchar(void);
14821486 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/getchar.html
14831487 pub extern fn getchar() c_int;
......@@ -3089,3 +3093,11 @@ pub fn recv(socketfd: c_uint, buffer: []u8, flags: c_int) errno.Error!usize {
30893093 std.debug.assert(rc >= 0);
30903094 return @intCast(rc);
30913095}
3096pub fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias req: ?*const struct_addrinfo) eai.Error!*const struct_addrinfo {
3097 var pai: *const struct_addrinfo = undefined;
3098 var hints = std.mem.zeroes(struct_addrinfo);
3099 const rc = libc.getaddrinfo(nodename, servname, req orelse &hints, &pai);
3100 if (rc < 0) return eai.fromInt(rc);
3101 std.debug.assert(rc == 0);
3102 return pai;
3103}
test.zig+1
......@@ -25,4 +25,5 @@ test {
2525 _ = &linux.accept4;
2626 _ = &linux.send;
2727 _ = &linux.recv;
28 _ = &linux.getaddrinfo;
2829}