title: Prevent kernel from processing TCP segments bound to a raw socket
body: <p>According to <a href="http://linux.die.net/man/7/raw" rel="nofollow">http://linux.die.net/man/7/raw</a> , 
  <code>raw_socket = socket(AF_INET, SOCK_RAW, int protocol);</code> is the way to create a raw socket.</p>
  
  <ol>
  <li><p>I assume that raw-sockets are created on layer-3 and so protocol shouldn't be <code>IPPROTO_TCP</code> / <code>IPPROTO_UDP</code> but it should be <code>IPPROTO_IP</code>. Is this understanding correct?</p></li>
  <li><p>But when I create the raw socket with protocol as <code>IPPROTO_IP</code> (<code>*socketFd = socket(AF_INET, SOCK_RAW, IPPROTO_IP);</code>), socket creation fails with the error <em>Protocol not supported</em></p></li>
  <li><p>When I create the raw socket with protocol as <code>IPPROTO_RAW</code> (<code>*socketFd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);</code>), my application doesn't receive any of packets</p></li>
  <li><p>When I create the raw socket with protocol as <code>IPPROTO_TCP</code> (<code>socketFd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);</code>), my application receives the TCP packets, but kernel also responds to these packets (and in my case it RSTs the link). I assume it is because kernel thinks there isn't anybody listening to the port to which that packet is intended to.</p></li>
  </ol>
  
  <p>My intention is just to send responses to the messages coming to my application with a fake IP and TCP header. Since none of the above tries worked for me, how should I create the raw socket and make kernel TCP layer to be quiet for only that connection?</p>
  
  <p>EDIT:
  Please skip questions 1-3. They are already answered by Filipe. For ques 4, we do have a workaround. But keeping the question open, if someone out here has an answer and would like to answer it.</p>