diff options
author | peter <peter@FreeBSD.org> | 1996-01-08 10:23:25 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-01-08 10:23:25 +0000 |
commit | 250a8d27d3a03118cbd0b4c9c232107adeabf587 (patch) | |
tree | 1cd58eb38624cd4a19797c9b6c266c9a2c16f890 /sbin/ifconfig | |
parent | a09220052fd33a1d0220b323549ec3b0a6c8a837 (diff) | |
download | FreeBSD-src-250a8d27d3a03118cbd0b4c9c232107adeabf587.zip FreeBSD-src-250a8d27d3a03118cbd0b4c9c232107adeabf587.tar.gz |
Yet another "fix" for some of the mistakes in the recent versions..
I discovered that when asking for the IFLIST via sysctl(), if you
specify only AF_INET address, it actually gives you only AF_INET..
(suprise, suprise..!)
Now, it should "do the right thing" in just about all cases... The only
problem, is that "the right thing" isn't exactly clear in all cases.
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 4a94522..aaca36d 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -185,7 +185,7 @@ struct afswtch { SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, { "iso", AF_ISO, iso_status, iso_getaddr, SIOCDIFADDR_ISO, SIOCAIFADDR_ISO, C(iso_ridreq), C(iso_addreq) }, - { "ether", AF_INET, ether_status, NULL }, + { "ether", AF_INET, ether_status, NULL }, /* XXX not real!! */ { 0, 0, 0, 0 } }; @@ -246,13 +246,14 @@ main(argc, argv) int all; if (argc < 2) { - fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s%s", + fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s%s%s", "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]", "[ netmask mask ] ]\n", "\t[ metric n ]\n", "\t[ mtu n ]\n", "\t[ arp | -arp ]\n", - "\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ] \n"); + "\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ] \n" + "\t[ -a ] [ -ad ] [ -au ]\n"); exit(1); } argc--, argv++; @@ -272,12 +273,17 @@ main(argc, argv) mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; - mib[3] = AF_INET; + mib[3] = 0; /* address family */ mib[4] = NET_RT_IFLIST; mib[5] = 0; + /* if particular family specified, only ask about it */ + if (afp) { + mib[3] = afp->af_af; + } + if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) - errx(1, "route-sysctl-estimate"); + errx(1, "iflist-sysctl-estimate"); if ((buf = malloc(needed)) == NULL) errx(1, "malloc"); if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) @@ -584,7 +590,7 @@ setsnpaoffset(val) */ status() { - register struct afswtch *p = afp; + struct afswtch *p = NULL; short af = ifr.ifr_addr.sa_family; char *mynext; struct if_msghdr *myifm; @@ -629,18 +635,24 @@ status() rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam, &info); - - if ((p = afp) != NULL) { - if (p->af_status != ether_status) - (*p->af_status)(1); + if (afp) { + if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family && + afp->af_status != ether_status) { + p = afp; + if (p->af_status != ether_status) + (*p->af_status)(1); + } } else for (p = afs; p->af_name; p++) { - ifr.ifr_addr.sa_family = p->af_af; - if (p->af_status != ether_status) + if (p->af_af == info.rti_info[RTAX_IFA]->sa_family && + p->af_status != ether_status) (*p->af_status)(0); } } if (afp == NULL || afp->af_status == ether_status) ether_status(); + else if (afp && !p) { + warnx("%s has no %s IFA address!", name, afp->af_name); + } } in_status(force) @@ -703,7 +715,7 @@ ipx_status(force) if (!sipx || sipx->sipx_family != AF_IPX) { if (!force) return; - /* warnx("%s has no AF_IPX IFA address!", name); */ + warnx("%s has no AF_IPX IFA address!", name); sipx = &null_sipx; } printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr)); |