#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <net/if.h>
// #include <netinet/in.h>
#include <arpa/inet.h>
// #include <ifaddrs.h> #define IF_NAME "eth0" int main(void)
{
struct ifreq ifr;
int skfd = ;
static char if_addr[]; if ((skfd = socket(AF_INET, SOCK_DGRAM, )) < ) {
} strcpy(ifr.ifr_name, IF_NAME);
if (ioctl(skfd, SIOCGIFADDR, &ifr) < ) {
close(skfd);
}
strcpy(if_addr, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
printf("ipaddr : %s\n", if_addr);
close(skfd); }