summaryrefslogtreecommitdiffstats
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-01-08 03:46:27 +0000
committerpeter <peter@FreeBSD.org>1996-01-08 03:46:27 +0000
commitbb732328cebd73f44de4acd2ac5139f12a639ce0 (patch)
treefd8613bc216d02cba446d3d274d21f4e461961ff /sbin/ifconfig
parentde80e40d71795a22837cd56c09ae22cf330461cf (diff)
downloadFreeBSD-src-bb732328cebd73f44de4acd2ac5139f12a639ce0.zip
FreeBSD-src-bb732328cebd73f44de4acd2ac5139f12a639ce0.tar.gz
Fix some of my mistakes, slight cleanup, improve reliability (the old
ifconfig would segfault on "ifconfig ed0 ether up" and the like). The main reason for this commit was that an "ifconfig -a" would also show the AF_INET addresses in AF_IPX form (if the kernel was configured for IPX) due to insufficient AF checking in my "new way" of doing it.
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifconfig.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 6292f73..4a94522 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 }, XXX - broken */
+ { "ether", AF_INET, ether_status, NULL },
{ 0, 0, 0, 0 }
};
@@ -425,6 +425,13 @@ ifconfig(argc,argv,af,rafp)
Perror("Encapsulation Routing");
}
if (clearaddr) {
+ if (rafp->af_ridreq == NULL || rafp->af_difaddr == 0) {
+ warnx("interface %s cannot change %s addresses!",
+ name, rafp->af_name);
+ clearaddr = NULL;
+ }
+ }
+ if (clearaddr) {
int ret;
strncpy(rafp->af_ridreq, name, sizeof ifr.ifr_name);
if ((ret = ioctl(s, rafp->af_difaddr, rafp->af_ridreq)) < 0) {
@@ -435,6 +442,13 @@ ifconfig(argc,argv,af,rafp)
}
}
if (newaddr) {
+ if (rafp->af_ridreq == NULL || rafp->af_difaddr == 0) {
+ warnx("interface %s cannot change %s addresses!",
+ name, rafp->af_name);
+ newaddr = NULL;
+ }
+ }
+ if (newaddr) {
strncpy(rafp->af_addreq, name, sizeof ifr.ifr_name);
if (ioctl(s, rafp->af_aifaddr, rafp->af_addreq) < 0)
Perror("ioctl (SIOCAIFADDR)");
@@ -583,6 +597,13 @@ status()
printf(" mtu %d", mtu);
putchar('\n');
+ /*
+ * XXX: Sigh. This is bad, I know. At this point, we may have
+ * *zero* RTM_NEWADDR's, so we have to "feel the water" before
+ * incrementing the loop. One day, I might feel inspired enough
+ * to get the top level loop to pass a count down here so we
+ * dont have to mess with this. -Peter
+ */
myifm = ifm;
while (1) {
@@ -610,13 +631,16 @@ status()
if ((p = afp) != NULL) {
- (*p->af_status)(1);
+ 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;
- (*p->af_status)(0);
+ if (p->af_status != ether_status)
+ (*p->af_status)(0);
}
}
- ether_status();
+ if (afp == NULL || afp->af_status == ether_status)
+ ether_status();
}
in_status(force)
@@ -629,10 +653,10 @@ in_status(force)
memset(&null_sin, 0, sizeof(null_sin));
sin = (struct sockaddr_in *)info.rti_info[RTAX_IFA];
- if (!sin) {
+ if (!sin || sin->sin_family != AF_INET) {
if (!force)
return;
- warnx("%s has no AF_INET IFA address!", name);
+ /* warnx("%s has no AF_INET IFA address!", name); */
sin = &null_sin;
}
printf("\tinet %s ", inet_ntoa(sin->sin_addr));
@@ -676,10 +700,10 @@ ipx_status(force)
memset(&null_sipx, 0, sizeof(null_sipx));
sipx = (struct sockaddr_ipx *)info.rti_info[RTAX_IFA];
- if (!sipx) {
+ 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));
@@ -710,10 +734,10 @@ xns_status(force)
memset(&null_sns, 0, sizeof(null_sns));
sns = (struct sockaddr_ns *)info.rti_info[RTAX_IFA];
- if (!sns) {
+ if (!sns || sns->sns_family != AF_NS) {
if (!force)
return;
- warnx("%s has no AF_NS IFA address!", name);
+ /* warnx("%s has no AF_NS IFA address!", name); */
sns = &null_sns;
}
printf("\tns %s ", ns_ntoa(sns->sns_addr));
@@ -745,10 +769,10 @@ iso_status(force)
memset(&null_siso, 0, sizeof(null_siso));
siso = (struct sockaddr_iso *)info.rti_info[RTAX_IFA];
- if (!siso) {
+ if (!siso || siso->siso_family != AF_ISO) {
if (!force)
return;
- warnx("%s has no AF_ISO IFA address!", name);
+ /* warnx("%s has no AF_ISO IFA address!", name); */
siso = &null_siso;
}
printf("\tiso %s ", iso_ntoa(&siso->siso_addr));
OpenPOWER on IntegriCloud