diff --git a/Cargo.lock b/Cargo.lock
index 509f1e37..0428cce4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -472,7 +472,7 @@ dependencies = [
"lazy_init",
"log",
"num_enum",
- "smoltcp",
+ "smoltcp 0.10.0 (git+https://github.com/YXalix/smoltcp.git)",
"spin 0.9.8",
]
@@ -1284,7 +1284,7 @@ dependencies = [
"bit_field",
"core_detect",
"log",
- "smoltcp",
+ "smoltcp 0.10.0 (git+https://github.com/c0per/smoltcp?branch=starryos)",
"volatile 0.3.0",
]
@@ -1915,6 +1915,20 @@ dependencies = [
"managed",
]
+[[package]]
+name = "smoltcp"
+version = "0.10.0"
+source = "git+https://github.com/YXalix/smoltcp.git#8b004f1845607bea1b7650cffdd41ed8fe90a918"
+dependencies = [
+ "bitflags 1.3.2",
+ "byteorder",
+ "cfg-if",
+ "defmt",
+ "heapless",
+ "log",
+ "managed",
+]
+
[[package]]
name = "spin"
version = "0.5.2"
diff --git a/modules/axnet/Cargo.toml b/modules/axnet/Cargo.toml
index f982a6f1..9c3c976e 100644
--- a/modules/axnet/Cargo.toml
+++ b/modules/axnet/Cargo.toml
@@ -36,8 +36,7 @@ version = "0.5.11"
default-features = false
[dependencies.smoltcp]
-git = "https://github.com/rcore-os/smoltcp.git"
-rev = "2ade274"
+git = "https://github.com/YXalix/smoltcp.git"
default-features = false
features = [
"alloc", "log", # no std
diff --git a/modules/axnet/src/smoltcp_impl/mod.rs b/modules/axnet/src/smoltcp_impl/mod.rs
index ea2da327..eb61ca20 100644
--- a/modules/axnet/src/smoltcp_impl/mod.rs
+++ b/modules/axnet/src/smoltcp_impl/mod.rs
@@ -9,6 +9,7 @@ use alloc::vec;
use core::cell::RefCell;
use core::ops::DerefMut;
+use axerrno::{ax_err, ax_err_type, AxError, AxResult};
use axdriver::prelude::*;
use axhal::time::{current_time_nanos, NANOS_PER_MICROS};
use axsync::Mutex;
@@ -16,7 +17,7 @@ use driver_net::{DevError, NetBufPtr};
use lazy_init::LazyInit;
use smoltcp::iface::{Config, Interface, SocketHandle, SocketSet};
use smoltcp::phy::{Device, DeviceCapabilities, Medium, RxToken, TxToken};
-use smoltcp::socket::{self, AnySocket};
+use smoltcp::socket::{self, AnySocket, Socket};
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress, IpCidr};
@@ -130,6 +131,23 @@ impl<'a> SocketSetWrapper<'a> {
f(socket)
}
+ pub fn bind_check(&self, addr: IpAddress, port: u16) -> AxResult {
+ let mut sockets = self.0.lock();
+ error!("checking addr: {:?}, port: {}", addr, port);
+ for item in sockets.iter_mut() {
+ match item.1 {
+ Socket::Udp(s) => {
+ error!("{}", s.endpoint().port);
+ if s.endpoint().port == port {
+ return Err(AxError::AddrInUse);
+ }
+ },
+ _ => continue,
+ };
+ }
+ Ok(())
+ }
+
pub fn poll_interfaces(&self) {
#[cfg(feature = "ip")]
{
@@ -350,6 +368,8 @@ pub(crate) fn init(_net_dev: AxNetDevice) {
.push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8))
.unwrap();
});
+ let multicast_addr = IpAddress::v4(239, 255, 0, 1);
+ let _= iface.join_multicast_group(&mut device, multicast_addr, Instant::from_micros_const((current_time_nanos() / NANOS_PER_MICROS) as i64));
LOOPBACK.init_by(Mutex::new(iface));
LOOPBACK_DEV.init_by(Mutex::new(device));
}
diff --git a/modules/axnet/src/smoltcp_impl/udp.rs b/modules/axnet/src/smoltcp_impl/udp.rs
index bc8ab1b4..ac2fddb4 100644
--- a/modules/axnet/src/smoltcp_impl/udp.rs
+++ b/modules/axnet/src/smoltcp_impl/udp.rs
@@ -26,6 +26,7 @@ pub struct UdpSocket {
local_addr: RwLock