Hi,
I'm having a nightmare doing something so, so simple in C++. All I want to do is input a hostname, and get its IP address. It is not something which should take hours and hours to work out.
Regardless whether I use the deprecated gethostbyname() or getaddrinfo(), nothing works. gethostbyname() returns 0.0.0.0, which is obviously wrong, and getaddrinfo() doesn't return anything at all. I don't want to use deprecated code, but neither works anyway.
What I have tried:
I've tried so, so many different variations of the same code, in excess of 20 by now. The most recent is
struct addrinfo hints {}, *res{}, *res0{};
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo("www.google.com", "http", &hints, &res0);
ip_address = res->ai_addr->sa_data;
freeaddrinfo(res0);