Fix bug in BIOCGETIF ioctl() where it would return a bogus interface
name if the interface unit number was greater than 9.
This commit is contained in:
parent
d38d3bf21b
commit
7e3945e1f6
@ -114,7 +114,6 @@ static int bpf_allocbufs __P((struct bpf_d *));
|
||||
static void bpf_attachd __P((struct bpf_d *d, struct bpf_if *bp));
|
||||
static void bpf_detachd __P((struct bpf_d *d));
|
||||
static void bpf_freed __P((struct bpf_d *));
|
||||
static void bpf_ifname __P((struct ifnet *, struct ifreq *));
|
||||
static void bpf_mcopy __P((const void *, void *, size_t));
|
||||
static int bpf_movein __P((struct uio *, int,
|
||||
struct mbuf **, struct sockaddr *, int *));
|
||||
@ -755,13 +754,18 @@ bpfioctl(dev, cmd, addr, flags, p)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Set interface name.
|
||||
* Get interface name.
|
||||
*/
|
||||
case BIOCGETIF:
|
||||
if (d->bd_bif == 0)
|
||||
error = EINVAL;
|
||||
else
|
||||
bpf_ifname(d->bd_bif->bif_ifp, (struct ifreq *)addr);
|
||||
else {
|
||||
struct ifnet *const ifp = d->bd_bif->bif_ifp;
|
||||
struct ifreq *const ifr = (struct ifreq *)addr;
|
||||
|
||||
snprintf(ifr->ifr_name, sizeof(ifr->ifr_name),
|
||||
"%s%d", ifp->if_name, ifp->if_unit);
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
@ -990,26 +994,6 @@ bpf_setif(d, ifr)
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an interface name plus unit number of an ifp to a single
|
||||
* name which is returned in the ifr.
|
||||
*/
|
||||
static void
|
||||
bpf_ifname(ifp, ifr)
|
||||
struct ifnet *ifp;
|
||||
struct ifreq *ifr;
|
||||
{
|
||||
char *s = ifp->if_name;
|
||||
char *d = ifr->ifr_name;
|
||||
|
||||
while ((*d++ = *s++) != 0)
|
||||
continue;
|
||||
d--; /* back to the null */
|
||||
/* XXX Assume that unit number is less than 10. */
|
||||
*d++ = ifp->if_unit + '0';
|
||||
*d = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* Support for select() and poll() system calls
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user