diff --git a/src/parser/packet_handler.rs b/src/parser/packet_handler.rs index 38729c5..154aca6 100644 --- a/src/parser/packet_handler.rs +++ b/src/parser/packet_handler.rs @@ -2,7 +2,7 @@ extern crate eui48; extern crate byteorder; extern crate bitfield; -use byteorder::{ByteOrder, LittleEndian, ReadBytesExt}; +use byteorder::{ByteOrder, BigEndian, LittleEndian, ReadBytesExt}; use eui48::{MacAddress, Eui48}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use bitfield::{bitfield, BitRange}; @@ -140,30 +140,18 @@ pub fn ipv6_handler ( packet_data: &[u8] ) -> IpV6Header { IpV6Header { - version: &raw_hdr[0] & 0xf0 >> 4, - traffic_class: (&raw_hdr[0] & 0x0f >> 4)| (&raw_hdr[1] & 0xf0 <<4) , - flow_label: LittleEndian::read_u32( &[0x00 ,(&_tail[1] &0x0f) , _tail[2] , _tail[3]]), - payload_length: LittleEndian::read_u16(&[_tail[4], _tail[5]]), + version: (&raw_hdr[0] & 0xf0) >> 4, + traffic_class: ((&raw_hdr[0] & 0x0f) >> 4)| ((&raw_hdr[1] & 0xf0 <<4)) , + flow_label: BigEndian::read_u32( &[0x00 ,(&_tail[1] &0x0f) , _tail[2] , _tail[3]]), + payload_length: BigEndian::read_u16(&[_tail[4], _tail[5]]), next_header: _tail[6], hop_limit: _tail[7], - source_address: IpAddr::V6(Ipv6Addr::from(LittleEndian::read_u128(&_tail[8..24]))), - destination_address: IpAddr::V6(Ipv6Addr::from(LittleEndian::read_u128(&_tail[24..40]))), + source_address: IpAddr::V6(Ipv6Addr::from(BigEndian::read_u128(&_tail[8..24]))), + destination_address: IpAddr::V6(Ipv6Addr::from(BigEndian::read_u128(&_tail[24..40]))), } } -/* -#[derive(Debug,Copy, Clone)] -pub struct IpV6Header { - pub version: u32, - pub traffic_class: u32, - pub flow_label: u32, - pub payload_length: u32, - pub next_header: u32, - pub hop_limit: u32, - pub source_address: IpAddr, - pub destination_address: IpAddr, -}*/ -/* I ve got no glue how this bitfield syntax works with impl and bitranges involved, if you do plz tell me */ +/* I ve got no glue how this bitfield macro syntax works with impl and bitranges involved, if you do plz enlighten me */ /*bitfield!{ struct BitfieldIpV6Header (MSB0 [u8]); impl Debug;