libnetutils: Clean all IPs assigned to the interface on cleaning
Change-Id: Ic285bbb4b224fc4e62e88e76b8b448edbe814a17 Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
This commit is contained in:
parent
7d05a80da8
commit
9092b91cca
2 changed files with 27 additions and 0 deletions
|
@ -36,6 +36,7 @@ extern int ifc_disable(const char *ifname);
|
|||
|
||||
extern int ifc_reset_connections(const char *ifname);
|
||||
|
||||
extern int ifc_get_addr(const char *name, in_addr_t *addr);
|
||||
extern int ifc_set_addr(const char *name, in_addr_t addr);
|
||||
extern int ifc_set_mask(const char *name, in_addr_t mask);
|
||||
extern int ifc_set_hwaddr(const char *name, const void *ptr);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue