three-way handshake

Feb 23, 2011 at 8:49 PM

Hi everyone

Im trying to initiate a three-way hand shake between two devices (a PC and Lapop) , when i send a TCP packet with the Synchronization bit set [Syn] i get nothing in return , no [Syn,Ack] or anything , which is really weird , Here is The Code :

Packet packet = PacketBuilder.Build(DateTime.Now,
                    new EthernetLayer
                        Source = source,
                        Destination = destination,
                    new IpV4Layer
                        Source = new IpV4Address(srcIP),
                        Destination = new IpV4Address(destIP), 
                        Ttl = 64,
                        Identification = 100,
                        Protocol = IpV4Protocol.Tcp,
                        TypeOfService = 0,
                    new TcpLayer
                        DestinationPort = 80,
                        SourcePort = 45639,
                        SequenceNumber = new Random(),
                        AcknowledgmentNumber = 0,
                        Window = (ushort)166,
                        ControlBits = TcpControlBits.Synchronize,


I've tried SOOOOOOOOOOO many times and sent around thousends of packets and i didnt get a single return of anything , no Acknowledgment or Reset or any other packet type from the destination device

P.S. the Connection between the two devices works perfectly , i send and receive the packets from/to both devices without any loss

Feb 26, 2011 at 8:14 AM

Hi shamilqais,


Did you sniff the packet on the other side?

Do you have an HTTP server turned on in the server side? What application should answer the SYN?

I'm not sure what SequenceNumber = new Random() does. Maybe you should use new Random().Next() instead?


Try to just do use a browser to establish an HTTP connection between the two machines and see what kind of packets are transmitted.

See what's the difference between the packets you send and the packets that are sent using a browser.


Good luck,



Feb 26, 2011 at 2:46 PM

Hi Boaz

The sequence number is initiated in a random method that i built , the one in the example is just to show what im doing

i have no server right now , im just sending the syn packet from one pc to another , but i thought the NIC of the receiver should automatically respond

btw i sniff the traffic on the receiver and the send works 100%

Feb 26, 2011 at 3:17 PM

NICs usually don't respond to SYN packets.

Feb 28, 2011 at 12:30 AM

I think u must have problem with converting string values of IP/MACs to their respective format. Here is a code which works for me (sorry code snippet toolbar icon not working in my browser). Actually i m developing a tool to send any type of packet from TCP, UDP, ARP and ICMP protocols.


private void sendTCPButton_Click(object sender, EventArgs e)
EthernetLayer ethernet;
IpV4Layer ip4;
TcpLayer tcp;

MacAddress srcMac, dstMac;
srcMac = new MacAddress(srcMACBox.Text);
dstMac = new MacAddress(dstMACBox.Text);

//ethernet packet
ethernet = new EthernetLayer();
ethernet.Source = srcMac;
ethernet.Destination = dstMac;
ethernet.EtherType = EthernetType.IpV4;

//ipv4 layer
IpV4Address srcIP = new IpV4Address(srcIPBox.Text);
IpV4Address dstIP = new IpV4Address(dstIPBox.Text);

ip4 = new IpV4Layer();
ip4.Source = srcIP;
ip4.Destination = dstIP;
ip4.Protocol = IpV4Protocol.Tcp;
ip4.Ttl = Convert.ToByte(ttlTextBox.Text);
ip4.Fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.DoNotFragment, 0);

//tcp layer
tcp = new TcpLayer();
tcp.SourcePort = (Convert.ToUInt16(srcPortBox.Text));
tcp.DestinationPort = (Convert.ToUInt16(dstPortBox.Text));
tcp.Window = (Convert.ToUInt16(windowSizeBox.Text)); ;
tcp.SequenceNumber = 13154; //for teting

tcp.ControlBits = TcpControlBits.Synchronize ;

//build and send packet

PacketBuilder pb = new PacketBuilder(ethernet, ip4, tcp);
SendPackets sp = new SendPackets(pb);

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
srcMACBox.Text = PacketCrafter.localMac.ToString();

class SendPackets
private PacketBuilder pktBuilder;

public SendPackets(PacketBuilder builder)
pktBuilder = builder;

public void WriteToWire()
using (PacketCommunicator communicator = PacketCraft.PacketCrafter.deviceSelected.Open(100, // name of the device
PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
1000)) // read timeout
// Build the packet
Packet packet = pktBuilder.Build(DateTime.Now);

// Send down the packet



Mar 1, 2011 at 9:18 PM

thanks qasali but i already said that the code i posted is just an example to show everyone the structure

my actual code is working and everything is initialized correctly , im up to 500 lines of code now and still going.

i used the sharppcap library and got the required result , but i honestly prefer pcapdotnet and i wanna know why its not working :(

Mar 4, 2011 at 11:03 AM

If you have a working code and a non-working code you can run each one and use Wireshark to see what the difference between the packets you send to see where the problem is.

Mar 5, 2011 at 7:03 AM

you didnt understand me , what i meant by the working code is that i developed a full application with hundreds lines of code , but the problem is tht any syn packet that i send does not   get any syn,ack packet in return , when i use wire shark i see that the destination is receiving all the sent packets without any loss , the code i gave is a sample of what im using , i just removed some of the complex equations that im using to create the packet field's contents

if anyone can provide a sample code that worked for a three way hand shake so that i can compare it to my code , i'll be really greatful

Mar 5, 2011 at 7:05 AM

As I said, you probably don't get any SYN-ACKs because there is nothing that will give you SYN-ACKs on the other side.