12.6Reading Current and Default MAC Addresses (SIOCRPHYSADDR ioctl Command)

The following code shows how the el_ioctl( ) routine implements the SIOCRPHYSADDR ioctl command to read the current and default MAC addresses when an application requests them:

case SIOCRPHYSADDR: 1 bcopy(sc->is_addr, ifd->current_pa, 6); 2 for (i=0; i<3; i++) { 3

j = sc->eeprom.addr[i]; ifd->default_pa[(i*2)] = (j>>8) & 0xff; ifd->default_pa[(i*2)+1] = (j) & 0xff;

}

break;

1

2

3

Determines whether the cmd argument is SIOCRPHYSADDR.

Copies the current MAC address that is stored in the el_softc data structure for this device to the ifd data structure, a command-specific data structure of type ifdevea.

Copies the default MAC address that is stored in the driver’s el_softc data structure for this device to the ifd data structure.

12.7Setting the Local MAC Address (SIOCSPHYSADDR ioctl Command)

The following code shows how the el_ioctl( ) routine implements the SIOCSPHYSADDR ioctl command to set the local MAC address:

case SIOCSPHYSADDR: 1 bcopy(ifr->ifr_addr.sa_data, sc->is_addr, 6);

2

pfilt_newaddress(sc->is_ed.ess_enetunit, sc->is_addr);

if (ifp->if_flags & IFF_RUNNING) { 4 el_reset_locked(sc, ifp, unit);

}

simple_unlock(&sc->el_softc_lock); 5 splx(s); 6

lock_on = 0; 7

3

if (((struct arpcom *)ifp)->ac_flag & AC_IPUP) { rearpwhohas((struct arpcom *)ifp);

}

8

if_sphyaddr(ifp, ifr); break;

9

1

2

3

Determines whether the cmd argument is SIOCSPHYSADDR ioctl.

Copies the new MAC address to the ifnet data structure.

Calls the pfilt_newaddress( ) routine to copy the new address to the packet filter.

Implementing the ioctl Section 12–5

Page 129
Image 129
Compaq AA-RNG2A-TE manual Setting the Local MAC Address Siocsphysaddr ioctl Command