[wip, waiting for proposal] [std] add proper ip address types #11795
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
HaxeFoundation/haxe-evolution#123
This is a very early draft of how I personally imagine hypothetical
sys.net
improvements might look like. Names and assumptions are subject to change. Posted here in case somebody finds these ramblings useful.Changes included so far:
sys.net.Ipv4Address
. This class has helper methods for creating new IPv4 address objects, stringifying them, parsing, determining address type (link-local? multicast?). For increased compatibility, methods for converting them from/to a little-endian Int are also present. (NAMED INCORRECTLY)sys.net.Ipv6Address
. This class is similar, but works on IPv6 addresses. (NO SCOPE ID SUPPORT IS INCLUDED)sys.net.IpAddress
. This enum holds either an IPv4 or an IPv6 address. I've chosen an enum over a base class/interface for increased ergonomics (cannot miscast, inherit).sys.net.Dns
. I've found most of the current platform-specific implementation ofsys.net.Host
is resolving and reversing hostnames, so it made sense to me to extract those to a separate module.sys.net.Host
.Host.addresses
, as a single hostname can be resolved to many addresses at once (e.g. one IPv4 and one IPv6).sys.net.Socket
implementations.Socket
should, in theory, be able to bind and connect to IPv6 interfaces.Socket
should throw when provided an IPv6 address.Changes currently (2024-11) not included, for one reason or another:
sys.net.Address
keeps its name and still can only hold an IPv4 address (as an int).sys.net.Socket.bind
still accepts aHost
, not anIpAddress
nor anAddress
.