diff --git a/src/main.rs b/src/main.rs index 804d471..0ba61b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,7 +142,7 @@ fn main() { let interfaces = pnet_datalink::interfaces(); let interface = interfaces.into_iter().next().unwrap(); // let (mut tx, mut rx) = match transport_channel(1500, Layer3(IpNextHeaderProtocols::Udp)) { - let (mut tx, mut rx) = match transport_channel(1500, Layer3(pnet_packet::ip::IpNextHeaderProtocols::Ipv4)) { + let (mut tx, mut rx) = match transport_channel(1500, Layer3(pnet_packet::ip::IpNextHeaderProtocols::Icmp)) { // let (mut tx, mut rx) = match transport_channel(1500, Layer4(Ipv4(Icmp))) { Ok((tx, rx)) => (tx, rx), Err(e) => panic!("An error occurred when creating transport channel: {}", e), @@ -157,8 +157,8 @@ fn main() { // Create a new mutable ICMP packet let mut binding = [4;64]; - // let mut packet = icmp::MutableIcmpPacket::new(&mut binding).expect("Couldn't create packet"); - let mut packet = pnet_packet::ipv4::MutableIpv4Packet::new(&mut binding).expect("Couldn't create packet"); + let mut packet = icmp::MutableIcmpPacket::new(&mut binding).expect("Couldn't create packet"); + // let mut packet = pnet_packet::ipv4::MutableIpv4Packet::new(&mut binding).expect("Couldn't create packet"); // // Set the ICMP packet type and code to the appropriate values for a ping request // packet.set_icmp_type(icmp::IcmpTypes::EchoRequest); // packet.set_icmp_code(pnet::packet::icmp::IcmpCode(0xaa)); @@ -169,29 +169,31 @@ fn main() { let IDENT_NUM: u16 = 111; // Create a new mutable Ethernet packet containaing the ICMP packet let mut binding = [3; 64+32]; - // let mut ethernet_packet = MutableEthernetPacket::new(&mut binding).unwrap(); - let mut ethernet_packet = pnet_packet::ipv4::MutableIpv4Packet::new(&mut binding).unwrap(); + let mut ethernet_packet = MutableEthernetPacket::new(&mut binding).unwrap(); + // let mut ethernet_packet = pnet_packet::ipv4::MutableIpv4Packet::new(&mut binding).unwrap(); // ethernet_packet.set_icmp_type(); // Set the destination and source MAC addresses // ethernet_packet.set_destination(interface.mac.unwrap().clone()); // // ethernet_packet.set_source(interface.mac.unwrap()); - ethernet_packet.set_version(4); - ethernet_packet.set_header_length(5); - ethernet_packet.set_dscp(0); - ethernet_packet.set_ecn(0); - ethernet_packet.set_ttl(64); - ethernet_packet.set_identification(8); - ethernet_packet.set_flags(1); - ethernet_packet.set_next_level_protocol(pnet_packet::ip::IpNextHeaderProtocols::Ipv4);//pnet_packet::ip::IpNextHeaderProtocol(6)); - - ethernet_packet.set_source("192.168.1.3".parse::().expect("Couldn't set destination")); - ethernet_packet.set_destination("192.168.1.1".parse::().expect("Couldn't set destination")); + // IPv4 - ethernet_packet.set_checksum(ethernet_packet.get_checksum()); - println!("Lgh {}",ethernet_packet.get_total_length()); - ethernet_packet.set_total_length(110); + // ethernet_packet.set_version(4); + // ethernet_packet.set_header_length(5); + // ethernet_packet.set_dscp(0); + // ethernet_packet.set_ecn(0); + // ethernet_packet.set_ttl(64); + // ethernet_packet.set_identification(8); + // ethernet_packet.set_flags(1); + // ethernet_packet.set_next_level_protocol(pnet_packet::ip::IpNextHeaderProtocols::Ipv4);//pnet_packet::ip::IpNextHeaderProtocol(6)); + + // ethernet_packet.set_source("192.168.1.3".parse::().expect("Couldn't set destination")); + // ethernet_packet.set_destination("192.168.1.1".parse::().expect("Couldn't set destination")); + + // ethernet_packet.set_checksum(ethernet_packet.get_checksum()); + // println!("Lgh {}",ethernet_packet.get_total_length()); + // ethernet_packet.set_total_length(110); // // ethernet_packet.set_source(interface.mac.unwrap());