diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-04-12 15:35:54 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-04-12 15:35:54 +0200 |
| commit | 54d6b6ec48145ecc33a35674f9b546b9abb01759 (patch) | |
| tree | 0434b8d4499bfc56d3350538d6404b664dc4ee45 /embassy-net/src/stack.rs | |
| parent | 9c5a8b945a743e75d586fdc2ef857d7c2a038e7d (diff) | |
Correctly randomize source port
Diffstat (limited to 'embassy-net/src/stack.rs')
| -rw-r--r-- | embassy-net/src/stack.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index dc8043e67..9b0dd54d4 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -181,18 +181,14 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf | |||
| 181 | 181 | ||
| 182 | let sockets = SocketSet::new(&mut res.sockets[..]); | 182 | let sockets = SocketSet::new(&mut res.sockets[..]); |
| 183 | 183 | ||
| 184 | let local_port = LOCAL_PORT_MIN; | ||
| 185 | |||
| 186 | /* | ||
| 187 | let local_port = loop { | 184 | let local_port = loop { |
| 188 | let mut res = [0u8; 2]; | 185 | let mut res = [0u8; 2]; |
| 189 | embassy::rand::rand(&mut res); | 186 | rand(&mut res); |
| 190 | let port = u16::from_le_bytes(res); | 187 | let port = u16::from_le_bytes(res); |
| 191 | if port >= LOCAL_PORT_MIN && port <= LOCAL_PORT_MAX { | 188 | if port >= LOCAL_PORT_MIN && port <= LOCAL_PORT_MAX { |
| 192 | break port; | 189 | break port; |
| 193 | } | 190 | } |
| 194 | }; | 191 | }; |
| 195 | */ | ||
| 196 | 192 | ||
| 197 | let stack = Stack { | 193 | let stack = Stack { |
| 198 | iface, | 194 | iface, |
| @@ -225,3 +221,11 @@ fn instant_to_smoltcp(instant: Instant) -> SmolInstant { | |||
| 225 | fn instant_from_smoltcp(instant: SmolInstant) -> Instant { | 221 | fn instant_from_smoltcp(instant: SmolInstant) -> Instant { |
| 226 | Instant::from_millis(instant.total_millis() as u64) | 222 | Instant::from_millis(instant.total_millis() as u64) |
| 227 | } | 223 | } |
| 224 | |||
| 225 | extern "Rust" { | ||
| 226 | fn _embassy_rand(buf: &mut [u8]); | ||
| 227 | } | ||
| 228 | |||
| 229 | fn rand(buf: &mut [u8]) { | ||
| 230 | unsafe { _embassy_rand(buf) } | ||
| 231 | } | ||
