Correctly randomize source port

This commit is contained in:
Dario Nieuwenhuis 2021-04-12 15:35:54 +02:00
parent 9c5a8b945a
commit 54d6b6ec48

View File

@ -181,18 +181,14 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf
let sockets = SocketSet::new(&mut res.sockets[..]); let sockets = SocketSet::new(&mut res.sockets[..]);
let local_port = LOCAL_PORT_MIN;
/*
let local_port = loop { let local_port = loop {
let mut res = [0u8; 2]; let mut res = [0u8; 2];
embassy::rand::rand(&mut res); rand(&mut res);
let port = u16::from_le_bytes(res); let port = u16::from_le_bytes(res);
if port >= LOCAL_PORT_MIN && port <= LOCAL_PORT_MAX { if port >= LOCAL_PORT_MIN && port <= LOCAL_PORT_MAX {
break port; break port;
} }
}; };
*/
let stack = Stack { let stack = Stack {
iface, iface,
@ -225,3 +221,11 @@ fn instant_to_smoltcp(instant: Instant) -> SmolInstant {
fn instant_from_smoltcp(instant: SmolInstant) -> Instant { fn instant_from_smoltcp(instant: SmolInstant) -> Instant {
Instant::from_millis(instant.total_millis() as u64) Instant::from_millis(instant.total_millis() as u64)
} }
extern "Rust" {
fn _embassy_rand(buf: &mut [u8]);
}
fn rand(buf: &mut [u8]) {
unsafe { _embassy_rand(buf) }
}