message: Fix packet dump example on macos loopback interface.
diff: @@ -248,27 +248,41 @@ fn main() {
  let mut fake_ethernet_frame = MutableEthernetPacket::new(&mut buf[..]).unwrap();
  match rx.next() {
  Ok(packet) => {
  + let payload_offset;
  if cfg!(target_os = "macos") && interface.is_up() && !interface.is_broadcast()
  - && !interface.is_loopback() && interface.is_point_to_point()
  + && ((!interface.is_loopback() && interface.is_point_to_point())
  + || interface.is_loopback())
  + {
  + if interface.is_loopback()
  + {
  + // The pnet code for BPF loopback adds a zero'd out Ethernet header
  + payload_offset = 14;
  + }
  + else
  {
  // Maybe is TUN interface
  - let version = Ipv4Packet::new(&packet).unwrap().get_version();
  + payload_offset = 0;
  + }
  + if packet.len() > payload_offset
  + {
  + let version = Ipv4Packet::new(&packet[payload_offset..]).unwrap().get_version();
  if version == 4 {
  fake_ethernet_frame.set_destination(MacAddr(0, 0, 0, 0, 0, 0));
  fake_ethernet_frame.set_source(MacAddr(0, 0, 0, 0, 0, 0));
  fake_ethernet_frame.set_ethertype(EtherTypes::Ipv4);
  - fake_ethernet_frame.set_payload(&packet);
  + fake_ethernet_frame.set_payload(&packet[payload_offset..]);
  handle_ethernet_frame(&interface, &fake_ethernet_frame.to_immutable());
  continue;
  } else if version == 6 {
  fake_ethernet_frame.set_destination(MacAddr(0, 0, 0, 0, 0, 0));
  fake_ethernet_frame.set_source(MacAddr(0, 0, 0, 0, 0, 0));
  fake_ethernet_frame.set_ethertype(EtherTypes::Ipv6);
  - fake_ethernet_frame.set_payload(&packet);
  + fake_ethernet_frame.set_payload(&packet[payload_offset..]);
  handle_ethernet_frame(&interface, &fake_ethernet_frame.to_immutable());
  continue;
  }
  }
  + }
  handle_ethernet_frame(&interface, &EthernetPacket::new(packet).unwrap());
  }
  Err(e) => panic!("packetdump: unable to receive packet: {}", e),
  