September 2002
Intermediate to advanced
560 pages
13h 16m
English
These are implementation-specific, device-specific and Socket I/O routines that are provided here for completeness and full readability of code. No explanations are provided for these.
/********************************************************* NAME : get_dev_from_ip *********************************************************/ static uint32_t ifname_to_ip( char *ifname ) { struct ifreq ifr; int fd = socket(AF_INET, SOCK_DGRAM, 0); uint32_t addr = 0; if (fd < 0) return (-1); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) == 0) { struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr; addr = ntohl(sin->sin_addr.s_addr); } close(fd); return addr; } /********************************************************* ...Read now
Unlock full access