Changes:
- Renamed `--no-std` flag to `--no-core`, since Onyx does not call its standard
library "std", the name did not make any sense.
+- `net.make_ipv4_address` now has a reasonable definition using a string for the IP,
+ instead of an integer.
Bugfixes:
- Formatting of days and months were incorrect `time.strftime`.
};
}
-make_ipv4_address :: (out: &SocketAddress, addr: u32, port: u16) {
- n := (addr & 0xFF) << 24
- | (addr & 0xFF00) << 8
- | (addr & 0xFF0000) >> 8
- | (addr & 0xFF000000) >> 24;
+make_ipv4_address :: #match #local {}
- *out = .{ Inet = .{ port = port, addr = n } };
+#overload
+make_ipv4_address :: (addr: str, port: u16) -> SocketAddress {
+ ip := str_to_ipv4(addr);
+
+ return .{ Inet = .{ port = port, addr = ip } };
+}
+
+#overload
+make_ipv4_address :: (out: &SocketAddress, addr: str, port: u16) {
+ ip := str_to_ipv4(addr);
+
+ *out = .{ Inet = .{ port = port, addr = ip } };
}
make_unix_address :: (out: &SocketAddress, path: str) {
return .{ Some = .{ sender_addr, res.Ok->unwrap() } };
}
-// TODO: Add these back
-// host_to_network :: #match #local {}
-// #match host_to_network (x: u16) => __net_host_to_net_s(x);
-// #match host_to_network (x: u32) => __net_host_to_net_l(x);
-
-// network_to_host :: #match #local {}
-// #match network_to_host (x: u16) => __net_net_to_host_s(x);
-// #match network_to_host (x: u32) => __net_net_to_host_l(x);
#local __net_socket_vtable := io.Stream_Vtable.{
read = (use s: &Socket, buffer: [] u8) -> (io.Error, u32) {
ip_ := ip;
res: u32;
+ shift := 0;
for 4 {
octet := string.read_until(&ip_, #char ".");
string.advance(&ip_, 1);
- res = res << 8;
- res |= ~~(conv.str_to_i64(octet) & cast(i64) 0xFF);
+ res |= cast(u32) (conv.str_to_i64(octet) & cast(i64) 0xFF) << shift;
+ shift += 8;
}
return res;
tcp_server_listen :: (use server: &TCP_Server, port: u16) -> bool {
sa: SocketAddress;
- make_ipv4_address(&sa, 0x00000000, port);
+ make_ipv4_address(&sa, "0.0.0.0", port);
if !socket->bind(&sa) do return false;
socket->listen();