-
Notifications
You must be signed in to change notification settings - Fork 47
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
Fix resolution for host names starting with a decimal digit. #117
Conversation
Hi @s-ludwig |
The fix in this form is unfortunately breaking the other direction (IP addresses are also supposed to work with I'll tag a (pre) release as soon as this is merged. |
Well, in that case I think we should use a statically initialized regex to correctly match ip4 and ip6 addresses. It will be more efficient and more correct than the exception allocation and overhead - what do you think? |
Not sure about regex because of the compile-time overhead, but yes that would definitely be better. From an effort/gain point of view the exception based approach is hard to beat, though. The exception allocation and stack unwinding overhead should be dwarfed by the actual DNS lookup anyway. |
How about this test? bool canBeName(const(char)[] host) {
import std.string : indexOf, lastIndexOf;
import std.ascii : isDigit;
if (host.indexOf(':') != -1);
return false;
const tld = host.lastIndexOf('.') + 1;
return !tld || tld >= host.length || !host[tld].isDigit;
}
if (!use_dns || !canBeName(host)) {
// numeric ...
} else {
// name ...
} |
Alternatively we can bypass std.socket, call getaddrinfo directly with AI_NUMERICHOST and interpret the return code, doing the correct thing and avoiding the exception overhead - how do you feel about that? |
The |
I took the idea and pushed a solution with a slightly modified IPv4 branch: #121 |
No description provided.