Hi,
I'm often deploying server apps on the IPv6 stack, and I find that Nim is quite lacking in this regard. I believe by default, sockets are only bound to AF_INET (which means IPv4 only) while normally on C it defaults to AF_UNSPEC if not manually defined (which means dual stack). I opened a bug here: https://github.com/nim-lang/Nim/issues/22442
Is there a reason behind this default value chosen for the stdlib? It seems that AF_UNSPEC does not even work.
If the default is changed, I believe this might be a breaking change. I'm willing to work on the topic in my spare time for the linux platform but how do you even go about telling the compiler to use a different stdlib?
I'm getting dual-stack wrong...
The correct way of doing things is to:
The problem is that the Nim standard library does things in the wrong order, it first creates the socket (and you have to choose AF_INET or AF_INET6 before resolving the DNS and knowing if it will be IPv4 or IPv6). When resolving the address, if the address type does not match it will not work.
A solution could be to have newSocket not actually create the socket until either bind`or `connect/connectUnix is called, and then detect the correct socket domain from the address given in each case.
Or instead of going through newSocket and connect one should just use dial to create the correct socket and connect to it.
The problem is that the Nim standard library does things in the wrong order, it first creates the socket (and you have to choose AF_INET or AF_INET6 before resolving the DNS and knowing if it will be IPv4 or IPv6). When resolving the address, if the address type does not match it will not work.
Yah, it's a bit annoying working with dual stack. I've come to like IPv6 though. It works nicely in number of scenarios.
One limit with connect and not providing a string seems to be ssl support. :/
The ability to do use AF_UNSPEC could be handy in newSocket though.