diff options
author | Linus Färnstrand <linus@mullvad.net> | 2018-04-03 16:52:33 +0200 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-06-03 11:56:44 -0500 |
commit | 4324ecd046c849f48afab39fc971bd9144075518 (patch) | |
tree | a52b56c4aa35182c975dd4c2948e746b042812c4 /src | |
parent | build: make Cargo.toml compile for people who aren't me ;) (diff) | |
download | wireguard-rs-4324ecd046c849f48afab39fc971bd9144075518.tar.xz wireguard-rs-4324ecd046c849f48afab39fc971bd9144075518.zip |
deps: Replace pnet_packet with rips-packets
Closes #11
Diffstat (limited to 'src')
-rw-r--r-- | src/interface/mod.rs | 2 | ||||
-rw-r--r-- | src/ip_packet.rs | 26 | ||||
-rw-r--r-- | src/lib.rs | 2 |
3 files changed, 13 insertions, 17 deletions
diff --git a/src/interface/mod.rs b/src/interface/mod.rs index c45e70f..7036a09 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::collections::HashMap; use types::{InterfaceInfo}; -use pnet_packet::ipv4::Ipv4Packet; +use rips_packets::ipv4::Ipv4Packet; use futures::{Future, Stream, Sink, unsync}; use tokio_core::reactor::Core; diff --git a/src/ip_packet.rs b/src/ip_packet.rs index 3de6a60..9150f5b 100644 --- a/src/ip_packet.rs +++ b/src/ip_packet.rs @@ -1,5 +1,5 @@ -use pnet_packet::ipv4::Ipv4Packet; -use pnet_packet::ipv6::Ipv6Packet; +use rips_packets::ipv4::Ipv4Packet; +use rips_packets::ipv6::Ipv6Packet; use std::net::IpAddr; pub enum IpPacket<'a> { @@ -9,35 +9,31 @@ pub enum IpPacket<'a> { impl<'a> IpPacket<'a> { pub fn new(packet: &'a [u8]) -> Option<Self> { - if packet.is_empty() { - return None; - } - - match packet[0] >> 4 { - 4 => Ipv4Packet::new(packet).map(IpPacket::V4), - 6 => Ipv6Packet::new(packet).map(IpPacket::V6), + match packet.get(0).map(|byte| *byte >> 4) { + Some(4) => Ipv4Packet::new(packet).map(IpPacket::V4), + Some(6) => Ipv6Packet::new(packet).map(IpPacket::V6), _ => None } } pub fn source(&self) -> IpAddr { match *self { - IpPacket::V4(ref packet) => packet.get_source().into(), - IpPacket::V6(ref packet) => packet.get_source().into(), + IpPacket::V4(ref packet) => packet.source().into(), + IpPacket::V6(ref packet) => packet.source().into(), } } pub fn destination(&self) -> IpAddr { match *self { - IpPacket::V4(ref packet) => packet.get_destination().into(), - IpPacket::V6(ref packet) => packet.get_destination().into(), + IpPacket::V4(ref packet) => packet.destination().into(), + IpPacket::V6(ref packet) => packet.destination().into(), } } pub fn length(&self) -> u16 { match *self { - IpPacket::V4(ref packet) => packet.get_total_length(), - IpPacket::V6(ref packet) => 40 + packet.get_payload_length(), + IpPacket::V4(ref packet) => packet.total_length(), + IpPacket::V6(ref packet) => 40 + packet.payload_length(), } } @@ -26,8 +26,8 @@ extern crate libc; extern crate mio; extern crate nix; extern crate notify; -extern crate pnet_packet; extern crate rand; +extern crate rips_packets; extern crate snow; extern crate socket2; extern crate subtle; |