title: How to check for presence of a layer in a scapy packet?
body: <p>How do I check for the presence of a particular layer in a scapy packet? For example, I need to check the src/dst fields of an IP header, how do I know that a particular packet actually has an IP header (as opposed to IPv6 for instance).</p>
  
  <p>My problem is that when I go to check for an IP header field, I get an error saying that the IP layer doesn't exist. Instead of an IP header, this particular packet had IPv6.</p>
  
  <pre><code>pkt = Ether(packet_string)
  if pkt[IP].dst == something:
    # do this
  </code></pre>
  
  <p>My error occurs when I try to reference the IP layer. How do I check for that layers existence before attempting to manipulate it?</p>
  
  <p>Thanks!</p>