Header Formats in Networking - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Header Formats in Networking

Share This

Physical Layer Header


The Physical Layer (Layer 1) of the OSI model does not use headers in the same sense as higher layers. Instead, it deals with the transmission and reception of raw bitstreams over a physical medium. The Physical Layer encompasses various elements such as electrical signals, light pulses, or radio waves, depending on the transmission medium.

However, it can be helpful to understand some of the basic concepts and components involved in the Physical Layer: 
  • Bit Transmission: The Physical Layer is responsible for the bit-by-bit transmission of data. These bits are encoded into signals that can be transmitted over the medium. 
  • Modulation and Demodulation: This involves converting digital data into analog signals for transmission (modulation) and then converting the received analog signals back into digital data (demodulation).
  • Signal Encoding: This refers to the method used to represent the digital data as signals. Common encoding schemes include: Non-Return to Zero (NRZ), Manchester Encoding, Differential Manchester Encoding.
  • Synchronization: Ensuring that the transmitter and receiver are aligned in time to correctly interpret the signals. 
  • Transmission Media: The Physical Layer includes specifications for the physical media used to transmit data, such as: Copper Cables (e.g., twisted pair, coaxial cables), Fiber Optic Cables, Wireless (e.g., radio waves, infrared).


Example: Ethernet Physical Layer

In Ethernet, the Physical Layer is defined by standards like IEEE 802.3. While Ethernet does not have a traditional "header" at the Physical Layer, it uses specific signaling and frame structures. Here’s a brief overview of the key components: 
  • Preamble: A sequence of bits (7 bytes) used for synchronization. `10101010` repeated for 7 bytes, used to allow the receiver to synchronize its clock with the transmitter.
  • Start Frame Delimiter (SFD): A 1-byte field that indicates the start of a frame. `10101011`, marks the start of the Ethernet frame.


Ethernet Frame Structure

| Preamble (7 bytes)  |  SFD (1 byte)  |  Ethernet Frame (Data Link Layer)  |
  

Signal Encoding Example: Manchester Encoding 

In Manchester Encoding, each bit of data is represented by a transition: 
  • A `0` bit is represented by a high-to-low transition. 
  • A `1` bit is represented by a low-to-high transition. 
This encoding ensures that there are plenty of transitions to help synchronize the clock between sender and receiver. 
 
While the Physical Layer does not use traditional headers, it relies on various protocols and standards to manage the physical transmission of data. These include preambles, signaling schemes, and synchronization techniques to ensure reliable communication over different types of physical media.


Data Link Layer Header


The Data Link Layer (Layer 2) of the OSI model is responsible for node-to-node data transfer and error detection and correction. This layer encapsulates the data from higher layers into frames and manages the physical addressing.

Here's an overview of the header formats for some common Data Link Layer protocols:

Ethernet is one of the most widely used protocols at the Data Link Layer. An Ethernet frame consists of several fields, each with a specific purpose. Here’s a breakdown of the Ethernet frame structure:

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Preamble (7 bytes)                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   SFD (1 byte)  |          Destination MAC Address (6 bytes)  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Destination MAC Address (continued)                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Source MAC Address (6 bytes)                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Source MAC Address (continued)                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ethertype/Length (2 bytes)  |          Payload (46-1500 bytes)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           Payload                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Frame Check Sequence (4 bytes)                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  • Preamble: 7 bytes (56 bits) - A sequence of alternating 1s and 0s used for synchronization. - Example: `10101010 10101010 10101010 10101010 10101010 10101010 10101010` 
  • Start Frame Delimiter (SFD): 1 byte (8 bits) - Indicates the start of the frame. - Example: `10101011` 
  • Destination MAC Address: 6 bytes (48 bits) - The physical address of the destination device. - Example: `FF:FF:FF:FF:FF:FF` (broadcast address) 
  • Source MAC Address: 6 bytes (48 bits) - The physical address of the source device. - Example: `00:1A:2B:3C:4D:5E` 
  • Ethertype/Length: 2 bytes (16 bits) - Indicates either the Ethertype (protocol type) or the length of the payload. - Example: `0800` (indicates IPv4) 
  • Payload: 46-1500 bytes - The actual data being transported. - Minimum size is 46 bytes (if smaller, padding is added). 
  • Frame Check Sequence (FCS): 4 bytes (32 bits) - Error-checking code (CRC-32) to detect corruption in the frame. - Example: `0x12345678` (CRC value)


802.11 (Wi-Fi) Frame Header


Wi-Fi frames are more complex due to additional requirements for wireless communication. Here’s a simplified breakdown:

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Frame Control (2 bytes)  |    Duration/ID (2 bytes)          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 1 (6 bytes)                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 1 (continued)                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 2 (6 bytes)                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 2 (continued)                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 3 (6 bytes)                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 3 (continued)                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Sequence Control (2 bytes)  |       Address 4 (6 bytes)      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Address 4 (continued)                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           Payload                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           Payload                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Frame Check Sequence (4 bytes)                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
  • Frame Control: 2 bytes - Contains subfields for protocol version, type, subtype, to DS, from DS, more fragments, retry, power management, more data, WEP, and order.
  • Duration/ID: 2 bytes - Used for NAV (Network Allocation Vector) and identifying frames.
  • Address 1: 6 bytes - Usually the receiver’s MAC address. 
  • Address 2: 6 bytes - Usually the transmitter’s MAC address. 
  • Address 3: 6 bytes - Typically the MAC address of the final destination or the BSSID.
  • Sequence Control: 2 bytes - Contains the sequence number and fragment number of the frame.
  • Address 4: 6 bytes (optional) - Used in ad-hoc mode or in frames where the DS bit is set.
  • Payload: Variable length - The actual data being transported. 
  • Frame Check Sequence (FCS): 4 bytes - Error-checking code to detect corruption in the frame.

These header formats help ensure data integrity, manage addressing, and facilitate error detection and correction, ensuring reliable data communication across a network.


Network Layer (IPv4) Header


The Network Layer (Layer 3) of the OSI model is responsible for routing packets across a network. It uses various protocols, with the most common being the Internet Protocol (IP). The headers in this layer include information necessary for routing, such as source and destination IP addresses, and other details to manage the delivery of packets.

Here are the header formats for IPv4 and IPv6, the two main versions of IP:


IPv4 Header

The IPv4 header is 20 to 60 bytes long, depending on the options field. Here is the format:

 0                   1                   2                   3  
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1  
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|      Fragment Offset    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |         Header Checksum       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source IP Address                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination IP Address                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options (if any)                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Padding (if any)                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
  • Version (4 bits): Specifies the IP version. For IPv4, this value is 4.
  • IHL (Internet Header Length) (4 bits): Specifies the header length in 32-bit words. The minimum value is 5 (20 bytes).
  • Type of Service (1 byte): Indicates the quality of service desired.
  • Total Length (2 bytes): The entire packet size, including header and data, in bytes.
  • Identification (2 bytes): Used for uniquely identifying fragments of an original IP packet.
  • Flags (3 bits): Used for fragmentation control. - Bit 0: Reserved, must be zero. - Bit 1: Don't Fragment (DF). - Bit 2: More Fragments (MF). 
  • Fragment Offset (13 bits): Indicates where in the datagram this fragment belongs.
  • Time to Live (TTL) (1 byte): Limits the packet's lifetime to prevent looping. 
  • Protocol (1 byte): Indicates the protocol used in the data portion (e.g., TCP, UDP).
  • Header Checksum (2 bytes): A checksum of the header only.
  • Source IP Address (4 bytes): The IP address of the sender. 
  • Destination IP Address (4 bytes): The IP address of the recipient.
  • Options (variable length): Optional settings, up to 40 bytes.
  • Padding (variable length): Used to ensure the header is a multiple of 32 bits.


IPv6 Header

The IPv6 header is simplified compared to IPv4 and is fixed at 40 bytes.

 0                   1                   2                   3  
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1  
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 6 |       Traffic Class       |           Flow Label          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      Payload Length           |  Next Header  |   Hop Limit   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                       Source IP Address                       |
|                                                               |
|                                                               |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                    Destination IP Address                     |
|                                                               |
|                                                               |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
  • Version (4 bits): Specifies the IP version. For IPv6, this value is 6.
  • Traffic Class (1 byte): Indicates the traffic class or priority of the packet.
  • Flow Label (20 bits): Used for special handling of the packet.
  • Payload Length (2 bytes): The length of the payload, not including the header, in bytes.
  • Next Header (1 byte): Indicates the type of the next header (e.g., TCP, UDP, ICMPv6).
  • Hop Limit (1 byte): Similar to TTL in IPv4, limits the packet's lifetime.
  • Source IP Address (16 bytes): The IP address of the sender.
  • Destination IP Address (16 bytes): The IP address of the recipient.

These headers provide essential information required for the proper routing and delivery of packets through a network. IPv6 simplifies the header structure and increases the address size to accommodate the growing need for IP addresses.


Transport Layer Header


TCP Header


                                    
    0                   1                   2                   3   
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |          Source Port          |       Destination Port        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                        Sequence Number                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Acknowledgment Number                      |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Data |           |U|A|P|R|S|F|                               |
   | Offset| Reserved  |R|C|S|S|Y|I|            Window             |
   |       |           |G|K|H|T|N|N|                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |           Checksum            |         Urgent Pointer        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Options                    |    Padding    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                             data                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

UDP Header


The User Datagram Protocol (UDP) is a transport layer protocol that enables low-latency, connectionless communication. UDP headers are relatively simple and consist of four fields, each 2 bytes (16 bits) long, making the entire UDP header 8 bytes (64 bits).



 0                   1                   2                   3  
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1  
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            Length             |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
Field Descriptions: 
  1. Source Port (2 bytes): - Identifies the sender's port number. - If the source host is not expecting a reply, this field may be zero. 
  2. Destination Port (2 bytes): - Identifies the receiver's port number. - Specifies the port to which the packet should be sent on the destination host. 
  3. Length (2 bytes): - Specifies the length of the UDP header and the encapsulated data in bytes. - The minimum length is 8 bytes (the size of the UDP header itself). 
  4. Checksum (2 bytes): - Used for error-checking of the header and data. - Optional in IPv4 (can be set to zero), but mandatory in IPv6.
 
Detailed UDP Header Example

 0                   1                   2                   3  
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1  
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Source Port (12345)        |  Destination Port (80)        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       Length (16)             |       Checksum (0x1c2d)       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
 Example Field Values: 
  • Source Port: 12345 (0x3039 in hexadecimal) 
  • Destination Port: 80 (0x0050 in hexadecimal) 
  • Length: 16 (0x0010 in hexadecimal, including 8 bytes of UDP header + 8 bytes of data) 
  • Checksum: 0x1c2d (checksum value for the header and data)

An entire UDP packet consists of the UDP header followed by the data (payload). For example:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            Length             |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Data (Payload)                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Data (continued)                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
In summary, the UDP header provides the essential information for identifying the source and destination ports, the length of the packet, and a checksum for error-checking. Its simplicity and minimal overhead make UDP suitable for applications where speed is critical and error correction can be handled by the application layer, such as in streaming media, online gaming, and DNS queries.


Session Layer Header


The Session Layer (Layer 5) of the OSI model is responsible for managing and controlling the connections between computers. This includes setting up, coordinating, and terminating conversations, exchanges, and dialogues between applications. However, unlike the Transport Layer (Layer 4) and Network Layer (Layer 3), the Session Layer does not have a universally defined header format because its implementation can vary widely depending on the protocol in use.

Most modern network protocols combine the functionality of the Session Layer with other layers, particularly the Application Layer (Layer 7). For example, protocols such as HTTP, FTP, and SMB integrate session management within their higher-layer protocols rather than as a distinct Session Layer header.

Example Protocols and Session Management

NetBIOS Session Service (NetBIOS over TCP/IP): NetBIOS is one example of a protocol that operates at the Session Layer. It provides session services like establishing, maintaining, and terminating connections. 
  • Session Request (0x81): Used to request a session. 
  • Positive Session Response (0x82): Indicates a session is established. 
  • Negative Session Response (0x83): Indicates a session is refused. 
  • Session Keep Alive (0x85): Keeps the session active.
  • Session End (0x86): Ends the session.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  TYPE (1 byte) |   FLAGS (1 byte) |   LENGTH (2 bytes)        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          DATA                                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
Field Descriptions:  
  • TYPE: Indicates the type of session message (e.g., 0x81 for session request).
  • FLAGS: Additional flags related to the session message.
  • LENGTH: The length of the message excluding the header. 
  • DATA: The actual data or payload of the message.

RPC (Remote Procedure Call): RPC mechanisms can also be seen as operating within the Session Layer, managing the setup, maintenance, and teardown of communication sessions for remote procedure calls.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  VERSION (1 byte) |  FLAGS (1 byte) |   FRAGMENT LENGTH (2 bytes)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    AUTH LENGTH (2 bytes)   |    CALL ID (4 bytes)              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          DATA                                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  
Field Descriptions: 
  • VERSION: The RPC version.
  • FLAGS: Flags indicating options for the RPC message.
  • FRAGMENT LENGTH: The length of this fragment of the message.
  • AUTH LENGTH: The length of any authentication information.
  • CALL ID: Identifier for the call.
  • DATA: The payload of the RPC message.

Higher-Layer Protocols with Session Management

Many modern protocols integrate session management within their higher-layer protocol definitions. Examples include:
  • HTTP/2 and HTTP/3: Include session management within the protocol, such as the use of streams and the multiplexing of connections. 
  • TLS (Transport Layer Security): Manages sessions through the use of session keys and the establishment of secure channels.

While these protocols operate primarily at the Application Layer, they include significant session management functionality that can be considered part of the Session Layer in the OSI model.


Presentation Layer Header


The Presentation Layer (Layer 6) of the OSI model is responsible for translating data between the application layer and the network format. This includes data encryption, decryption, compression, decompression, and formatting. Like the Session Layer, the Presentation Layer does not have a standardized, universal header format. Instead, the functionality of the Presentation Layer is often embedded within higher-level protocols.

SSL/TLS (Secure Sockets Layer/Transport Layer Security)

SSL/TLS operates at the Presentation Layer for securing data communications. It provides encryption, message integrity, and authentication.

SSL/TLS Record Format:

0                   1                   2                   3  
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1  
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Content Type (1 byte)|Version (2 bytes)| Length (2 bytes)       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           Payload                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  • Content Type: Indicates the type of data (e.g., handshake, application data).
  • Version: Specifies the SSL/TLS version.
  • Length: Length of the payload. 
  • Payload: The encrypted data, handshake messages, etc.

MIME (Multipurpose Internet Mail Extensions)

MIME is used for formatting messages in email systems to support text in character sets other than ASCII, as well as attachments like audio, video, images, and application programs.

MIME Header Example:

Content-Type: multipart/mixed; boundary="----=_Part_0_123456789.123456789"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="example.txt"
  • Content-Type: Specifies the media type of the message.
  • Content-Transfer-Encoding: Indicates the encoding method used.
  • Content-Disposition: Provides presentation information, such as the filename for an attachment.

XDR (External Data Representation)

XDR is a standard for data serialization used to ensure that data structures can be exchanged between different platforms.

XDR Data Format:

XDR doesn't have a fixed header but specifies how data types (integers, floats, strings, etc.) should be encoded into a standard binary format.

Example XDR Encoding:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Integer Data                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Floating Point Data                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          String Data                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ASN.1 (Abstract Syntax Notation One)
 
ASN.1 is a standard interface description language for defining data structures that can be serialized and deserialized in a cross-platform way.

ASN.1 Encoding (DER/BER):

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Tag (1 byte)   | Length (1 byte) |      Value (variable)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  • Tag: Indicates the data type.
  • Length: Specifies the length of the data.
  • Value: The actual data.

Example ASN.1 Encoding:

Tag: 0x02 (INTEGER)
Length: 0x01 (1 byte)
Value: 0x05 (5)
The Presentation Layer of the OSI model does not have a single standardized header format. Instead, various protocols and standards provide specific mechanisms for data translation, encryption, and compression. The examples of SSL/TLS, MIME, XDR, and ASN.1 demonstrate how the Presentation Layer's responsibilities are implemented in different contexts, each with its own format and structure for handling data.


Application Layer Header


The Application Layer (Layer 7) of the OSI model is responsible for providing network services directly to the user's applications. This layer interacts directly with software applications to implement communication functions. Unlike lower layers, the Application Layer headers can vary greatly depending on the specific protocol in use. Here, we will explore the header formats of several commonly used Application Layer protocols, including HTTP, SMTP, and FTP.

HTTP (HyperText Transfer Protocol)

HTTP is the foundation of data communication on the World Wide Web. It is a request-response protocol between clients and servers.

HTTP Request Header

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Upgrade-Insecure-Requests: 1
  
HTTP Response Header

HTTP/1.1 200 OK
Date: Mon, 23 Jun 2024 12:00:00 GMT
Server: Apache/2.4.41 (Ubuntu)
Last-Modified: Wed, 22 Jun 2024 16:00:00 GMT
Content-Length: 3056
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
  

SMTP (Simple Mail Transfer Protocol)

From: sender@example.com
To: recipient@example.com
Date: Mon, 23 Jun 2024 12:00:00 GMT
Subject: Test Email
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit


FTP (File Transfer Protocol)

FTP is used for transferring files between a client and a server on a network.

FTP Response (Sent from server to client)

220 Service ready for new user.
331 User name okay, need password.
230 User logged in, proceed.
550 Requested action not taken. File unavailable.

DNS (Domain Name System)


DNS Message Header

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification | Parameters | Question Count | Answer Count   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Authority Count     |    Additional Count     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Descriptions: 
  • Identification: 16 bits, used for matching requests and responses. 
  • Parameters: 16 bits, various flags like query/response, opcode, etc.
  • Question Count: 16 bits, number of questions. 
  • Answer Count: 16 bits, number of answers.
  • Authority Count: 16 bits, number of authority records.
  • Additional Count: 16 bits, number of additional records.

The Application Layer of the OSI model encompasses a wide variety of protocols, each with its own specific header format. The examples provided for HTTP, SMTP, FTP, and DNS illustrate the diversity of header structures and information contained within the Application Layer. These headers provide crucial information for the proper delivery and processing of data between applications and across networks.



Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.