What is TCP/IP ? Introduction TCP/IP Packet.
Tags: python, security, wireshark
Published: 2023-05-12 19:38:35

**Transmission Control Protocol/Internet Protocol explanation.**

**[GitHub: Salah Ud Din - 4yub1k](https://github.com/4yub1k)**

#### Discussed:

- OSI Model.
- Encapsulation.
- Internet Protocol (IP).
- Transmission Control Protocol (TCP).
- Duty of TCP.
- Connection Establishment.
- 3-Way Handshake.

#### Open Systems Interconnection model (OSI model):
The Open Systems Interconnection model (OSI model) is a conceptual model that characterize and standardize the communication functions of a telecommunication or computing system without regard to its underlying internal structure and technology.
![Internet protocol suite](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/snvr7a3pz4g4v4n053ke.jpg)

![OSI model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zurzbcht8ngybleitmu.jpg)

#### Encapsulation:
When data is transmitted from one host to another, the data is handed downwards from the uppermost layer to the bottom layer of the sending host. At each level, the current layer adds its own header (or trailer) and hands it further downwards. This process is also called encapsulation.

At the bottom layer the data is transmitted to the receiving host in bytes, which then does the same process in reverse. Handing the received transmission from the bottom to the top with each layer removing their header (or trailer).

#### Layer architecture:

![Layer architecture OSI Model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vofq0dr89o0h4ke1kk8j.png)


#### Internet Protocol (IP):
The Internet Protocol (IP) is the principal communication protocol. It delivers packets from one Host(IP) to other Host(IP).

It is connectionless so packet loss/corruption may occur.

Packets of connectionless protocols are also called datagrams. This falls in Internet/Network Layer.

#### Types:
IP Version 4 (IPv4) -> 192.168. 10.150.
IP Version 6 (IPv6) -> 3002:0bd6:0000:0000:0000:ee00:0033:6778.

#### Format of IP Header:

![Format of IP Header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8x9cv9nmuhwohh5ejjrs.jpg)

#### Detailed Format of IP Header:

![Detailed Format of IP Header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipos5kwgb8o1ptqk6rnp.jpg)



#### Transmission Control Protocol (TCP):
This protocol is responsible for many application which work on internet e-g WWW, email, File Transfer Protocol, Secure Shell, peer-to-peer file sharing, and streaming media.
This Transport layer provide connectivity between HOST-HOST. It is reliable, ordered and error-checked protocol. Opposite to User Datagram Protocol (UDP).

#### Duty of TCP:
(Why TCP ?)

- Establishment/termination,
- Reliable transmission,
- Error detection,
- Flow/congestion control, and more of connection.

#### Format of TCP Header:

![Format of TCP Header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uik3s7bvewt7on8555tn.jpg)



#### Detailed Format of TCP Header:

![Detailed Format of TCP Heade](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvqnf56k34eyuc8v0dm5.jpg)



#### Connection Establishment:
TCP uses a three-way handshake in order to establish a connection. Let’s assume that host A (Client) wants to connect to host B (Server):

#### 3-Way Handshake:

![3-Way Handshake](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enylu2gpc5n2s4xyc96w.jpg)


SYN: Client send a [SYN] <bit of flag=1, for SYN> to Server with a random value as sequence number “x”.

SYN-ACK: Server replies on this connection attempt by sending a [SYN ACK] <bit of flag=1, for SYN & ACK>. The sequence number “y” is randomly chosen by Server. The acknowledgement number is the received sequence number increased by one i.e. [PACK]=”x+1".

ACK: Client send an [ACK] to Server. The sequence number [SEQ] is the previously received acknowledgement number [PACK]=” x+1". The new acknowledgement number [PACK] is the received sequence number increased by one i.e.[PACK]=”y+1".

![TCP/IP wireshark](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ondsbj5jwkzufdkgqj5.jpg)



FIN: To terminate the connection. See Flag in TCP.

We’ll discuss TCP/IP crafting in next article. [Coming soon..]