= Obtaining Interface Information = This is based on an answer posted to the RTEMS User's mailing list by [wiki:ThomasRauscher ThomasRauscher] http://www.rtems.com/ml/rtems-users/2004/november/msg00255.html. '''Question:''' What is the best way to obtain my IP address, MAC Address, Network Mask, and Default Gateway after the ''rtems''bsdnet''initialize''network()_ call? I want to be able to access this information from software. '''Answer:''' This should do the trick. 'ifname' should contain the name of your interface, e.g. "eth0", 'addr' then contains the result. {{{ #include #include #include #include #include int get_ifaddr(const char *ifname, struct in_addr *addr) { int fd; int rc; struct ifreq ifreq; struct sockaddr_in *sockaddr; fd = socket(AF_INET, SOCK_DGRAM, 0); if(fd<0) { return -1; } strcpy(ifreq.ifr_name, ifname); rc = ioctl(fd, SIOCGIFADDR, &ifreq); if(rc == 0) { sockaddr = (struct sockaddr_in *) &ifreq.ifr_ifru.ifru_addr; memcpy(addr, &sockaddr->sin_addr, sizeof(*addr)); } close(fd); return (rc==0) ? 0 : -1; } }}}