Sends a test packet on the interface named "ifname".
(ifname: &str)
| 674 | |
| 675 | // Sends a test packet on the interface named "ifname". |
| 676 | fn pnet_send_packet(ifname: &str) { |
| 677 | let payload = DATA_STRING.as_bytes(); |
| 678 | |
| 679 | // eth hdr + ip hdr + udp hdr + payload len |
| 680 | let buf_size = 14 + 20 + 8 + payload.len(); |
| 681 | |
| 682 | let (mac, mut tx, _) = pnet_get_mac_tx_rx(ifname); |
| 683 | |
| 684 | let res = tx.build_and_send(1, buf_size, &mut |buf| { |
| 685 | pnet_build_packet(buf, mac, payload); |
| 686 | }); |
| 687 | // Make sure build_and_send() -> Option<io::Result<()>> succeeds. |
| 688 | res.unwrap().unwrap(); |
| 689 | } |
| 690 | |
| 691 | // For a given interface name, this returns a tuple that contains the MAC address of the |
| 692 | // interface, an object that can be used to send Ethernet frames, and a receiver of |