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>
This commit is contained in:
parent
d5756b2599
commit
8b7805e44e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=54557
57
sys/net/if.c
57
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;
|
||||
|
Loading…
Reference in New Issue
Block a user