C - create TCP SYN without filling IP header using raw socket <p>I want my application to create TCP SYN packet and send on network. I did not set <code>IP_HDRINCL</code> using <code>setsockopt</code> because I want the kernel to fill the IP Header.</p> <p>I tried </p> <ol> <li>using a byte buffer to include TCP Header + Payload </li> <li>using a byte buffer to include IP Header + TCP Header + Payload.</li> </ol> <p>Both above methods returned <code>sendto</code> error -1 and errno is set to 88 Following is the code I used </p> <pre><code>#include &lt;sys/socket.h&gt; #include &lt;sys/types.h&gt; #include &lt;netinet/in.h&gt; #include &lt;netinet/ip.h&gt; #include &lt;netinet/tcp.h&gt; #include &lt;errno.h&gt; int main() { int sockfd; if(sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP) &lt; 0) { printf("sokcet functin failed : \n"); exit (-1); } char packet[512]; struct sockaddr_in remote; // remote address struct iphdr *ip = (struct iphdr *) packet; struct tcphdr *tcp = (struct tcphdr *) packet + sizeof(struct iphdr); /* struct tcphdr *tcp = (struct tcphdr *) packet; // tcp header */ remote.sin_family = AF_INET; // family remote.sin_addr.s_addr = inet_addr("192.168.0.57"); // destination ip remote.sin_port = htons(atoi("3868")); // destination port memset(packet, 0, 512); // set packet to 0 tcp-&gt;source = htons(atoi("6668")); // source port tcp-&gt;dest = htons(atoi("3868")); // destination port tcp-&gt;seq = htons(random()); // inital sequence number tcp-&gt;ack_seq = htons(0); // acknowledgement number tcp-&gt;ack = 0; // acknowledgement flag tcp-&gt;syn = 1; // synchronize flag tcp-&gt;rst = 0; // reset flag tcp-&gt;psh = 0; // push flag tcp-&gt;fin = 0; // finish flag tcp-&gt;urg = 0; // urgent flag tcp-&gt;check = 0; // tcp checksum tcp-&gt;doff = 5; // data offset int err; if((err = sendto(sockfd, packet, sizeof(struct iphdr), 0, (struct sockaddr *)&amp;remote, sizeof(struct sockaddr))) &lt; 0) { // send packet printf("Error: Can't send packet : %d %d !\n\n", err, errno); return -1; } </code></pre> <p>Why i am getting the <code>sendto</code> error -1 and errno 88? </p> <p>Also, I want to know how to determine the length of data that is to be used in second argument in <code>sendto</code> function. If I hard code it to size of packet byte buffer i.e. 512 bytes, is it wrong ? </p>