Skip to content

[wip, waiting for proposal] [std] add proper ip address types #11795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

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