pub async fn create_eth_client(mac: &[u8; 6]) -> Result<Option<ethernet::Client>, anyhow::Error> {
    const ETH_PATH: &str = "class/ethernet";
    let eth_dir = IsolatedDeviceEnv::open_dir(ETH_PATH).expect("opening ethernet dir");
    let directory_proxy = fidl_fuchsia_io::DirectoryProxy::new(
        fuchsia_async::Channel::from_channel(fdio::clone_channel(&eth_dir)?)?,
    );
    let files = readdir(&directory_proxy).await?;
    for file in files {
        let vmo = zx::Vmo::create(ETH_BUF_FRAME_COUNT * ethernet::DEFAULT_BUFFER_SIZE as u64)?;

        let path = Path::new(ETH_PATH).join(file.name);
        let dev = IsolatedDeviceEnv::open_file(path)?;
        if let Ok(client) =
            ethernet::Client::from_file(dev, vmo, ethernet::DEFAULT_BUFFER_SIZE, "wlan-hw-sim")
                .await
        {
            if let Ok(info) = client.info().await {
                if &info.mac.octets == mac {
                    info!("ethernet client created: {:?}", client);
                    client.start().await.expect("error starting ethernet device");
                    // must call get_status() after start() to clear zx::Signals::USER_0 otherwise
                    // there will be a stream of infinite StatusChanged events that blocks
                    // fasync::Interval
                    info!(
                        "info: {:?} status: {:?}",
                        client.info().await.expect("calling client.info()"),
                        client.get_status().await.expect("getting client status()")
                    );
                    let mut stream = client.get_stream();
                    // The rust Ethernet client makes one single rx buffer available
                    // to the Ethernet driver on every poll.
                    // Without this loop, the Ethernet driver may complain about no RX buffer
                    // available and drop the packet, leaving our Ethernet client sitting forever.
                    for _ in 0..ETH_BUF_FRAME_COUNT {
                        let _ = poll!(stream.next());
                    }
                    return Ok(Some(client));
                }
            }
        }
    }
    Ok(None)
}
/// loop through all ethernet interface and return the one with matching MAC addresss.
/// Returns Ok(None) if no matching interface is found,
/// Returns Err(e) if there is an error.
loop through all ethernet interface and return the one with matching MAC addresss.
Returns Ok(None) if no matching interface is found,
Returns Err(e) if there is an error.
loop through all ethernet interface and return the one with matching MAC addresss . Returns Ok ( None ) if no matching interface is found Returns Err ( e ) if there is an error .
pub async fn create_eth_client(mac: &[u8; 6]) -> Result<Option<ethernet::Client>, anyhow::Error> {
    const ETH_PATH: &str = "class/ethernet";
    let eth_dir = IsolatedDeviceEnv::open_dir(ETH_PATH).expect("opening ethernet dir");
    let directory_proxy = fidl_fuchsia_io::DirectoryProxy::new(
        fuchsia_async::Channel::from_channel(fdio::clone_channel(&eth_dir)?)?,
    );
    let files = readdir(&directory_proxy).await?;
    for file in files {
        let vmo = zx::Vmo::create(ETH_BUF_FRAME_COUNT * ethernet::DEFAULT_BUFFER_SIZE as u64)?;
        let path = Path::new(ETH_PATH).join(file.name);
        let dev = IsolatedDeviceEnv::open_file(path)?;
        if let Ok(client) =
            ethernet::Client::from_file(dev, vmo, ethernet::DEFAULT_BUFFER_SIZE, "wlan-hw-sim")
                .await
        {
            if let Ok(info) = client.info().await {
                if &info.mac.octets == mac {
                    info!("ethernet client created: {:?}", client);
                    client.start().await.expect("error starting ethernet device");
                    // must call get_status() after start() to clear zx::Signals::USER_0 otherwise
                    // there will be a stream of infinite StatusChanged events that blocks
                    // fasync::Interval
                    info!(
                        "info: {:?} status: {:?}",
                        client.info().await.expect("calling client.info()"),
                        client.get_status().await.expect("getting client status()")
                    );
                    let mut stream = client.get_stream();
                    // The rust Ethernet client makes one single rx buffer available
                    // to the Ethernet driver on every poll.
                    // Without this loop, the Ethernet driver may complain about no RX buffer
                    // available and drop the packet, leaving our Ethernet client sitting forever.
                    for _ in 0..ETH_BUF_FRAME_COUNT {
                        let _ = poll!(stream.next());
                    }
                    return Ok(Some(client));
                }
            }
        }
    }
    Ok(None)
}
pub async fn create_eth_client ( mac : & [ u8 ; 6 ] ) -> Result < Option < ethernet :: Client > , anyhow :: Error > { const ETH_PATH : & str = " " ; let eth_dir = IsolatedDeviceEnv :: open_dir ( ETH_PATH ) . expect ( " " ) ; let directory_proxy = fidl_fuchsia_io :: DirectoryProxy :: new ( fuchsia_async :: Channel :: from_channel ( fdio :: clone_channel ( & eth_dir ) ? ) ? , ) ; let files = readdir ( & directory_proxy ) . await ? ; for file in files { let vmo = zx :: Vmo :: create ( ETH_BUF_FRAME_COUNT * ethernet :: DEFAULT_BUFFER_SIZE as u64 ) ? ; let path = Path :: new ( ETH_PATH ) . join ( file . name ) ; let dev = IsolatedDeviceEnv :: open_file ( path ) ? ; if let Ok ( client ) = ethernet :: Client :: from_file ( dev , vmo , ethernet :: DEFAULT_BUFFER_SIZE , " " ) . await { if let Ok ( info ) = client . info ( ) . await { if & info . mac . octets == mac { info ! ( " " client ) ; client . start ( ) . await . expect ( " " ) ; // must call get_status() after start() to clear zx::Signals::USER_0 otherwise // there will be a stream of infinite StatusChanged events that blocks // fasync::Interval info ! ( " " client info ( ) await expect ( " " ) client get_status ( ) await expect ( " " ) ) ; let mut stream = client . get_stream ( ) ; // The rust Ethernet client makes one single rx buffer available // to the Ethernet driver on every poll. // Without this loop, the Ethernet driver may complain about no RX buffer // available and drop the packet, leaving our Ethernet client sitting forever. for _ in 0 .. ETH_BUF_FRAME_COUNT { let _ = poll ! ( stream next ( ) ) ; } return Ok ( Some ( client ) ) ; } } } } Ok ( None ) }
loop through all ethernet interface and return the one with matching MAC addresss.
loop through all ethernet interface and return the one with matching MAC addresss .
mac
&[u8; 6]
mac
&[u8; 6]