Commit Graph

129 Commits

Author SHA1 Message Date
gingerBill
842cfee0f3 Change Odin's LICENSE to zlib from BSD 3-clause
This change was made in order to allow things produced with Odin and using Odin's core library, to not require the LICENSE to also be distributed alongside the binary form.
2025-10-28 14:38:25 +00:00
Jeroen van Rijn
7a9ea3ee6d Further overhaul of package line comments. 2025-10-09 23:05:29 +02:00
Jeroen van Rijn
8a35acd506 More package lines. 2025-10-09 20:11:06 +02:00
gingerBill
7642e0a0e0 Require @(init) and @(fini) to be proc "contextless" () 2025-08-08 12:10:01 +01:00
Harold Brenes
219b0fe535 Replace system:System.framework imports with system:System
This makes the linker work for both macOS and iOS targets
2025-07-13 15:45:21 -04:00
Jeroen van Rijn
a65ece4426 Allow core:net to be imported with -default-to-panic-allocator. 2025-06-17 15:36:17 +02:00
Jeroen van Rijn
6d01aa9069 Appease -vet for haiku 2025-06-16 23:30:22 +02:00
Jeroen van Rijn
9c9380d158 Merge pull request #5315 from peperronii/master
Expose getpeername() in core:net package as "peer_endpoint"
2025-06-16 11:30:34 +02:00
PePerRoNii
acdab793d9 Added Socket_Info_Error to Network_Error union 2025-06-16 16:17:48 +07:00
PePerRoNii
c08d9c50c8 Changed TCP_Recv_Err to Socket_Info_Err and tested on darwin_arm64 2025-06-15 12:14:59 +07:00
PePerRoNii
42aa8ac383 Implemented _socket_info_error on peer_endpoint and bound_endpoint 2025-06-15 11:17:49 +07:00
PePerRoNii
f49bf1abd2 added Socket_Info_Errors Enum 2025-06-15 10:26:06 +07:00
Jeroen van Rijn
3862555153 Replace core:posix usage in core:os/os2 2025-06-13 17:49:05 +02:00
PePerRoNii
a32ee6af97 added linux implementation NOTE: tcp_recv_error doesn't cover all cases 2025-06-11 13:10:37 +07:00
PePerRoNii
297fdd4075 added freebsd implementation NOTE: bsd's tcp_recv_error does not cover all cases 2025-06-11 13:05:16 +07:00
PePerRoNii
7ba4427d52 added windows implementation 2025-06-11 12:57:22 +07:00
PePerRoNii
5e11af9676 added darwin implementation 2025-06-11 12:50:20 +07:00
PePerRoNii
c402ac8606 Add entry point in core:net as peer_endpoint 2025-06-11 12:44:17 +07:00
Feoramund
b7de15caa3 Clarify strconv.append_* to strconv.write_* 2025-06-05 16:56:00 -04:00
Jeroen van Rijn
bc86b50392 Replace default_tcp_options with constant (#5056)
Replace `default_tcp_options` with constant
2025-04-19 14:32:59 +02:00
Laytan
11da543f26 net: add ECONNRESET to the error handling of recv 2025-04-14 21:17:22 +02:00
Laytan Laats
ff7d55a8e1 net: rework errors to be cross-platform 2025-04-05 17:35:19 +02:00
Laytan Laats
327d9f134d net: drop core:os dependency for Darwin 2025-03-29 23:27:03 +01:00
Christiano Haesbaert
42d7e7a402 Fix multiple vulnerabilities in the resolver
This fixes some vulnerabilities in the resolver that make spoofing DNS
queries somewhat trivial due to the code failing to randomize xid, as
well as match the reply xid with the query, and the origin of the packet:

 - xid of the query was fixed at zero
 - xid from the reply was never checked
 - source address of the reply was never checked

This means anyone can flood the host with a fake reply with xid 0,
guessing the source port is trivial as it's less than 16bits (2^16 -
1024), which would cause odin to resolve a hostname to whatever an
attacker wanted.

While here also plug in two memory leaks.

Since this is CVE material, I've contacted @kelimion before hand which
instructed to put it in a PR.

There are also more bugs as the code conflates answer section,
authority section and aditional section into one, while in reality
only the anwer section should be taken into consideration.
2025-02-23 17:28:32 +01:00
Jeroen van Rijn
940da61869 Fix missing error when TCP connection refused.
Fixes #4867
2025-02-23 12:47:22 +01:00
Jeroen van Rijn
963663b8e1 Merge pull request #4814 from haesbaert/dns-cleanup
Cleanup allocated dns runtime data
2025-02-09 02:12:02 +01:00
Christiano Haesbaert
cd53949c92 Cleanup allocated dns runtime data
While harmless, the runtime should clean up non-user allocated data.
On the same veign of: https://github.com/odin-lang/Odin/pull/4680

I'm kinda new to Odin and wrote netcat, in order to get a clean valgrind run,
one has to manually destroy dns_configuration:
https://github.com/haesbaert/learn-odin/blob/main/netcat/netcat.odin#L168-L169

While here unexport the destroy procedure and make destruction idempotent.
2025-02-09 00:26:25 +01:00
Christiano Haesbaert
605527f9db Fix some compression bugs in dns.
- A compression pointer is when the two higher bits are set, the code was
   considering only 0xC0 as a pointer, where in reality anything from 0xC0-0xFF is
   a pointer, probably went unnoticed since you need big packets to have long pointers.
 - Make sure we can access the lower byte of the pointer by checking len, the
   code was careful to not access past the first byte, but ignored the second.
 - As per RFC9267 make sure a pointer only points backwards, this one is not so
   bad, as the code had a iteration_max that ended up guarding against infinite jumps.

Lightly tested, some eyes are welcome, but these are remote DOSable.
2025-02-09 00:00:11 +01:00
Jeroen van Rijn
0683a3d672 Merge pull request #4681 from haesbaert/sockaddr
Add net.dial_tcp_from_host{_or_endpoint} and unify them
2025-02-08 12:45:02 +01:00
Jeroen van Rijn
cc29bdaefc Simplify *nix mDNS 2025-01-27 23:04:15 +01:00
Jeroen van Rijn
8998d74a92 Add mDNS for *nix. 2025-01-27 22:55:48 +01:00
Jeroen van Rijn
d85c2c1ca7 Add mDNS/Bonjour/Avahi (.local) support for Windows 2025-01-27 22:16:24 +01:00
Christiano Haesbaert
5699c533c6 Add net.dial_tcp_from_host{_or_endpoint} and unify them
The main motivation for this is to have sinergy with flags parsing, currently
flags for a sockaddr returns a net.Host_Or_Endpoint, but we can't just dial
from it since there isn't a variant.

Consider the following:

```
Options :: struct {
	target: net.Host_Or_Endpoint `args:"pos=0,required" usage:"host:port"`,
}

before :: proc() -> (sock: net.TCP_Socket, err: net.Network_Error) {
	opt: Options

	flags.parse_or_exit(&opt, os.args)
	switch t in opt.target {
	case net.Host:
		sock, err = net.dial_tcp(t.hostname, t.port)
	case net.Endpoint:
		sock, err = net.dial_tcp(t)
	}
	return
}

after :: proc() -> (sock: net.TCP_Socket, err: net.Network_Error) {
	opt: Options

	flags.parse_or_exit(&opt, os.args)
	sock, err = net.dial_tcp(opt.target)
	return
}

```

For completion, add dial_tcp_from_host() and define the upper functions in terms
of the newly added ones, cuts one repeated block, now:

from_hostname_and_port_string is parse + from_host_or_endpoint
from_hostname_with_port_override is parse + override + from_host_or_endpoint
from_host is to_endpoint + from_endpoint
from_host_or_endpoint is from_endpoint or from_host
2025-01-12 02:41:35 +01:00
Laytan Laats
5c63617191 net: fix leaking sockets in listen_tcp if an error occurs 2024-10-08 21:08:14 +02:00
Laytan Laats
d8af35f01e net: fix leaking sockets in dial_tcp if connect errors 2024-10-08 21:01:57 +02:00
gingerBill
327ca2ab71 Merge pull request #4261 from laytan/net-bound-endpoint
net: add `bound_endpoint` procedure
2024-09-19 12:53:42 +01:00
Laytan Laats
652557bfcd net: add bound_endpoint procedure 2024-09-17 22:22:19 +02:00
Karl Zylinski
3d7b924260 Fix a few incorrectly placed build tags. 2024-09-14 18:41:05 +02:00
Karl Zylinski
19f0127e55 Moved all packages in core, base, vendor, tests and examples to use new #+ file tag syntax. 2024-09-14 18:27:49 +02:00
Laytan Laats
288312a812 core: improve package doc comments for the documentation generator 2024-09-03 19:59:04 +02:00
Jeroen van Rijn
0a825fc44d Improve SRV handling in dns_windows.odin 2024-08-24 18:43:25 +02:00
gingerBill
70932dc478 Merge pull request #4089 from laytan/riscv64
add support for linux_riscv64 and freestanding_riscv64
2024-08-22 11:20:03 +01:00
Laytan
06fb500dfe make sure net.Network_Error is of size 8 2024-08-20 15:52:07 +02:00
Laytan
ca6ef95b03 add support for linux_riscv64 and freestanding_riscv64 2024-08-20 14:06:40 +02:00
Jeroen van Rijn
cc24d2de3e Merge pull request #3810 from Feoramund/freebsd-core-net
Port `core:net` to FreeBSD
2024-08-09 09:50:05 +02:00
Feoramund
4c0ab09c9a Handle EPIPE in Darwin core:net 2024-08-05 13:15:08 -04:00
Feoramund
6cc7f3b451 Add FreeBSD Accept_Error.Would_Block alias 2024-08-05 13:00:44 -04:00
Feoramund
3512d7c672 Move Darwin MSG_NOSIGNAL to core:os 2024-08-05 12:49:12 -04:00
Feoramund
eba0774bf3 Prevent SIGPIPE on Darwin when writing to a closed core:net socket
Mimics behavior found on Linux implementation.
2024-08-05 12:23:09 -04:00
Feoramund
fe754af13d Add new contribution notes to core:net 2024-08-05 03:05:49 -04:00