How do I get the IP address of the local machine in C on Windows? I was not able to get the IP address of my machine in the following code:
#include <ifaddrs.h>
#include <stdio.h>
int main()
{
struct ifaddrs *id;
int val;
val = getifaddrs(&id);
printf("Network Interface Name :- %s\n",id->ifa_name);
printf("Network Address of %s :- %d\n",id->ifa_name,id->ifa_addr);
printf("Network Data :- %d \n",id->ifa_data);
printf("Socket Data : -%c\n",id->ifa_addr->sa_data);
return 0;
}
I am facing an error while compiling:
fatal error C1083: Cannot open include file: 'net/if.h': No such file or directory.
I cannot use #include <net/if.h>
as it is only available on Linux.