Server machine has more than one IP where one IP is connected with local LAN and Other is connected with WAN(Internet).
Server Application need to bind the IP and Port so that it can listen to the Client. I am able to get the All Ip in ther server machine but facing problem in finding the the active IP i.e. IP connected internet.
following code will give all the IP in the system.
char chHostName[MAX_PATH];
if ( gethostname(chHostName, sizeof(chHostName)) == SOCKET_ERROR)
{
return ;
}
struct hostent *phe = gethostbyname(chHostName);
if (phe == 0)
{
return ;
}
//struct in_addr addrLocalIP;
for (int i = 0; phe->h_addr_list[i] != 0; ++i)
{
memcpy(&m_addrLocal.sin_addr.S_un, phe->h_addr_list[i], sizeof(struct in_addr));
}
1. Is there any way to find the IP which is connected with internet among many IP in the system.
2. Is last IP fetched through the above program is always the IP which is connected with Internet?