]>
git.wh0rd.org - sysvinit.git/blob - src/ifdown.c
2 * ifdown.c Find all network interfaces on the system and
5 * Copyright (C) 1998 Miquel van Smoorenburg.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 char *v_ifdown
= "@(#)ifdown.c 1.11 02-Jun-1998 miquels@cistron.nl";
31 #include <sys/ioctl.h>
32 #include <sys/socket.h>
36 #include <netinet/in.h>
41 * First, we find all shaper devices and down them. Then we
42 * down all real interfaces. This is because the comment in the
43 * shaper driver says "if you down the shaper device before the
44 * attached inerface your computer will follow".
48 struct ifreq ifr
[MAX_IFS
];
54 if ((fd
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
55 fprintf(stderr
, "ifdown: ");
59 ifc
.ifc_len
= sizeof(ifr
);
62 if (ioctl(fd
, SIOCGIFCONF
, &ifc
) < 0) {
63 fprintf(stderr
, "ifdown: ");
64 perror("SIOCGIFCONF");
68 numif
= ifc
.ifc_len
/ sizeof(struct ifreq
);
70 for (shaper
= 1; shaper
>= 0; shaper
--) {
71 for (i
= 0; i
< numif
; i
++) {
73 if ((strncmp(ifr
[i
].ifr_name
, "shaper", 6) == 0)
76 if (strcmp(ifr
[i
].ifr_name
, "lo") == 0)
78 if (strchr(ifr
[i
].ifr_name
, ':') != NULL
)
81 /* Read interface flags */
82 if (ioctl(fd
, SIOCGIFFLAGS
, &ifr
[i
]) < 0) {
83 fprintf(stderr
, "ifdown: shutdown ");
84 perror(ifr
[i
].ifr_name
);
88 * Expected in <net/if.h> according to
89 * "UNIX Network Programming".
92 # define IRFFLAGS ifr_flags
93 #else /* Present on kFreeBSD */
94 # define IRFFLAGS ifr_flagshigh
96 if (ifr
[i
].IRFFLAGS
& IFF_UP
) {
97 ifr
[i
].IRFFLAGS
&= ~(IFF_UP
);
98 if (ioctl(fd
, SIOCSIFFLAGS
, &ifr
[i
]) < 0) {
99 fprintf(stderr
, "ifdown: shutdown ");
100 perror(ifr
[i
].ifr_name
);