'gethostname function always returns nullptr
I am attempting to resolve a hostname in C in windows. No matter what I enter in as the address it always returns a nullptr. I have tried the same function in a python interpreter and it works fine, so there is nothing wrong outside of this function that would cause it to be unable to resolve a DNS. Even "localhost" fails aswell. Attempting to access anything in the host variables causes a crash.
struct hostent* host = gethostbyname("google.com");
if (host) {
printf("Yes\n");
}
else {
printf("No\n"); // Always gets here
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
