This will print the IP address of all the NICs in a PC.
struct in_addr addr;
struct hostent *phe;
char ac[80];
int i;
char *local;
// get the name of the local host
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
printf("Error getting local host name: %d\n",WSAGetLastError());
return 1;
}
printf("Host name is %s\n",ac);
phe = gethostbyname(ac);
if (phe == 0) {
cerr << "Error: Bad host lookup." << endl;
return 1;
}
for (i=0; phe->h_addr_list !=0; ++i) {
memcpy(&addr, phe->h_addr_list,sizeof(struct in_addr));
printf("Card %i) %s\n",i,inet_ntoa(addr));
local=inet_ntoa(addr);
}