diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-10-30 12:33:47 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-10-30 12:33:47 -0400 |
| commit | f5ff36271bce54eaec6f20cdff4fa4efb833c0d4 (patch) | |
| tree | 8773174d52c67f23b723a1f59a437fc6c6d52b58 /lib/std/net.zig | |
| parent | 0fb1388031ec98af77fe5e0ae8459c983010d1a8 (diff) | |
| parent | 4e0c2ed443a0c13030decf8a9d53aff28f415005 (diff) | |
| download | zig-f5ff36271bce54eaec6f20cdff4fa4efb833c0d4.tar.gz zig-f5ff36271bce54eaec6f20cdff4fa4efb833c0d4.zip | |
Merge branch 'testAddresses' of https://github.com/marler8997/zig into std.net
Diffstat (limited to 'lib/std/net.zig')
| -rw-r--r-- | lib/std/net.zig | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/std/net.zig b/lib/std/net.zig index 5b1037633c..c741941328 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -29,16 +29,30 @@ pub const Address = struct { //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0); pub fn initIp4(ip4: u32, _port: u16) Address { - return Address{ - .os_addr = os.sockaddr{ - .in = os.sockaddr_in{ - .family = os.AF_INET, - .port = mem.nativeToBig(u16, _port), - .addr = ip4, - .zero = [_]u8{0} ** 8, + switch (builtin.os) { + .macosx, .ios, .watchos, .tvos, .freebsd, .netbsd => 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, + .zero = [_]u8{0} ** 8, + }, }, }, - }; + .linux => return Address{ + .os_addr = os.sockaddr{ + .in = os.sockaddr_in{ + .family = os.AF_INET, + .port = mem.nativeToBig(u16, _port), + .addr = ip4, + .zero = [_]u8{0} ** 8, + }, + }, + }, + else => @compileError("Address.initIp4 not implemented for this platform"), + } } pub fn initIp6(ip6: Ip6Addr, _port: u16) Address { |
