Subject: Re: always print IPv4 alias addresses
To: Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>
From: None <itojun@iijlab.net>
List: tech-net
Date: 04/28/2001 08:35:02
>> it is, IMHO, confusing (and i got comments from others, including
>> jinmei - cc'ed). is it okay to always print aliases, and say
>> good bye to -A? (i.e. -A is the default behavior)
>Sounds good to me, but I'm not authoritative here. :)
>Can you - while there - make the MAC address printed with "ifconfig foo"?
>So far it's only printed with "ifconfig -a"... equally confusing.
the following diff will take care of both (-A by default, and
mac address printing).
itojun
Index: ifconfig.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.105
diff -u -r1.105 ifconfig.c
--- ifconfig.c 2001/04/27 09:10:04 1.105
+++ ifconfig.c 2001/04/27 23:34:48
@@ -143,7 +143,7 @@
int newaddr = -1;
int nsellength = 1;
int af;
-int Aflag, aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag;
+int aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag;
#ifdef INET6
int Lflag;
#endif
@@ -295,7 +295,7 @@
int getinfo __P((struct ifreq *));
int carrier __P((void));
void getsock __P((int));
-void printall __P((void));
+void printall __P((const char *));
void list_cloners __P((void));
void printb __P((const char *, unsigned short, const char *));
int prefix __P((void *, int));
@@ -400,7 +400,7 @@
)) != -1) {
switch (ch) {
case 'A':
- Aflag = 1;
+ warnx("-A is deprecated");
break;
case 'a':
@@ -460,7 +460,7 @@
*
* -a means "print status of all interfaces".
*/
- if ((lflag || Cflag) && (aflag || mflag || Aflag || argc))
+ if ((lflag || Cflag) && (aflag || mflag || argc))
usage();
#ifdef INET6
if ((lflag || Cflag) && Lflag)
@@ -486,7 +486,7 @@
af = ifr.ifr_addr.sa_family = afp->af_af;
else
af = ifr.ifr_addr.sa_family = afs[0].af_af;
- printall();
+ printall(NULL);
exit(0);
}
@@ -537,7 +537,7 @@
/* No more arguments means interface status. */
if (argc == 0) {
- status(NULL, 0);
+ printall(name);
exit(0);
}
@@ -694,7 +694,8 @@
}
void
-printall()
+printall(ifname)
+ const char *ifname;
{
#ifdef HAVE_IFADDRS_H
struct ifaddrs *ifap, *ifa;
@@ -715,6 +716,8 @@
ifa->ifa_addr->sa_len);
}
+ if (ifname && strcmp(ifname, ifa->ifa_name) != 0)
+ continue;
if (ifa->ifa_addr->sa_family == AF_LINK)
sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
if (p && strcmp(p, ifa->ifa_name) == 0)
@@ -789,6 +792,9 @@
errx(1, "ifr too big");
memcpy(ifrbuf, cp, siz);
+ if (ifname && strncmp(ifname, ifr->ifr_name,
+ sizeof(ifr->ifr_name)))
+ continue;
if (ifr->ifr_addr.sa_family == AF_LINK)
sdl = (const struct sockaddr_dl *) &ifr->ifr_addr;
if (!strncmp(ifreq.ifr_name, ifr->ifr_name,
@@ -2031,9 +2037,6 @@
if (memcmp(&ifr.ifr_addr, &creq->ifr_addr,
sizeof(creq->ifr_addr)) == 0)
alias = 0;
- /* we print aliases only with -A */
- if (alias && !Aflag)
- return;
(void) memset(&addreq, 0, sizeof(addreq));
(void) strncpy(addreq.ifra_name, name, sizeof(addreq.ifra_name));
addreq.ifra_addr = creq->ifr_addr;