Merge pull request #8 from dlrobertson/use_byteorder
Use byteorder to improve readability
This commit is contained in:
Generated
+1
@@ -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)",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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::<u16>());
|
||||
// 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::<u16>() + 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::<u16>() + i] = data[i];
|
||||
|
||||
Reference in New Issue
Block a user