#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
int sock_fd;
struct my_addr;
struct ifreq ifr;
unsigned char * addr;
#define ETH_INTERFACE_NAME "eth0"
/**//* Get socket file descriptor */
if ((sock_fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)...{
perror("socket");
exit(1);
}
/**//* Get IP Address */
strncpy(ifr.ifr_name, ETH_INTERFACE_NAME, IF_NAMESIZE);
ifr.ifr_name[IFNAMSIZ-1]='/0';
if (ioctl(sock_fd, SIOCGIFADDR, &ifr) < 0)...{
perror("ioctl");
exit(1);
}
memcpy(&my_addr, &ifr.ifr_addr, sizeof(my_addr));
addr=inet_ntoa(my_addr.sin_addr);