My computer is connected to the local network(ethernet adapter) with ip address 10.3.3.3 and it is connected with my VPN(PPP adapter) with the IP address 172.4.0.70
Now, how can I get my local IP(10.3.3.3) programmatically?
I had tested using the following code.
But I can't differentiate between the VPN and local network, any help will be much appreciated.
WSAData .....;
char* address=NULL;
getLocalIP(&address);
int getLocalIP(char** raddr)
{
char ac[80];
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR)
{
return 1;
}
struct hostent *phe = gethostbyname(ac);
if (phe == 0)
{
return 1;
}
for (int i = 0; phe->h_addr_list[i] != 0; ++i)
{
struct in_addr addr;
memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));
//How can I tell if it's not VPN?
//if (isnotVPN){
*raddr=inet_ntoa(addr); //<== ip address
//break;}
}
return 0;
}
c++ VS2008 Win7 64bits