diff options
author | Boris Popov <bp@FreeBSD.org> | 1999-12-13 15:57:11 +0000 |
---|---|---|
committer | Boris Popov <bp@FreeBSD.org> | 1999-12-13 15:57:11 +0000 |
commit | 8b7805e44e9aeaf8fd798a813f000e087eac63b9 (patch) | |
tree | 09b82c1c57e90d9bc5002af5d1492116faf1df56 /sys/net/if.c | |
parent | d5756b259912fd255b2c7f0f9d089f29f1097019 (diff) | |
download | src-8b7805e44e9aeaf8fd798a813f000e087eac63b9.tar.gz src-8b7805e44e9aeaf8fd798a813f000e087eac63b9.zip |
Allow ifunit() routine to understand names like ed0f2. Also
fix a bug caused by using bcmp() instead of strcmp().
Reviewed by: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Notes
Notes:
svn path=/head/; revision=54557
Diffstat (limited to 'sys/net/if.c')
-rw-r--r-- | sys/net/if.c | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index e244ce9ab819..5329c6d7ecba 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -597,46 +597,41 @@ if_slowtimo(arg) * interface structure pointer. */ struct ifnet * -ifunit(name) - register char *name; +ifunit(char *name) { char namebuf[IFNAMSIZ + 1]; - register char *cp, *cp2; - char *end; - register struct ifnet *ifp; + char *cp; + struct ifnet *ifp; int unit; - unsigned len; - register char c = '\0'; + unsigned len, m; + char c; - /* - * Look for a non numeric part - */ - end = name + IFNAMSIZ; - cp2 = namebuf; - cp = name; - while ((cp < end) && (c = *cp)) { - if (c >= '0' && c <= '9') - break; - *cp2++ = c; - cp++; - } - if ((cp == end) || (c == '\0') || (cp == name)) - return ((struct ifnet *)0); - *cp2 = '\0'; - /* - * check we have a legal number (limit to 7 digits?) - */ + len = strlen(name); + if (len < 2 || len > IFNAMSIZ) + return NULL; + cp = name + len - 1; + c = *cp; + if (c < '0' || c > '9') + return NULL; /* trailing garbage */ + unit = 0; + m = 1; + do { + if (cp == name) + return NULL; /* no interface name */ + unit += (c - '0') * m; + if (unit > 1000000) + return NULL; /* number is unreasonable */ + m *= 10; + c = *--cp; + } while (c >= '0' && c <= '9'); len = cp - name + 1; - for (unit = 0; - ((c = *cp) >= '0') && (c <= '9') && (unit < 1000000); cp++ ) - unit = (unit * 10) + (c - '0'); - if (*cp != '\0') - return 0; /* no trailing garbage allowed */ + bcopy(name, namebuf, len); + namebuf[len] = '\0'; /* * Now search all the interfaces for this name/number */ for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) { - if (bcmp(ifp->if_name, namebuf, len)) + if (strcmp(ifp->if_name, namebuf)) continue; if (unit == ifp->if_unit) break; |