ipv6 are correct now

This commit is contained in:
gurkenhabicht 2020-05-18 17:31:25 +02:00
parent 9c15ce850c
commit a2d6ebe535
1 changed files with 8 additions and 20 deletions

View File

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