Search code examples
c++csocketstcpraw-sockets

Connect function in raw socket?


I am trying to initiate a TCP Three-Way-Handshake in C. However, it occurred to me that connect may already be establishing such a connection or in some way interfering. Does connect automatically establish a TCP connection whenever the socket it's called on has the IPPROTO_TCP option set?


Solution

  • Yes, IPPROTO_TCP creates TCP socket. To use raw socket, you need to pass SOCK_RAW as second argument to the socket function.