2 * ifconfig This file contains an implementation of the command
3 * that either displays or sets the characteristics of
4 * one or more of the system's networking interfaces.
6 * Version: $Id: ifconfig.c,v 1.50 2001/04/13 18:25:18 pb Exp $
8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9 * and others. Copyright 1993 MicroWalt Corporation
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * Patched to support 'add' and 'del' keywords for INET(4) addresses
18 * by Mrs. Brisby <mrs.brisby@nimh.org>
20 * {1.34} - 19980630 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
21 * - gettext instead of catgets for i18n
22 * 10/1998 - Andi Kleen. Use interface list primitives.
23 * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu
24 * (default AF was wrong)
25 * 20010404 - Arnaldo Carvalho de Melo, use setlocale
28 #define DFLT_AF "inet"
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/ioctl.h>
37 #include <netinet/in.h>
39 #include <net/if_arp.h>
49 /* Ugh. But libc5 doesn't provide POSIX types. */
50 #include <asm/types.h>
54 #include <linux/if_slip.h>
61 * This is in linux/include/net/ipv6.h.
65 struct in6_addr ifr6_addr;
67 unsigned int ifr6_ifindex;
72 #endif /* HAVE_AFINET6 */
75 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
76 #include <netipx/ipx.h>
81 #include "net-support.h"
82 #include "pathnames.h"
85 #include "interface.h"
89 char *Release = RELEASE, *Version = "ifconfig 1.42 (2001-04-13)";
91 int opt_a = 0; /* show all interfaces */
92 int opt_i = 0; /* show the statistics */
93 int opt_v = 0; /* debugging output flag */
95 int addr_family = 0; /* currently selected AF */
97 /* for ipv4 add/del modes */
98 static int get_nmbc_parent(char *parent, unsigned long *nm,
100 static int set_ifstate(char *parent, unsigned long ip,
101 unsigned long nm, unsigned long bc,
104 static int if_print(char *ifname)
109 printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
112 res = for_all_interfaces(do_if_print, &opt_a);
114 struct interface *ife;
116 ife = lookup_interface(ifname);
117 res = do_if_fetch(ife);
124 /* Set a certain interface flag. */
125 static int set_flag(char *ifname, short flag)
129 safe_strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
130 if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
131 fprintf(stderr, _("%s: unknown interface: %s\n"),
132 ifname, strerror(errno));
135 safe_strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
136 ifr.ifr_flags |= flag;
137 if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
138 perror("SIOCSIFFLAGS");
144 /* Clear a certain interface flag. */
145 static int clr_flag(char *ifname, short flag)
150 if (strchr(ifname, ':')) {
151 /* This is a v4 alias interface. Downing it via a socket for
152 another AF may have bad consequences. */
153 fd = get_socket_for_af(AF_INET);
155 fprintf(stderr, _("No support for INET on this system.\n"));
161 safe_strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
162 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
163 fprintf(stderr, _("%s: unknown interface: %s\n"),
164 ifname, strerror(errno));
167 safe_strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
168 ifr.ifr_flags &= ~flag;
169 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
170 perror("SIOCSIFFLAGS");
176 static void usage(void)
178 fprintf(stderr, _("Usage:\n ifconfig [-a] [-i] [-v] [-s] <interface> [[<AF>] <address>]\n"));
180 fprintf(stderr, _(" [add <address>[/<prefixlen>]]\n"));
181 fprintf(stderr, _(" [del <address>[/<prefixlen>]]\n"));
182 fprintf(stderr, _(" [[-]broadcast [<address>]] [[-]pointopoint [<address>]]\n"));
183 fprintf(stderr, _(" [netmask <address>] [dstaddr <address>] [tunnel <address>]\n"));
185 #ifdef SIOCSKEEPALIVE
186 fprintf(stderr, _(" [outfill <NN>] [keepalive <NN>]\n"));
188 fprintf(stderr, _(" [hw <HW> <address>] [metric <NN>] [mtu <NN>]\n"));
189 fprintf(stderr, _(" [[-]trailers] [[-]arp] [[-]allmulti]\n"));
190 fprintf(stderr, _(" [multicast] [[-]promisc]\n"));
191 fprintf(stderr, _(" [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]\n"));
192 #ifdef HAVE_TXQUEUELEN
193 fprintf(stderr, _(" [txqueuelen <NN>]\n"));
196 fprintf(stderr, _(" [[-]dynamic]\n"));
198 fprintf(stderr, _(" [up|down] ...\n\n"));
200 fprintf(stderr, _(" <HW>=Hardware Type.\n"));
201 fprintf(stderr, _(" List of possible hardware types:\n"));
202 print_hwlist(0); /* 1 = ARPable */
203 fprintf(stderr, _(" <AF>=Address family. Default: %s\n"), DFLT_AF);
204 fprintf(stderr, _(" List of possible address families:\n"));
205 print_aflist(0); /* 1 = routeable */
209 static void version(void)
211 fprintf(stderr, "%s\n%s\n", Release, Version);
215 static int set_netmask(int skfd, struct ifreq *ifr, struct sockaddr *sa)
219 memcpy((char *) &ifr->ifr_netmask, (char *) sa,
220 sizeof(struct sockaddr));
221 if (ioctl(skfd, SIOCSIFNETMASK, ifr) < 0) {
222 fprintf(stderr, "SIOCSIFNETMASK: %s\n",
229 int main(int argc, char **argv)
232 struct sockaddr sanetmask;
233 struct sockaddr_in sin;
238 int goterr = 0, didnetmask = 0, gotnetmask;
242 extern struct aftype inet6_aftype;
243 struct sockaddr_in6 sa6;
244 struct in6_ifreq ifr6;
245 unsigned long prefix_len;
249 extern struct aftype inet_aftype;
253 setlocale (LC_ALL, "");
254 bindtextdomain("net-tools", "/usr/share/locale");
255 textdomain("net-tools");
258 /* Find any options. */
261 while (argc && *argv[0] == '-') {
262 if (!strcmp(*argv, "-a"))
265 else if (!strcmp(*argv, "-s"))
268 else if (!strcmp(*argv, "-v"))
271 else if (!strcmp(*argv, "-V") || !strcmp(*argv, "-version") ||
272 !strcmp(*argv, "--version"))
275 else if (!strcmp(*argv, "-?") || !strcmp(*argv, "-h") ||
276 !strcmp(*argv, "-help") || !strcmp(*argv, "--help"))
280 fprintf(stderr, _("ifconfig: option `%s' not recognised.\n"),
282 fprintf(stderr, _("ifconfig: `--help' gives usage information.\n"));
290 /* Create a channel to the NET kernel. */
291 if ((skfd = sockets_open(0)) < 0) {
296 /* Do we have to show the current setup? */
298 int err = if_print((char *) NULL);
302 /* No. Fetch the interface name. */
304 safe_strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
305 if (*spp == (char *) NULL) {
306 int err = if_print(ifr.ifr_name);
312 /* The next argument is either an address family name, or an option. */
313 if ((ap = get_aftype(*spp)) != NULL)
314 spp++; /* it was a AF name */
316 ap = get_aftype(DFLT_AF);
319 addr_family = ap->af;
323 /* Process the remaining arguments. */
324 while (*spp != (char *) NULL) {
325 if (!strcmp(*spp, "arp")) {
326 goterr |= clr_flag(ifr.ifr_name, IFF_NOARP);
330 if (!strcmp(*spp, "-arp")) {
331 goterr |= set_flag(ifr.ifr_name, IFF_NOARP);
336 if (!strcmp(*spp, "media") || !strcmp(*spp, "port")) {
339 if (!strcasecmp(*spp, "auto")) {
340 goterr |= set_flag(ifr.ifr_name, IFF_AUTOMEDIA);
344 newport = strtol(*spp, &endp, 10);
347 for (i = 0; if_port_text[i][0] && newport == -1; i++) {
348 for (j = 0; if_port_text[i][j]; j++) {
349 if (!strcasecmp(*spp, if_port_text[i][j])) {
358 fprintf(stderr, _("Unknown media type.\n"));
361 if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
362 perror("port: SIOCGIFMAP");
366 ifr.ifr_map.port = newport;
367 if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
368 perror("port: SIOCSIFMAP");
377 if (!strcmp(*spp, "trailers")) {
378 goterr |= clr_flag(ifr.ifr_name, IFF_NOTRAILERS);
382 if (!strcmp(*spp, "-trailers")) {
383 goterr |= set_flag(ifr.ifr_name, IFF_NOTRAILERS);
387 if (!strcmp(*spp, "promisc")) {
388 goterr |= set_flag(ifr.ifr_name, IFF_PROMISC);
392 if (!strcmp(*spp, "-promisc")) {
393 goterr |= clr_flag(ifr.ifr_name, IFF_PROMISC);
397 if (!strcmp(*spp, "multicast")) {
398 goterr |= set_flag(ifr.ifr_name, IFF_MULTICAST);
402 if (!strcmp(*spp, "-multicast")) {
403 goterr |= clr_flag(ifr.ifr_name, IFF_MULTICAST);
407 if (!strcmp(*spp, "allmulti")) {
408 goterr |= set_flag(ifr.ifr_name, IFF_ALLMULTI);
412 if (!strcmp(*spp, "-allmulti")) {
413 goterr |= clr_flag(ifr.ifr_name, IFF_ALLMULTI);
417 if (!strcmp(*spp, "up")) {
418 goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
422 if (!strcmp(*spp, "down")) {
423 goterr |= clr_flag(ifr.ifr_name, IFF_UP);
428 if (!strcmp(*spp, "dynamic")) {
429 goterr |= set_flag(ifr.ifr_name, IFF_DYNAMIC);
433 if (!strcmp(*spp, "-dynamic")) {
434 goterr |= clr_flag(ifr.ifr_name, IFF_DYNAMIC);
440 if (!strcmp(*spp, "metric")) {
443 ifr.ifr_metric = atoi(*spp);
444 if (ioctl(skfd, SIOCSIFMETRIC, &ifr) < 0) {
445 fprintf(stderr, "SIOCSIFMETRIC: %s\n", strerror(errno));
451 if (!strcmp(*spp, "mtu")) {
454 ifr.ifr_mtu = atoi(*spp);
455 if (ioctl(skfd, SIOCSIFMTU, &ifr) < 0) {
456 fprintf(stderr, "SIOCSIFMTU: %s\n", strerror(errno));
462 #ifdef SIOCSKEEPALIVE
463 if (!strcmp(*spp, "keepalive")) {
466 ifr.ifr_data = (caddr_t) atoi(*spp);
467 if (ioctl(skfd, SIOCSKEEPALIVE, &ifr) < 0) {
468 fprintf(stderr, "SIOCSKEEPALIVE: %s\n", strerror(errno));
477 if (!strcmp(*spp, "outfill")) {
480 ifr.ifr_data = (caddr_t) atoi(*spp);
481 if (ioctl(skfd, SIOCSOUTFILL, &ifr) < 0) {
482 fprintf(stderr, "SIOCSOUTFILL: %s\n", strerror(errno));
490 if (!strcmp(*spp, "-broadcast")) {
491 goterr |= clr_flag(ifr.ifr_name, IFF_BROADCAST);
495 if (!strcmp(*spp, "broadcast")) {
496 if (*++spp != NULL) {
497 safe_strncpy(host, *spp, (sizeof host));
498 if (ap->input(0, host, &sa) < 0) {
504 memcpy((char *) &ifr.ifr_broadaddr, (char *) &sa,
505 sizeof(struct sockaddr));
506 if (ioctl(ap->fd, SIOCSIFBRDADDR, &ifr) < 0) {
507 fprintf(stderr, "SIOCSIFBRDADDR: %s\n",
513 goterr |= set_flag(ifr.ifr_name, IFF_BROADCAST);
516 if (!strcmp(*spp, "dstaddr")) {
519 safe_strncpy(host, *spp, (sizeof host));
520 if (ap->input(0, host, &sa) < 0) {
526 memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa,
527 sizeof(struct sockaddr));
528 if (ioctl(ap->fd, SIOCSIFDSTADDR, &ifr) < 0) {
529 fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
536 if (!strcmp(*spp, "netmask")) {
537 if (*++spp == NULL || didnetmask)
539 safe_strncpy(host, *spp, (sizeof host));
540 if (ap->input(0, host, &sa) < 0) {
547 goterr = set_netmask(ap->fd, &ifr, &sa);
551 #ifdef HAVE_TXQUEUELEN
552 if (!strcmp(*spp, "txqueuelen")) {
555 ifr.ifr_qlen = strtoul(*spp, NULL, 0);
556 if (ioctl(skfd, SIOCSIFTXQLEN, &ifr) < 0) {
557 fprintf(stderr, "SIOCSIFTXQLEN: %s\n", strerror(errno));
565 if (!strcmp(*spp, "mem_start")) {
568 if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
569 fprintf(stderr, "mem_start: SIOCGIFMAP: %s\n", strerror(errno));
574 ifr.ifr_map.mem_start = strtoul(*spp, NULL, 0);
575 if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
576 fprintf(stderr, "mem_start: SIOCSIFMAP: %s\n", strerror(errno));
582 if (!strcmp(*spp, "io_addr")) {
585 if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
586 fprintf(stderr, "io_addr: SIOCGIFMAP: %s\n", strerror(errno));
591 ifr.ifr_map.base_addr = strtol(*spp, NULL, 0);
592 if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
593 fprintf(stderr, "io_addr: SIOCSIFMAP: %s\n", strerror(errno));
599 if (!strcmp(*spp, "irq")) {
602 if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
603 fprintf(stderr, "irq: SIOCGIFMAP: %s\n", strerror(errno));
608 ifr.ifr_map.irq = atoi(*spp);
609 if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
610 fprintf(stderr, "irq: SIOCSIFMAP: %s\n", strerror(errno));
616 if (!strcmp(*spp, "-pointopoint")) {
617 goterr |= clr_flag(ifr.ifr_name, IFF_POINTOPOINT);
621 if (!strcmp(*spp, "pointopoint")) {
622 if (*(spp + 1) != NULL) {
624 safe_strncpy(host, *spp, (sizeof host));
625 if (ap->input(0, host, &sa)) {
631 memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa,
632 sizeof(struct sockaddr));
633 if (ioctl(ap->fd, SIOCSIFDSTADDR, &ifr) < 0) {
634 fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
639 goterr |= set_flag(ifr.ifr_name, IFF_POINTOPOINT);
644 if (!strcmp(*spp, "hw")) {
647 if ((hw = get_hwtype(*spp)) == NULL)
649 if (hw->input == NULL) {
650 fprintf(stderr, _("hw address type `%s' has no handler to set address. failed.\n"), *spp);
657 safe_strncpy(host, *spp, (sizeof host));
658 if (hw->input(host, &sa) < 0) {
659 fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name);
664 memcpy((char *) &ifr.ifr_hwaddr, (char *) &sa,
665 sizeof(struct sockaddr));
666 if (ioctl(skfd, SIOCSIFHWADDR, &ifr) < 0) {
667 fprintf(stderr, "SIOCSIFHWADDR: %s\n",
674 #if HAVE_AFINET || HAVE_AFINET6
675 if (!strcmp(*spp, "add")) {
679 if (strchr(*spp, ':')) {
681 if ((cp = strchr(*spp, '/'))) {
682 prefix_len = atol(cp + 1);
683 if ((prefix_len < 0) || (prefix_len > 128))
689 safe_strncpy(host, *spp, (sizeof host));
690 if (inet6_aftype.input(1, host,
691 (struct sockaddr *) &sa6) < 0) {
692 inet6_aftype.herror(host);
697 memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
698 sizeof(struct in6_addr));
700 fd = get_socket_for_af(AF_INET6);
703 _("No support for INET6 on this system.\n"));
708 if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
709 perror("SIOGIFINDEX");
714 ifr6.ifr6_ifindex = ifr.ifr_ifindex;
715 ifr6.ifr6_prefixlen = prefix_len;
716 if (ioctl(fd, SIOCSIFADDR, &ifr6) < 0) {
717 perror("SIOCSIFADDR");
725 { /* ipv4 address a.b.c.d */
726 unsigned long ip, nm, bc;
727 safe_strncpy(host, *spp, (sizeof host));
728 if (inet_aftype.input(0, host, (struct sockaddr *)&sin) < 0) {
734 fd = get_socket_for_af(AF_INET);
737 _("No support for INET on this system.\n"));
743 memcpy(&ip, &sin.sin_addr.s_addr, sizeof(unsigned long));
745 if (get_nmbc_parent(ifr.ifr_name, &nm, &bc) < 0) {
746 fprintf(stderr, _("Interface %s not initialized\n"),
752 set_ifstate(ifr.ifr_name, ip, nm, bc, 1);
758 fprintf(stderr, _("Bad address.\n"));
763 #if HAVE_AFINET || HAVE_AFINET6
764 if (!strcmp(*spp, "del")) {
770 if (strchr(*spp, ':')) { /* INET6 */
771 if ((cp = strchr(*spp, '/'))) {
772 prefix_len = atol(cp + 1);
773 if ((prefix_len < 0) || (prefix_len > 128))
779 safe_strncpy(host, *spp, (sizeof host));
780 if (inet6_aftype.input(1, host,
781 (struct sockaddr *) &sa6) < 0) {
782 inet6_aftype.herror(host);
787 memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
788 sizeof(struct in6_addr));
790 fd = get_socket_for_af(AF_INET6);
793 _("No support for INET6 on this system.\n"));
798 if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
799 perror("SIOGIFINDEX");
804 ifr6.ifr6_ifindex = ifr.ifr_ifindex;
805 ifr6.ifr6_prefixlen = prefix_len;
806 if (ioctl(fd, SIOCDIFADDR, &ifr6) < 0) {
807 fprintf(stderr, "SIOCDIFADDR: %s\n",
817 /* ipv4 address a.b.c.d */
818 unsigned long ip, nm, bc;
819 safe_strncpy(host, *spp, (sizeof host));
820 if (inet_aftype.input(0, host, (struct sockaddr *)&sin) < 0) {
826 fd = get_socket_for_af(AF_INET);
828 fprintf(stderr, _("No support for INET on this system.\n"));
834 memcpy(&ip, &sin.sin_addr.s_addr, sizeof(unsigned long));
836 if (get_nmbc_parent(ifr.ifr_name, &nm, &bc) < 0) {
837 fprintf(stderr, _("Interface %s not initialized\n"),
843 set_ifstate(ifr.ifr_name, ip, nm, bc, 0);
848 fprintf(stderr, _("Bad address.\n"));
851 fprintf(stderr, _("Address deletion not supported on this system.\n"));
856 if (!strcmp(*spp, "tunnel")) {
859 if ((cp = strchr(*spp, '/'))) {
860 prefix_len = atol(cp + 1);
861 if ((prefix_len < 0) || (prefix_len > 128))
867 safe_strncpy(host, *spp, (sizeof host));
868 if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) {
869 inet6_aftype.herror(host);
874 memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
875 sizeof(struct in6_addr));
877 fd = get_socket_for_af(AF_INET6);
879 fprintf(stderr, _("No support for INET6 on this system.\n"));
884 if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
885 perror("SIOGIFINDEX");
890 ifr6.ifr6_ifindex = ifr.ifr_ifindex;
891 ifr6.ifr6_prefixlen = prefix_len;
893 if (ioctl(fd, SIOCSIFDSTADDR, &ifr6) < 0) {
894 fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
903 /* If the next argument is a valid hostname, assume OK. */
904 safe_strncpy(host, *spp, (sizeof host));
906 /* FIXME: sa is too small for INET6 addresses, inet6 should use that too,
907 broadcast is unexpected */
910 switch (ap->getmask(host, &sanetmask, NULL)) {
921 if (ap->input == NULL) {
922 fprintf(stderr, _("ifconfig: Cannot set address for this protocol family.\n"));
925 if (ap->input(0, host, &sa) < 0) {
927 fprintf(stderr, _("ifconfig: `--help' gives usage information.\n"));
930 memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct sockaddr));
932 int r = 0; /* to shut gcc up */
936 fd = get_socket_for_af(AF_INET);
938 fprintf(stderr, _("No support for INET on this system.\n"));
941 r = ioctl(fd, SIOCSIFADDR, &ifr);
946 fd = get_socket_for_af(AF_ECONET);
948 fprintf(stderr, _("No support for ECONET on this system.\n"));
951 r = ioctl(fd, SIOCSIFADDR, &ifr);
956 _("Don't know how to set addresses for family %d.\n"), ap->af);
960 perror("SIOCSIFADDR");
965 goterr |= set_netmask(skfd, &ifr, &sanetmask);
970 * Don't do the set_flag() if the address is an alias with a - at the
971 * end, since it's deleted already! - Roman
973 * Should really use regex.h here, not sure though how well it'll go
974 * with the cross-platform support etc.
978 short int found_colon = 0;
979 for (ptr = ifr.ifr_name; *ptr; ptr++ )
980 if (*ptr == ':') found_colon++;
982 if (!(found_colon && *(ptr - 1) == '-'))
983 goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
999 static unsigned char searcher[256];
1001 static int set_ip_using(const char *name, int c, unsigned long ip)
1004 struct sockaddr_in sin;
1006 safe_strncpy(ifr.ifr_name, name, IFNAMSIZ);
1007 memset(&sin, 0, sizeof(struct sockaddr));
1008 sin.sin_family = AF_INET;
1009 sin.sin_addr.s_addr = ip;
1010 memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr));
1011 if (ioctl(skfd, c, &ifr) < 0)
1016 static int do_ifcmd(struct interface *x, struct ifcmd *ptr)
1019 struct sockaddr_in *sin;
1022 if (do_if_fetch(x) < 0)
1024 if (strncmp(x->name, ptr->base, ptr->baselen) != 0)
1025 return 0; /* skip */
1026 z = strchr(x->name, ':');
1030 for (e = z; *e; e++)
1031 if (*e == '-') /* deleted */
1034 if (i < 0 || i > 255)
1039 sin = (struct sockaddr_in *)&x->dstaddr;
1040 if (sin->sin_addr.s_addr != ptr->addr) {
1046 if (set_flag(x->name, IFF_UP | IFF_RUNNING) == -1)
1050 if (clr_flag(x->name, IFF_UP) == -1)
1054 return 1; /* all done! */
1058 static int get_nmbc_parent(char *parent,
1059 unsigned long *nm, unsigned long *bc)
1061 struct interface *i;
1062 struct sockaddr_in *sin;
1064 i = lookup_interface(parent);
1067 if (do_if_fetch(i) < 0)
1069 sin = (struct sockaddr_in *)&i->netmask;
1070 memcpy(nm, &sin->sin_addr.s_addr, sizeof(unsigned long));
1071 sin = (struct sockaddr_in *)&i->broadaddr;
1072 memcpy(bc, &sin->sin_addr.s_addr, sizeof(unsigned long));
1076 static int set_ifstate(char *parent, unsigned long ip,
1077 unsigned long nm, unsigned long bc,
1085 pt.baselen = strlen(parent);
1088 memset(searcher, 0, sizeof(searcher));
1089 i = for_all_interfaces((int (*)(struct interface *,void *))do_ifcmd,
1096 /* add a new interface */
1097 for (i = 0; i < 256; i++)
1098 if (searcher[i] == 0)
1102 return -1; /* FAILURE!!! out of ip addresses */
1104 if (snprintf(buf, IFNAMSIZ, "%s:%d", parent, i) > IFNAMSIZ)
1106 if (set_ip_using(buf, SIOCSIFADDR, ip) == -1)
1108 if (set_ip_using(buf, SIOCSIFNETMASK, nm) == -1)
1110 if (set_ip_using(buf, SIOCSIFBRDADDR, bc) == -1)
1112 if (set_flag(buf, IFF_BROADCAST) == -1)