fn pnet_build_packet(buf: &mut [u8], dst_mac: MacAddr, payload: &[u8]) {
        let mut eth = MutableEthernetPacket::new(buf).unwrap();
        eth.set_source(MacAddr::new(0x06, 0, 0, 0, 0, 0));
        eth.set_destination(dst_mac);
        eth.set_ethertype(EtherTypes::Ipv4);

        let mut ipv4 = MutableIpv4Packet::new(eth.payload_mut()).unwrap();
        ipv4.set_version(4);
        ipv4.set_header_length(5);
        ipv4.set_total_length(20 + 8 + payload.len() as u16);
        ipv4.set_ttl(200);
        ipv4.set_next_level_protocol(IpNextHeaderProtocols::Udp);
        ipv4.set_source(Ipv4Addr::new(192, 168, 241, 1));
        ipv4.set_destination(Ipv4Addr::new(192, 168, 241, 2));

        let mut udp = MutableUdpPacket::new(ipv4.payload_mut()).unwrap();
        udp.set_source(1000);
        udp.set_destination(1001);
        udp.set_length(8 + payload.len() as u16);
        udp.set_payload(payload);
    }
// Given a buffer of appropriate size, this fills in the relevant fields based on the
// provided information. Payload refers to the UDP payload.
Given a buffer of appropriate size, this fills in the relevant fields based on the
provided information. Payload refers to the UDP payload.
Given a buffer of appropriate size this fills in the relevant fields based on the provided information . Payload refers to the UDP payload .
fn pnet_build_packet(buf: &mut [u8], dst_mac: MacAddr, payload: &[u8]) {
        let mut eth = MutableEthernetPacket::new(buf).unwrap();
        eth.set_source(MacAddr::new(0x06, 0, 0, 0, 0, 0));
        eth.set_destination(dst_mac);
        eth.set_ethertype(EtherTypes::Ipv4);
        let mut ipv4 = MutableIpv4Packet::new(eth.payload_mut()).unwrap();
        ipv4.set_version(4);
        ipv4.set_header_length(5);
        ipv4.set_total_length(20 + 8 + payload.len() as u16);
        ipv4.set_ttl(200);
        ipv4.set_next_level_protocol(IpNextHeaderProtocols::Udp);
        ipv4.set_source(Ipv4Addr::new(192, 168, 241, 1));
        ipv4.set_destination(Ipv4Addr::new(192, 168, 241, 2));
        let mut udp = MutableUdpPacket::new(ipv4.payload_mut()).unwrap();
        udp.set_source(1000);
        udp.set_destination(1001);
        udp.set_length(8 + payload.len() as u16);
        udp.set_payload(payload);
    }
fn pnet_build_packet ( buf : & mut [ u8 ] , dst_mac : MacAddr , payload : & [ u8 ] ) { let mut eth = MutableEthernetPacket :: new ( buf ) . unwrap ( ) ; eth . set_source ( MacAddr :: new ( 0x06 , 0 , 0 , 0 , 0 , 0 ) ) ; eth . set_destination ( dst_mac ) ; eth . set_ethertype ( EtherTypes :: Ipv4 ) ; let mut ipv4 = MutableIpv4Packet :: new ( eth . payload_mut ( ) ) . unwrap ( ) ; ipv4 . set_version ( 4 ) ; ipv4 . set_header_length ( 5 ) ; ipv4 . set_total_length ( 20 + 8 + payload . len ( ) as u16 ) ; ipv4 . set_ttl ( 200 ) ; ipv4 . set_next_level_protocol ( IpNextHeaderProtocols :: Udp ) ; ipv4 . set_source ( Ipv4Addr :: new ( 192 , 168 , 241 , 1 ) ) ; ipv4 . set_destination ( Ipv4Addr :: new ( 192 , 168 , 241 , 2 ) ) ; let mut udp = MutableUdpPacket :: new ( ipv4 . payload_mut ( ) ) . unwrap ( ) ; udp . set_source ( 1000 ) ; udp . set_destination ( 1001 ) ; udp . set_length ( 8 + payload . len ( ) as u16 ) ; udp . set_payload ( payload ) ; }
Given a buffer of appropriate size, this fills in the relevant fields based on the
provided information.
Given a buffer of appropriate size this fills in the relevant fields based on the provided information .
buf
&mut [u8]
dst_mac
MacAddr
payload
&[u8]
buf
&mut [u8]
dst_mac
MacAddr
payload
&[u8]