Hi,
I can get the IP of a remote host (e.g.
google.com) perfectly, so my
wifi and permissions seems set up correctly.
But using the code below, I only get 127.0.0.1 as a local IP address.
What am I doing wrong?
Thank you for helping.
// --------------- START CODE ----------------------------------
// no idea what this does, but I think I need that.
setenv("ANDROID_DNS_MODE", "local", 1);
char alladdr[16 * MAXHOSTNAMELEN];
alladdr[0]='\0';
struct addrinfo hints, *res=NULL;
int status;
// will return "localhost"
if(gethostname(alladdr, MAXHOSTNAMELEN) == SOCKET_ERROR)
return;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; // AF_INET (IPv4) or AF_INET6 (IPv6) to
force version
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo(alladdr, NULL, &hints, &res)) != 0)
return;
for(struct addrinfo *p = res;p != NULL; p = p->ai_next)
{
sockaddr_in* sin = (sockaddr_in*)p->ai_addr;
sprintf_IP(tmp, &sin->sin_addr); // only one loop, with 127.0.0.1
}
freeaddrinfo(res);
// --------------- END CODE ----------------------------------