code: def arp_packet(opcode, src_mac, src_ip, dst_mac, dst_ip):
          
          # Generate ethernet header first.
          pkt = packet.Packet()
          eth_pkt = ethernet.ethernet(dst_mac, src_mac, ETH_TYPE_ARP)
          pkt.add_protocol(eth_pkt)
  
          # Use IPv4 ARP wrapper from packet library directly.
          arp_pkt = arp.arp_ip(opcode, src_mac, src_ip, dst_mac, dst_ip)
          pkt.add_protocol(arp_pkt)
  
          pkt.serialize()
          return pkt.data
docs: Generate ARP packet with ethernet encapsulated.