summaryrefslogtreecommitdiffstats
path: root/libnetutils
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2011-01-27 15:59:52 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-27 15:59:52 -0800
commitb42db825e103b1c37107bf8cd9a35fe4b8a07a13 (patch)
tree1be7d443876eac3f8e020ec721a7081a9736a0cf /libnetutils
parent56fc4c98531beac24114fa4daf52d776d4314532 (diff)
parent9092b91ccaa4c6069036f72163e6473a5ca408c4 (diff)
downloadsystem_core-b42db825e103b1c37107bf8cd9a35fe4b8a07a13.zip
system_core-b42db825e103b1c37107bf8cd9a35fe4b8a07a13.tar.gz
system_core-b42db825e103b1c37107bf8cd9a35fe4b8a07a13.tar.bz2
Merge "libnetutils: Clean all IPs assigned to the interface on cleaning"
Diffstat (limited to 'libnetutils')
-rw-r--r--libnetutils/ifc_utils.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 8076496..6788391 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -189,6 +189,23 @@ int ifc_set_mask(const char *name, in_addr_t mask)
return ioctl(ifc_ctl_sock, SIOCSIFNETMASK, &ifr);
}
+int ifc_get_addr(const char *name, in_addr_t *addr)
+{
+ struct ifreq ifr;
+ int ret = 0;
+
+ ifc_init_ifr(name, &ifr);
+ if (addr != NULL) {
+ ret = ioctl(ifc_ctl_sock, SIOCGIFADDR, &ifr);
+ if (ret < 0) {
+ *addr = 0;
+ } else {
+ *addr = ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr;
+ }
+ }
+ return ret;
+}
+
int ifc_get_info(const char *name, in_addr_t *addr, in_addr_t *mask, unsigned *flags)
{
struct ifreq ifr;
@@ -312,11 +329,20 @@ int ifc_enable(const char *ifname)
int ifc_disable(const char *ifname)
{
+ unsigned addr, count;
int result;
ifc_init();
result = ifc_down(ifname);
+
ifc_set_addr(ifname, 0);
+ for (count=0, addr=1;((addr != 0) && (count < 255)); count++) {
+ if (ifc_get_addr(ifname, &addr) < 0)
+ break;
+ if (addr)
+ ifc_set_addr(ifname, 0);
+ }
+
ifc_close();
return result;
}