IP (Internet Protocol)
IP stands for Internet Protocol, is a set of rules for routing and addressing packets so that they can travel across the network and arrive at correct places
Once they arrive at the destination, they will be handled by Transport protocol (TCP (Transmission Control Protocol) or UDP (User Diagram Protocol))

IPV4 Structure
packet-beta
title IPv4 Header Structure
0-3: "Version"
4-7: "IHL (Header Length)"
8-15: "Type of Service or DiffServ"
16-31: "Total Length"
32-47: "Identifier"
48-50: "Flags"
51-63: "Fragment Offset"
64-71: "Time to Live (TTL)"
72-79: "Protocol"
80-95: "Header Checksum"
96-127: "Source IP Address"
128-159: "Destination IP Address"
160-183: "Options (if IHL > 5)"
184-191: "Padding"
Version (4 bit)
Use 4 if IPv4, 6 if IPv6. The full list of table is here:
| Decimal | Version / Protocol Name | Description / Status |
|---|---|---|
| 0 | Reserved | Historically reserved or used in early experimental prototypes. |
| 1–3 | Unassigned | Reserved for future allocation. |
| 4 | IPv4 | Internet Protocol version 4. Current primary global standard. |
| 5 | ST / ST2 | Internet Stream Protocol. Used for experimental multimedia streaming; now Historic. |
| 6 | IPv6 | Internet Protocol version 6. Current standard for massive address space. |
| 7 | TP/IX | The Next Internet. Proposed in 1993; now Historic. |
| 8 | PIP | P Internet Protocol. Proposed in 1994; now Historic. |
| 9 | TUBA | TCP and UDP over Bigger Addresses. Proposed in 1992; now Historic. |
| 10–14 | Unassigned | Currently reserved; includes various non-standard drafts like "IPv10". |
| 15 | Reserved | Reserved for experimental or future use. |
Header length (4 bit)
Specify how much data is this single header. Because there is an Options field, the size of the header could be varied from 20 bytes to 60 bytes.
The value provided in this number is 32-bit-word (i.e $\times 4{bytes}$) so if we specify 5 it will be 5x4=20 which is the standard for this IPv4 header.
ToS or DiffServ
For this fields there are 2 types of data. One is DSCP (DiffServ Code Points) and ECN (Explicit Congestion Notification). Another one is Type of Service
If we set ECN, we have last 2 bit for ECN and first 5 bits for DSCP
packet-beta
title DSCP & ECN contains 8 bits
0-5: "DSCP"
6-7: "ECN"
For ECN, if we set 11 that means congestion
Total Length (2 byte - 16 bits)
Total length of the packet including the headers and data payload in octet (bytes).
[!danger]
This does not includeEthernetIIheader
Identifier (16 bits)
Packet will be break into smaller fagment if it exceeds MTU (Maximum Transmission unit). Maximum size of the packet is the MTU. For those that're break into fragment, they need to have the same identifier number.
Flags (4 bits)
3 bit:
- First bit: unused
- Second bit: Don't fragment (DF) if we set this bit, the router cannot fragment the packet. If it exceeds MTU (Maximum Transmission unit) and cannot be forwarded, it will send an error message to the source.
Flagment Offset (8 bits)
The id of the fragment since the fragment might not be in sequence. This is to use to sort the fragment after
TTL (8 bits)
As packet passed from router to router, each router decrement this number, if the number reaches 0, the packet will be discard.
This is to prevent lost packet to wander around.
The recommended TTL value is 64.
Protocol (8 bits)
Set the type of protocol
| Decimal | Keyword | Protocol Name / Description |
|---|---|---|
| 0 | HOPOPT | IPv6 Hop-by-Hop Option |
| 1 | ICMP | Internet Control Message Protocol |
| 2 | IGMP | Internet Group Management Protocol |
| 4 | IPv4 | IPv4 encapsulation (IP-in-IP) |
| 6 | TCP | Transmission Control Protocol |
| 17 | UDP | User Datagram Protocol |
| 41 | IPv6 | IPv6 encapsulation (6to4, etc.) |
| 47 | GRE | Generic Routing Encapsulation |
| 50 | ESP | Encapsulating Security Payload (IPsec) |
| 51 | AH | Authentication Header (IPsec) |
| 58 | IPv6-ICMP | ICMP for IPv6 |
| 88 | EIGRP | Enhanced Interior Gateway Routing Protocol |
| 89 | OSPF | Open Shortest Path First |
| 103 | PIM | Protocol Independent Multicast |
| 112 | VRRP | Virtual Router Redundancy Protocol |
| 115 | L2TP | Layer Two Tunneling Protocol |
| 132 | SCTP | Stream Control Transmission Protocol |
| 253–254 | — | Use for experimentation and testing |
| 255 | — | Reserved |
Header check sum (16 bits)
Check sum calculate by the origin of the packet. Different protocols have different ways of calculating checksum.
Sender will calculate the checksum and put there, the receiver will calculate the check sum again (including the sender checksum in the header). The end checksum needs to compliment each other (sum up to 0)
Source and destination IP (32 bit)
32 bit IPv4 address of the originator of the packet
Option (varied length)
Optional fiels normally used for testing. For example:
- Timestamp: packet keep track of the timestamp where it was
- Loose source routing: list of IP addresses packet needs to pass through
- Strict source routing: list of IP addresses where packet must pass through exactly in the same order