diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-02-26 20:25:10 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-02-26 20:25:10 +0000 |
commit | e917533ebed150d458a7466d8e9400b35b6434f4 (patch) | |
tree | 526c9b2df1c53260fcab4db223b7bb4bdaa2a45a /sbin/ifconfig | |
parent | e4cdba19e32c7d0b83c69eba5ba96f92c581c48b (diff) |
Deal correctly with printing interfaces with multiple trailing digits.
E.g. "ifconfig vlan1" should only match vlan1, not vlan1, vlan10, vlan11,
etc. OK tdeval@, hshoexer@, otto@. Closes PR 3693.
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index c9954d69f8d..41c44702c52 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.89 2004/01/13 01:42:45 mcbride Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.90 2004/02/26 20:25:09 millert Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -77,7 +77,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #else -static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.89 2004/01/13 01:42:45 mcbride Exp $"; +static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.90 2004/02/26 20:25:09 millert Exp $"; #endif #endif /* not lint */ @@ -648,7 +648,7 @@ printif(struct ifreq *ifrm, int ifaliases) #ifdef HAVE_IFADDRS_H struct ifaddrs *ifap, *ifa; const char *namep; - char ch, *oname = NULL; + char *oname = NULL; struct ifreq *ifrp; int nlen, count = 0, noinet = 1; @@ -664,13 +664,17 @@ printif(struct ifreq *ifrm, int ifaliases) namep = NULL; for (ifa = ifap; ifa; ifa = ifa->ifa_next) { - if (oname && strncmp(oname, ifa->ifa_name, nlen)) - continue; if (oname) { - /* Check for end or a digit ! */ - ch = ifa->ifa_name[nlen]; - if (ch && (ch < '0' || ch > '9')) - continue; + if (isdigit(oname[nlen - 1])) { + /* must have exact match */ + if (strcmp(oname, ifa->ifa_name) != 0) + continue; + } else { + /* partial match OK if it ends w/ digit */ + if (strncmp(oname, ifa->ifa_name, nlen) != 0 || + !isdigit(ifa->ifa_name[nlen])) + continue; + } } (void) strlcpy(name, ifa->ifa_name, sizeof(name)); |