title: Unable to send UDP packets to local port with python, fails checksum according to WireShark
body: <p>I've been pulling my hair out over this one. I'm trying to write a SOCKS5 server in Python to tunnel UDP traffic. I bind to a port, and receive data fine. I then parse the SOCKS5 UDP header (not the typical UDP header), and forward the datagram to the requested endpoint.</p>
  <p>All is good. I then listen for a response from the endpoint (resending if timeout), and get a response. Great!</p>
  <p>Here is where I'm losing my mind-</p>
  <p>I get the datagram back from the endpoint. I re-encapsulate the returned datagram according to the <a href="https://www.rfc-editor.org/rfc/rfc1928" rel="nofollow noreferrer">SOCKS5 RFC</a>, which is the same UDP header as before, except I have now changed the destination address and port to the original caller. I use:</p>
  <pre><code>sock_client = socket.socket(socket.AF_INET, # Internet
                              socket.SOCK_DGRAM) # UDP
  sock_client.sendto(packed_datagram, (self.client_ip, self.client_port))
  </code></pre>
  <p>to send the datagram back to client. The client never receives the reply! Ever!</p>
  <p>Looking at WireShark, it says this: Header checksum: 0x0000 [incorrect, should be 0xcd1f (may be caused by &quot;IP checksum offload&quot;?)]</p>
  <p>Shouldn't the python socket implementation, with socket.DGRAM set, automatically pack my data correctly in a UDP header and calculate the appropriate checksum? Why is it being set to 0x0000? I checked the payload in hex, the checksum is indeed set wrong. What the heck is going on?</p>