Constructing a TCP packet with libnet
Using Transmission Control Protocol (TCP), a device sends packets to other devices on an IP network. TCP is designed to provide a reliable, ordered, and error-checked delivery of packets between applications. This does add additional overheads as compared to UDP, so applications that do not require reliability should use UDP instead.
When a device wants to communicate with another device using TCP, a three-way handshake must occur. The first device begins by sending a TCP packet with the SYN flag set. This is like saying, "Hi Joe. Can we talk?" The remote device is supposed to respond with a packet that has the SYN/ACK (synchronize/acknowledge) flags set, which is like Joe saying, "Sure, we can talk. What's up?" The three-way handshake is completed when the first device responds again with a packet that has the ACK flag set. This is like responding to Joe by saying, "Good, because I have something important to tell you."
The following diagram shows the...