Reputation: 512
gethostbyname
works when doing gethostbyname("www.google.com")
but when doing it like:
char *name = "www.google.com";
gethostbyname(name);
The connection is timing out. I am making sure my string is trimmed before the function to ensure that there is not any funky characters in it. I don't understand the issue.
Upvotes: 0
Views: 731
Reputation: 81
#include <stdio.h>
#include <netdb.h>
int main()
{
char *name = "www.google.com";
struct hostent* test = gethostbyname(name);
printf("%s\n", test->h_name);
return 0;
}
is what I tried, and it worked fine:
www.google.com
Maybe show the code and we can see if the problem lies somewhere else.
Upvotes: 1