The code I used show below:
ANSICHAR HostName[256];
gethostname(HostName,256);
struct addrinfo *AddrInfo = NULL;
getaddrinfo(HostName, NULL, NULL, &AddrInfo);
for (struct addrinfo *i = AddrInfo; i != NULL; i = i->ai_next)
{
if (i->ai_family == AF_INET)
{
const in_addr &IP = ((sockaddr_in *) i->ai_addr)->sin_addr;
if (IP.s_addr != 0)
{
Addr.SetIp(IP);
break;
}
}
}
The problem is "HostName" got by "gethostname(HostName,256)" is "localhost". So the final IP I get is "127.0.0.1". It diffent between the IP address I get used "adb shell ifconfig wlan0".
How can I get the correct IP address?