pnet 0.5.1

Cross-platform, low level networking using the Rust programming language.
diff --git a/pnet_macros/src/lint.rs b/pnet_macros/src/lint.rs
index 6119bf8..85a61fc 100644
--- a/pnet_macros/src/lint.rs
+++ b/pnet_macros/src/lint.rs
@@ -8,12 +8,7 @@
 
 //! Linting and other functionality which requires type information
 
-use syntax::ast;
-use syntax::attr::AttrMetaMethods;
-use syntax::parse::token;
-use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
-use rustc::middle::ty::{node_id_to_type_opt, ty_to_def_id};
-//use rustc::plugin::Registry;
+use rustc::lint::{LintPass, LintArray};
 
 declare_lint! {
     PACKET_LINT,
@@ -23,84 +18,8 @@ declare_lint! {
 
 pub struct PacketPass;
 
-fn get_attr<'a>(attrs: &'a [ast::Attribute], name: &str) -> &'a ast::MetaItem_ {
-    &attrs.iter().filter(|a| a.check_name(name)).nth(0).unwrap().node.value.node
-}
-
-fn has_attr(attrs: &[ast::Attribute], name: &str) -> bool {
-    attrs.iter().filter(|a| a.check_name(name)).count() != 0
-}
-
-fn check_struct(ctxt: &Context, sd: &ast::StructDef) {
-    //let fields = &sd.fields;
-    //for ref field in fields {
-    //    if has_attr(&field.node.attrs[..], "length_fn") {
-    //        match get_attr(&field.node.attrs[..], "length_fn") {
-    //            &ast::MetaNameValue(ref s, ref lit) => {
-    //                let ref node = lit.node;
-    //                match node {
-    //                    &ast::LitStr(ref s, _) => {
-    //                        //s.to_string()
-    //                    },
-    //                    _ => panic!("this should be caught before linting")
-    //                }
-    //            },
-    //            _ => panic!("this should be caught before linting")
-    //        }
-    //    }
-    //    //println!("field: {}", field.node.ident().unwrap());
-    //    //println!("field ty: {:?}", field.node.ty.node);
-    //}
-}
-
 impl LintPass for PacketPass {
     fn get_lints(&self) -> LintArray {
         lint_array!(PACKET_LINT)
     }
-    fn check_item(&mut self, ctxt: &Context, item: &ast::Item) {
-        // Find any structs/enums marked as #[packet],
-        // for each member field, ensure that either:
-        //  * it's a u<N>_<be/le>, or
-        //  * it implements some trait to give the on the wire repr/reverse it
-        //  * it's a type made of up the above
-        // make sure there's some way for the decorator pass to know the size/how
-        // to convert it
-
-        if item.attrs.iter().filter(|a| a.check_name("_packet_lint")).count() == 0 {
-            return;
-        }
-        //println!("item: {}", item.ident.as_str().to_string());
-        match item.node {
-            ast::ItemEnum(..) => unimplemented!(),
-            ast::ItemStruct(ref sd, ref _gs) => {
-                check_struct(ctxt, sd);
-            },
-            _ => panic!("this should be caught before linting")
-        }
-//println!("      _               _    _               _ _                     
-//  ___| |__   ___  ___| | _(_)_ __   __ _  (_) |_ ___ _ __ ___  ___ 
-// / __| '_ \\ / _ \\/ __| |/ / | '_ \\ / _` | | | __/ _ \\ '_ ` _ \\/ __|
-//| (__| | | |  __/ (__|   <| | | | | (_| | | | ||  __/ | | | | \\__ \\
-// \\___|_| |_|\\___|\\___|_|\\_\\_|_| |_|\\__, | |_|\\__\\___|_| |_| |_|___/
-//                                   |___/                           
-//");
-//        println!("item: {}", item.ident.as_str().to_string());
-//        println!("attrs: {:?}", item.attrs);
-
- //       if let Some(nid) = node_id_to_type_opt(ctxt.tcx, item.id) {
- //           println!("has nid");
- //           if let Some(def_id) = ty_to_def_id(nid) {
- //           println!("has did");
- //               println!("impls {:?}", ctxt.tcx.trait_impls.borrow().get(&def_id));
- //           } else {
- //           println!("no did");
- //           }
- //       } else {
- //           println!("no nid");
-
- //       }
-        //println!("traits: {:?}", ctxt.tcx.trait_defs);
-        //println!("attrs: {:?}", item.attrs);
-
-    }
 }
diff --git a/pnet_macros/src/util.rs b/pnet_macros/src/util.rs
index 7e9e996..f13a463 100644
--- a/pnet_macros/src/util.rs
+++ b/pnet_macros/src/util.rs
@@ -9,7 +9,6 @@
 //! Utility functions for bit manipulation operations
 
 use std::fmt;
-use std::num::SignedInt;
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 pub enum Endianness {
@@ -440,6 +439,7 @@ fn test_to_mutator() {
 
 /// Takes a set of operations to get a field in big endian, and converts them to get the field in
 /// little endian.
-pub fn to_little_endian(ops: Vec<GetOperation>) -> Vec<GetOperation> {
+pub fn to_little_endian(_ops: Vec<GetOperation>) -> Vec<GetOperation> {
+    // FIXME
     unimplemented!()
 }
diff --git a/src/datalink/netmap.rs b/src/datalink/netmap.rs
index 50a79d1..57f324e 100644
--- a/src/datalink/netmap.rs
+++ b/src/datalink/netmap.rs
@@ -18,9 +18,10 @@ use self::netmap_sys::netmap_user::{nm_open, nm_close, nm_nextpkt, nm_desc, nm_p
 use self::netmap_sys::netmap::{nm_ring_empty, netmap_slot};
 
 use std::ffi::CString;
-use std::old_path::Path;
-use std::old_io::fs::File;
-use std::old_io::{Reader};
+use std::path::Path;
+use std::fs::File;
+use std::io;
+use std::io::Read;
 use std::mem;
 use std::num;
 use std::ptr;
@@ -28,8 +29,8 @@ use std::raw;
 use std::sync::Arc;
 
 use datalink::DataLinkChannelType;
-use old_packet::Packet;
-use old_packet::ethernet::{EthernetHeader, MutableEthernetHeader};
+use packet::Packet;
+use packet::ethernet::{EthernetPacket, MutableEthernetPacket};
 use util::{NetworkInterface};
 
 #[cfg(target_os = "linux")]
@@ -58,7 +59,7 @@ struct NmDesc {
 
 impl NmDesc {
     fn new(iface: &NetworkInterface) -> io::Result<NmDesc> {
-        let ifname = CString::new(("netmap:".to_string() + iface.name.as_slice()).as_bytes());
+        let ifname = CString::new(("netmap:".to_string() + &iface.name[..]).as_bytes());
         let desc = unsafe {
             nm_open(ifname.unwrap().as_ptr(), ptr::null(), 0, ptr::null())
         };
@@ -67,7 +68,8 @@ impl NmDesc {
             Err(io::Error::last_os_error())
         } else {
             let mut f = try!(File::open(&Path::new("/sys/module/netmap/parameters/buf_size")));
-            let num_str = try!(f.read_to_string());
+            let mut num_str = String::new();
+            try!(f.read_to_string(&mut num_str));
             let buf_size = num_str.trim_right().parse().unwrap();
 
             Ok(NmDesc {
@@ -94,7 +96,7 @@ pub struct DataLinkSenderImpl {
 impl DataLinkSenderImpl {
     pub fn build_and_send<F>(&mut self, num_packets: usize, packet_size: usize,
                           func: &mut F) -> Option<io::Result<()>>
-        where F : FnMut(MutableEthernetHeader)
+        where F : FnMut(MutableEthernetPacket)
     {
         assert!(num::cast::<usize, u16>(packet_size).unwrap() as c_uint <= self.desc.buf_size);
         let desc = self.desc.desc;
@@ -115,7 +117,7 @@ impl DataLinkSenderImpl {
                     let slot_ptr: *mut netmap_slot = mem::transmute(&mut (*ring).slot);
                     let buf = NETMAP_BUF(ring, (*slot_ptr.offset(i as isize)).buf_idx as isize);
                     let slice = raw::Slice { data: buf, len: packet_size };
-                    let meh = MutableEthernetHeader::new(mem::transmute(slice));
+                    let meh = MutableEthernetPacket::new(mem::transmute(slice));
                     (*slot_ptr.offset(i as isize)).len = packet_size as u16;
                     func(meh);
                     let next = nm_ring_next(ring, i);
@@ -129,10 +131,10 @@ impl DataLinkSenderImpl {
         Some(Ok(()))
     }
 
-    pub fn send_to(&mut self, packet: &EthernetHeader, _dst: Option<NetworkInterface>)
+    pub fn send_to(&mut self, packet: &EthernetPacket, _dst: Option<NetworkInterface>)
         -> Option<io::Result<()>> {
-        use old_packet::MutablePacket;
-        self.build_and_send(1, packet.packet().len(), &mut |mut eh: MutableEthernetHeader| {
+        use packet::MutablePacket;
+        self.build_and_send(1, packet.packet().len(), &mut |mut eh: MutableEthernetPacket| {
             eh.clone_from(packet);
         })
     }
@@ -174,7 +176,7 @@ pub struct DataLinkChannelIteratorImpl<'a> {
 }
 
 impl<'a> DataLinkChannelIteratorImpl<'a> {
-    pub fn next<'c>(&'c mut self) -> io::Result<EthernetHeader<'c>> {
+    pub fn next<'c>(&'c mut self) -> io::Result<EthernetPacket<'c>> {
         let desc = self.pc.desc.desc;
         let mut h: nm_pkthdr = unsafe { mem::uninitialized() };
         let mut buf = unsafe { nm_nextpkt(desc, &mut h) };
@@ -189,7 +191,7 @@ impl<'a> DataLinkChannelIteratorImpl<'a> {
             }
             buf = unsafe { nm_nextpkt(desc, &mut h) };
         }
-        Ok(EthernetHeader::new( unsafe {
+        Ok(EthernetPacket::new( unsafe {
             mem::transmute(raw::Slice { data: buf, len: h.len as usize })
         }))
     }
diff --git a/src/lib.rs b/src/lib.rs
index 4a5b5e6..8404562 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,13 +47,14 @@
 //! use pnet::old_packet::ethernet::EthernetPacket;
 //! use pnet::util::{NetworkInterface, get_network_interfaces};
 //!
-//! use std::os;
+//! use std::env;
 //!
 //! // Invoke as echo <interface name>
 //! // FIXME Remove before 1.0
 //! #[allow(unstable)]
 //! fn main() {
-//!     let interface_names_match = |iface: &NetworkInterface| iface.name == os::args()[1];
+//!     let interface_name = env::args().nth(1).unwrap();
+//!     let interface_names_match = |iface: &NetworkInterface| iface.name == interface_name;
 //!
 //!     // Find the network interface with the provided name
 //!     let interfaces = get_network_interfaces();
@@ -108,8 +109,6 @@
            plugin, slice_patterns)]
 #![plugin(pnet_macros)]
 #![cfg_attr(test, feature(str_char))]
-#![plugin(pnet_macros)]
-#![cfg_attr(feature = "netmap", feature(old_path))]
 
 extern crate libc;
 extern crate pnet_macros;
diff --git a/src/lib.rs.orig b/src/lib.rs.orig
new file mode 100644
index 0000000..6211d75
--- /dev/null
+++ b/src/lib.rs.orig
@@ -0,0 +1,138 @@
+// Copyright (c) 2014 Robert Clipsham <robert@octarineparrot.com>
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! # libpnet
+//!
+//! `libpnet` provides a cross-platform API for low level networking using Rust.
+//!
+//! There are three key components:
+//!
+//!  * The old_packet module, allowing safe construction and manipulation of packets
+//!  * The transport module, which allows implementation of transport protocols
+//!  * The datalink module, which allows sending and receiving data link packets directly
+//!
+//! ## Terminology
+//!
+//! The documentation uses the following terms interchangably:
+//!
+//!  * Layer 2, datalink layer
+//!  * Layer 3, network layer
+//!  * Layer 4, transport layer
+//!
+//! Unless otherwise stated, all interactions with libpnet are in host-byte order - any platform
+//! specific variations are handled internally.
+//!
+//! ## Examples
+//!
+//! More examples, including a packet logger, and a version of the echo server written at the
+//! transport layer, can be found in the examples/ directory.
+//!
+//! ### Ethernet echo server
+//!
+//! This (fairly useless) code implements an Ethernet echo server. Whenever a packet is received on
+//! an interface, it echo's the packet back; reversing the source and destination addresses.
+//!
+//! ```rust,no_run
+//! #![feature(os)]
+//! extern crate pnet;
+//!
+//! use pnet::datalink::{datalink_channel};
+//! use pnet::datalink::DataLinkChannelType::{Layer2};
+//! use pnet::old_packet::{MutablePacket, Packet};
+//! use pnet::old_packet::ethernet::EthernetPacket;
+//! use pnet::util::{NetworkInterface, get_network_interfaces};
+//!
+//! use std::env;
+//!
+//! // Invoke as echo <interface name>
+//! // FIXME Remove before 1.0
+//! #[allow(unstable)]
+//! fn main() {
+//!     let interface_name = env::args().nth(1).unwrap();
+//!     let interface_names_match = |iface: &NetworkInterface| iface.name == interface_name;
+//!
+//!     // Find the network interface with the provided name
+//!     let interfaces = get_network_interfaces();
+//!     let interface = interfaces.into_iter()
+//!                               .filter(interface_names_match)
+//!                               .next()
+//!                               .unwrap();
+//!
+//!     // Create a new channel, dealing with layer 2 packets
+//!     let (mut tx, mut rx) = match datalink_channel(&interface, 4096, 4096, Layer2) {
+//!         Ok((tx, rx)) => (tx, rx),
+//!         Err(e) => panic!("An error occurred when creating the datalink channel: {}", e)
+//!     };
+//!
+//!     let mut iter = rx.iter();
+//!     loop {
+//!         match iter.next() {
+//!             Ok(packet) => {
+//!                 // Constructs a single packet, the same length as the the one received,
+//!                 // using the provided closure. This allows the packet to be constructed
+//!                 // directly in the write buffer, without copying. If copying is not a
+//!                 // problem, you could also use send_to.
+//!                 //
+//!                 // The packet is sent once the closure has finished executing.
+//!                 tx.build_and_send(1, packet.packet().len(), &mut |mut new_packet| {
+//!                     // Create a clone of the original packet
+//!                     new_packet.clone_from(packet);
+//!
+//!                     // Switch the source and destination
+//!                     new_packet.set_source(packet.get_destination());
+//!                     new_packet.set_destination(packet.get_source());
+//!                 });
+//!             },
+//!             Err(e) => {
+//!                 // If an error occurs, we can handle it here
+//!                 panic!("An error occurred while reading: {}", e);
+//!             }
+//!         }
+//!     }
+//! }
+//! ```
+
+#![crate_name = "pnet"]
+#![crate_type = "rlib"]
+#![crate_type = "dylib"]
+
+#![deny(missing_docs)]
+
+// FIXME Remove this once the std lib has stabilised
+<<<<<<< HEAD
+#![feature(alloc, convert, core, collections, custom_attribute, old_io,
+           libc, os, plugin, slice_patterns, std_misc)]
+#![plugin(pnet_macros)]
+=======
+#![feature(alloc, core, collections, convert, old_io, libc, os, std_misc)]
+>>>>>>> 67f172158a19120371251391ed96c5f92bbeb161
+#![cfg_attr(test, feature(str_char))]
+#![cfg_attr(feature = "netmap", feature(old_path))]
+
+extern crate libc;
+extern crate pnet_macros;
+
+pub mod datalink;
+pub mod old_packet;
+pub mod packet;
+pub mod transport;
+pub mod util;
+
+mod bindings;
+mod internal;
+
+// NOTE should probably have a cfg(pnet_test_network) here, but cargo doesn't allow custom --cfg
+//      flags
+#[cfg(test)]
+mod test;
+
+// Required to make sure that imports from pnet_macros work
+mod pnet {
+    pub use packet;
+}
+