ax-net 0.5.13

ArceOS network module
Documentation
//! [ArceOS](https://github.com/arceos-org/arceos) network module.
//!
//! It provides unified networking primitives for TCP/UDP communication
//! using various underlying network stacks. Currently, only [smoltcp] is
//! supported.
//!
//! # Organization
//!
//! - [`TcpSocket`]: A TCP socket that provides POSIX-like APIs.
//! - [`UdpSocket`]: A UDP socket that provides POSIX-like APIs.
//! - [`dns_query`]: Function for DNS query.
//!
//! # Cargo Features
//!
//! - `smoltcp`: Use [smoltcp] as the underlying network stack. This is enabled
//!   by default.
//!
//! [smoltcp]: https://github.com/smoltcp-rs/smoltcp

#![no_std]

extern crate alloc;
#[cfg(feature = "smoltcp")]
#[macro_use]
extern crate log;

cfg_if::cfg_if! {
    if #[cfg(feature = "smoltcp")] {
        mod smoltcp_impl;
        use smoltcp_impl as net_impl;
    }
}

#[cfg(feature = "smoltcp")]
use ax_driver::{AxDeviceContainer, AxNetDevice};

#[cfg(feature = "smoltcp")]
pub use self::net_impl::{
    TcpSocket, UdpSocket, bench_receive, bench_transmit, dns_query, poll_interfaces,
};

/// Initializes the network subsystem by NIC devices.
#[cfg(feature = "smoltcp")]
pub fn init_network(mut net_devs: AxDeviceContainer<AxNetDevice>) {
    use ax_driver::prelude::*;

    info!("Initialize network subsystem...");

    if let Some(dev) = net_devs.take_one() {
        info!("  use NIC 0: {:?}", dev.device_name());
        net_impl::init(dev);
    } else {
        warn!("  No network device found!");
    }
}