axnet/
lib.rs

1//! [ArceOS](https://github.com/arceos-org/arceos) network module.
2//!
3//! It provides unified networking primitives for TCP/UDP communication
4//! using various underlying network stacks. Currently, only [smoltcp] is
5//! supported.
6//!
7//! # Organization
8//!
9//! - [`TcpSocket`]: A TCP socket that provides POSIX-like APIs.
10//! - [`UdpSocket`]: A UDP socket that provides POSIX-like APIs.
11//! - [`dns_query`]: Function for DNS query.
12//!
13//! # Cargo Features
14//!
15//! - `smoltcp`: Use [smoltcp] as the underlying network stack. This is enabled
16//!   by default.
17//!
18//! [smoltcp]: https://github.com/smoltcp-rs/smoltcp
19
20#![no_std]
21
22#[macro_use]
23extern crate log;
24extern crate alloc;
25
26cfg_if::cfg_if! {
27    if #[cfg(feature = "smoltcp")] {
28        mod smoltcp_impl;
29        use smoltcp_impl as net_impl;
30    }
31}
32
33pub use self::net_impl::TcpSocket;
34pub use self::net_impl::UdpSocket;
35pub use self::net_impl::{bench_receive, bench_transmit};
36pub use self::net_impl::{dns_query, poll_interfaces};
37
38use axdriver::{AxDeviceContainer, prelude::*};
39
40/// Initializes the network subsystem by NIC devices.
41pub fn init_network(mut net_devs: AxDeviceContainer<AxNetDevice>) {
42    info!("Initialize network subsystem...");
43
44    let dev = net_devs.take_one().expect("No NIC device found!");
45    info!("  use NIC 0: {:?}", dev.device_name());
46    net_impl::init(dev);
47}