Skip to content

Conversation

@Frixuu
Copy link
Contributor

@Frixuu Frixuu commented Oct 21, 2024

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:

  • Added 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)
  • Added sys.net.Ipv6Address. This class is similar, but works on IPv6 addresses. (NO SCOPE ID SUPPORT IS INCLUDED)
  • Added 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).
  • Added sys.net.Dns. I've found most of the current platform-specific implementation of sys.net.Host is resolving and reversing hostnames, so it made sense to me to extract those to a separate module.
  • Changed sys.net.Host.
    • This class now has a single target-independent implementation.
    • Added Host.addresses, as a single hostname can be resolved to many addresses at once (e.g. one IPv4 and one IPv6).
  • Changed sys.net.Socket implementations.
    • On platforms that appear to support IPv6 (eval, jvm, python) Socket should, in theory, be able to bind and connect to IPv6 interfaces.
    • On platforms that do not support IPv6 (hl, neko) Socket should throw when provided an IPv6 address.
    • Node.js implementation lives in a separate repository and was left unchanged at this time (that's why the build fails).

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).
  • No Unix socket addresses capabilities were added.
  • sys.net.Socket.bind still accepts a Host, not an IpAddress nor an Address.

@Frixuu Frixuu closed this Oct 21, 2024
@skial skial mentioned this pull request Oct 31, 2024
1 task
@Frixuu Frixuu changed the title [std] [WIP] Add proper IP address types [wip, waiting for proposal] [std] add proper ip address types Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant