summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kexec/ifdown.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/kexec/ifdown.c b/kexec/ifdown.c
index d480b3b..bc7f12f 100644
--- a/kexec/ifdown.c
+++ b/kexec/ifdown.c
@@ -19,8 +19,6 @@ char *v_ifdown = "@(#)ifdown.c 1.11 02-Jun-1998 miquels@cistron.nl";
#include <net/if.h>
#include <netinet/in.h>
-#define MAX_IFS 64
-
/*
* First, we find all shaper devices and down them. Then we
* down all real interfaces. This is because the comment in the
@@ -29,43 +27,45 @@ char *v_ifdown = "@(#)ifdown.c 1.11 02-Jun-1998 miquels@cistron.nl";
*/
int ifdown(void)
{
- struct ifreq ifr[MAX_IFS];
- struct ifconf ifc;
- int i, fd;
- int numif;
- int shaper;
+ struct if_nameindex *ifa, *ifp;
+ struct ifreq ifr;
+ int fd, shaper;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
fprintf(stderr, "ifdown: ");
perror("socket");
return -1;
}
- ifc.ifc_len = sizeof(ifr);
- ifc.ifc_req = ifr;
- if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
+ if ((ifa = if_nameindex()) == NULL) {
fprintf(stderr, "ifdown: ");
- perror("SIOCGIFCONF");
- close(fd);
+ perror("if_nameindex");
return -1;
}
- numif = ifc.ifc_len / sizeof(struct ifreq);
for (shaper = 1; shaper >= 0; shaper--) {
- for (i = 0; i < numif; i++) {
+ for (ifp = ifa; ifp->if_index; ifp++) {
- if ((strncmp(ifr[i].ifr_name, "shaper", 6) == 0)
+ if ((strncmp(ifp->if_name, "shaper", 6) == 0)
!= shaper) continue;
-
- if (strcmp(ifr[i].ifr_name, "lo") == 0)
+ if (strcmp(ifp->if_name, "lo") == 0)
continue;
- if (strchr(ifr[i].ifr_name, ':') != NULL)
+ if (strchr(ifp->if_name, ':') != NULL)
continue;
- ifr[i].ifr_flags &= ~(IFF_UP);
- if (ioctl(fd, SIOCSIFFLAGS, &ifr[i]) < 0) {
+
+ strncpy(ifr.ifr_name, ifp->if_name, IFNAMSIZ);
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
fprintf(stderr, "ifdown: shutdown ");
- perror(ifr[i].ifr_name);
+ perror(ifp->if_name);
+ return -1;
}
+ ifr.ifr_flags &= ~(IFF_UP);
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+ fprintf(stderr, "ifdown: shutdown ");
+ perror(ifp->if_name);
+ return -1;
+ }
+
}
}
close(fd);