Skip to content
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

nativesockets.Domain et al should not be enum, AF_INET6 enum has some random value #23333

Open
arnetheduck opened this issue Feb 21, 2024 · 2 comments

Comments

@arnetheduck
Copy link
Contributor

Description

AF_INET6 = when defined(macosx): 30 else: 23 ## for network protocol IPv6.

Domains are platform-specific and do not form a closed set - when you read a domain from the list of addresses that any wrapped C api supports, you may get values that nim does not support which breaks the enum invariant meaning that using an enum for Domain constrains the native socket support to whatever nim happens to have supported at the time of inception whereas native sockets are more flexible - an enum domain could perhaps be suitable for some high-level library that only offers limited socket support (ie tcp/udp).

A better design would model domains etc as distinct open integers as they are represented in the underlying interface.

Even if the enum design is kept, the enum values should never be used to interface with the system - therefore, assigning random values like 23 and creating a holey enum serves no purpose - ie on linux, AF_INET6 has the value 10.

Nim Version

2.0

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

@litlighilit
Copy link
Contributor

litlighilit commented Feb 26, 2024

Why under Linux,

AF_INET6 with its value of 23 passing to newSocket can set up a ipv6 server

while AF_INET6 in C <sys/socket.h> is 10

?

@arnetheduck
Copy link
Contributor Author

toInt and toKnownDomain is the canonical way to convert a Domain to a platform-specific value:

proc toInt(domain: Domain): cint =

@ringabout ringabout removed their assignment Feb 27, 2024
Araq pushed a commit that referenced this issue Mar 3, 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

No branches or pull requests

3 participants