title: Reading a TCP header and managing a TCP connection with RAW_SOCKET
body: <p>I'm trying to get the TCP header of a TCP connection in C++11. Reading through already existing StackOverflow questions (<a href="https://stackoverflow.com/questions/9905528/how-to-access-tcp-header-details">here</a>, <a href="https://stackoverflow.com/questions/16528868/c-linux-kernel-module-tcp-header">here</a>, <a href="https://stackoverflow.com/questions/52631600/retrieving-tcp-header-using-boostasioiptcp-socket">here</a> and <a href="https://stackoverflow.com/questions/37839444/accessing-tcp-header-fields-without-raw-socket-api">here</a>) it seems like I have to open a <code>RAW_SOCKET</code> or to write a Linux Kernel Module (LKM) to have access to it.</p>
  
  <p>From what I've understood, opening a raw socket means handling the whole TCP protocol (handshake, window size, etc...). Is there a way to obtain the TCP header and let the kernel manage the TCP protocol (either "by hand" or with some framework)?</p>
  
  <p>I know I could use libpcap for capturing the packets, but this would mean for my application making somehow a match from the incoming packet in the TCP socket and the captured packet from libpcap. While this is a possible solution, it'd be a cumbersome one (and I wouldn't like to do that).</p>
  
  <p>Any help is appreciated, thank you!</p>