diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/c/darwin.zig | 55 | ||||
| -rw-r--r-- | lib/std/net.zig | 41 | ||||
| -rw-r--r-- | lib/std/os/bits/darwin.zig | 16 |
3 files changed, 98 insertions, 14 deletions
diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index ebd12a0d86..391939aba7 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -56,3 +56,58 @@ pub fn sigaddset(set: *sigset_t, signo: u5) void { } pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; + +/// get address to use bind() +pub const AI_PASSIVE = 0x00000001; + +/// fill ai_canonname +pub const AI_CANONNAME = 0x00000002; + +/// prevent host name resolution +pub const AI_NUMERICHOST = 0x00000004; + +/// prevent service name resolution +pub const AI_NUMERICSERV = 0x00001000; + +/// address family for hostname not supported +pub const EAI_ADDRFAMILY = 1; + +/// temporary failure in name resolution +pub const EAI_AGAIN = 2; + +/// invalid value for ai_flags +pub const EAI_BADFLAGS = 3; + +/// non-recoverable failure in name resolution +pub const EAI_FAIL = 4; + +/// ai_family not supported +pub const EAI_FAMILY = 5; + +/// memory allocation failure +pub const EAI_MEMORY = 6; + +/// no address associated with hostname +pub const EAI_NODATA = 7; + +/// hostname nor servname provided, or not known +pub const EAI_NONAME = 8; + +/// servname not supported for ai_socktype +pub const EAI_SERVICE = 9; + +/// ai_socktype not supported +pub const EAI_SOCKTYPE = 10; + +/// system error returned in errno +pub const EAI_SYSTEM = 11; + +/// invalid value for hints +pub const EAI_BADHINTS = 12; + +/// resolved protocol is unknown +pub const EAI_PROTOCOL = 13; + +/// argument buffer overflow +pub const EAI_OVERFLOW = 14; +pub const EAI_MAX = 15; diff --git a/lib/std/net.zig b/lib/std/net.zig index c741941328..1109d17411 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -30,10 +30,9 @@ pub const Address = struct { pub fn initIp4(ip4: u32, _port: u16) Address { switch (builtin.os) { - .macosx, .ios, .watchos, .tvos, .freebsd, .netbsd => return Address{ + .linux => return Address{ .os_addr = os.sockaddr{ .in = os.sockaddr_in{ - .len = @sizeOf(os.sockaddr_in), .family = os.AF_INET, .port = mem.nativeToBig(u16, _port), .addr = ip4, @@ -41,9 +40,10 @@ pub const Address = struct { }, }, }, - .linux => return Address{ + else => return Address{ .os_addr = os.sockaddr{ .in = os.sockaddr_in{ + .len = @sizeOf(os.sockaddr_in), .family = os.AF_INET, .port = mem.nativeToBig(u16, _port), .addr = ip4, @@ -51,22 +51,35 @@ pub const Address = struct { }, }, }, - else => @compileError("Address.initIp4 not implemented for this platform"), } } pub fn initIp6(ip6: Ip6Addr, _port: u16) Address { - return Address{ - .os_addr = os.sockaddr{ - .in6 = os.sockaddr_in6{ - .family = os.AF_INET6, - .port = mem.nativeToBig(u16, _port), - .flowinfo = 0, - .addr = ip6.addr, - .scope_id = ip6.scope_id, + switch (builtin.os) { + .linux => return Address{ + .os_addr = os.sockaddr{ + .in6 = os.sockaddr_in6{ + .family = os.AF_INET6, + .port = mem.nativeToBig(u16, _port), + .flowinfo = 0, + .addr = ip6.addr, + .scope_id = ip6.scope_id, + }, }, }, - }; + else => return Address{ + .os_addr = os.sockaddr{ + .in6 = os.sockaddr_in6{ + .len = @sizeOf(os.sockaddr_in6), + .family = os.AF_INET6, + .port = mem.nativeToBig(u16, _port), + .flowinfo = 0, + .addr = ip6.addr, + .scope_id = ip6.scope_id, + }, + }, + }, + } } pub fn port(self: Address) u16 { @@ -1126,7 +1139,7 @@ fn resMSendRc( }}; const retry_interval = timeout / attempts; var next: u32 = 0; - var t2: usize = std.time.milliTimestamp(); + var t2: u64 = std.time.milliTimestamp(); var t0 = t2; var t1 = t2 - retry_interval; diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index fe3156bb90..beb0c602a9 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -11,6 +11,7 @@ pub const socklen_t = u32; pub const sockaddr = extern union { in: sockaddr_in, in6: sockaddr_in6, + un: sockaddr_un, }; pub const sockaddr_in = extern struct { len: u8, @@ -27,6 +28,10 @@ pub const sockaddr_in6 = extern struct { addr: [16]u8, scope_id: u32, }; +pub const sockaddr_un = extern struct { + len: u8, + family: sa_family_t, +}; pub const timeval = extern struct { tv_sec: c_long, @@ -1192,3 +1197,14 @@ pub const AT_SYMLINK_FOLLOW = 0x0040; /// Path refers to directory pub const AT_REMOVEDIR = 0x0080; + +pub const addrinfo = extern struct { + flags: i32, + family: i32, + socktype: i32, + protocol: i32, + addrlen: socklen_t, + canonname: ?[*]u8, + addr: ?*sockaddr, + next: ?*addrinfo, +}; |
