diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2010-07-12 18:45:59 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-07-12 20:44:27 +0200 |
commit | 57cecbcc89e3df31600b6a769be6255c5916529f (patch) | |
tree | c39e767ca0599e1b05b87a001478beda58e6d2eb /src/inet.c | |
parent | 5c00b517f7dfcd8edef4819580fa21c38d19c2bc (diff) | |
download | connman-57cecbcc89e3df31600b6a769be6255c5916529f.tar.gz connman-57cecbcc89e3df31600b6a769be6255c5916529f.tar.bz2 connman-57cecbcc89e3df31600b6a769be6255c5916529f.zip |
No host route needed for nameservers on the same subnet
Diffstat (limited to 'src/inet.c')
-rw-r--r-- | src/inet.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -898,3 +898,50 @@ int connman_inet_clear_gateway_interface(int index) return err; } + +connman_bool_t connman_inet_compare_subnet(int index, const char *host) +{ + struct ifreq ifr; + struct in_addr _host_addr; + in_addr_t host_addr, netmask_addr, if_addr; + struct sockaddr_in *netmask, *addr; + int sk; + + DBG("host %s", host); + + if (host == NULL) + return FALSE; + + if (inet_aton(host, &_host_addr) == 0) + return -1; + host_addr = _host_addr.s_addr; + + sk = socket(PF_INET, SOCK_DGRAM, 0); + if (sk < 0) + return FALSE; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_ifindex = index; + + if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) { + close(sk); + return FALSE; + } + + if (ioctl(sk, SIOCGIFNETMASK, &ifr) < 0) { + close(sk); + return FALSE; + } + + netmask = (struct sockaddr_in *)&ifr.ifr_netmask; + netmask_addr = netmask->sin_addr.s_addr; + + if (ioctl(sk, SIOCGIFADDR, &ifr) < 0) { + close(sk); + return FALSE; + } + addr = (struct sockaddr_in *)&ifr.ifr_addr; + if_addr = addr->sin_addr.s_addr; + + return ((if_addr & netmask_addr) == (host_addr & netmask_addr)); +} |