title: Python raw socket not receiving ICMP packets
body: <p>
  I'm trying to use raw sockets in Python to send UDP packets to a host and then get the ICMP response back for the packet -- basically reimplementing traceroute.</p>
  
  <p>I've managed to correctly construct my IP and UDP headers and send the packet. I can see it in Wireshark. I also see the ICMP response in Wireshark telling me that the TTL exceeded.</p>
  
  <p>I have the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>me = gethostbyname(gethostname())
  my_socket = socket(AF_INET, SOCK_RAW)
  my_socket.setsockopt(IPPROTO_IP, IP_HDRINCL, 1)
  my_socket.bind((me, 0))
  
  hostname = 'www.google.com'
  hostip = gethostbyname(hostname)
  
  packet = create_packet(hostname)
  send_socket.sendto(packet, (hostip , 0))
  </code></pre>
  
  <p>Then after the packet is sent I call another function to listen for incoming packets which includes this snippet:</p>
  
  <pre class="lang-py prettyprint-override"><code>while True:
      ready = select.select([my_socket], [], [], time_left)
      if ready[0] == []:
          print "timeout"
      time_now = time.time()
      rec_packet, addr = my_socket.recvfrom(5120)
  
      unpacked_ip = unpack('!BBHHHBBH4s4s', rec_packet[0:20]) #0-20 is IP header
      prot = unpacked_ip[6] #gives the protocol id
      if prot == 1:
          #this is ICMP , let's do things
  </code></pre>
  
  <p>I'm able to successfully unpack the IP header and check the protocol, but it is always either 6 or 17 (TCP or UDP). I never get the IP packet containing the ICMP payload even though it appears in Wireshark.</p>
  
  <p>I've tried comparing the ICMP packet in Wireshark to other packets in Wireshark that my program does see and the IP headers are pretty much identical. I don't know what is wrong.</p>
  
  <p>Thanks for the help</p>