diff --git a/Cargo.lock b/Cargo.lock index 827586960d..44751d42fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,6 +265,7 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ + "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", diff --git a/Cargo.toml b/Cargo.toml index 25cc10c017..3f6b71053e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ path = "src/smolnetd/main.rs" netutils = { git = "https://github.com/redox-os/netutils.git" } redox_event = { git = "https://github.com/redox-os/event.git" } redox_syscall = { git = "https://github.com/redox-os/syscall.git" } +byteorder = { version = "1.0", default-features = false } [dependencies.log] version = "0.3" diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 59e39841e6..fa51bf27ea 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -6,6 +6,7 @@ extern crate log; extern crate netutils; extern crate smoltcp; extern crate syscall; +extern crate byteorder; use std::cell::RefCell; use std::fs::File; diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 412666ca35..bccb75a3b0 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -4,6 +4,7 @@ use std::mem; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; +use byteorder::{ByteOrder, NetworkEndian}; use device::NetworkDevice; use port_set::PortSet; @@ -135,8 +136,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { return Err(SyscallError::new(syscall::EINVAL)); } let (seq_buf, payload) = buf.split_at(mem::size_of::()); - // Don't really care about endianness here as long as it's consistent with read - let seq_no: u16 = u16::from(seq_buf[0]) | (u16::from(seq_buf[1]) << 8); + let seq_no = NetworkEndian::read_u16(seq_buf); let icmp_repr = Icmpv4Repr::EchoRequest { ident: file.data.ident, seq_no, @@ -173,10 +173,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { if buf.len() < mem::size_of::() + data.len() { return Err(SyscallError::new(syscall::EINVAL)); } - - // Don't really care about endianness here as long as it's consistent with read - buf[0] = (seq_no & 0xff) as u8; - buf[1] = (seq_no >> 8) as u8; + NetworkEndian::write_u16(&mut buf[0..2], seq_no); for i in 0..data.len() { buf[mem::size_of::() + i] = data[i];