TCPHeader


C Specification

#include <dolphin/ip.h>

// TCP header length macros
#define TCP_HLEN(tcp)       ((tcp->flag & 0xf000) >> 10)
#define TCP_MIN_HLEN        20
#define TCP_MAX_HLEN        60

// TCPHeader.flag bits
#define TCP_FLAG_URG        0x20    // Urgent pointer field significant
#define TCP_FLAG_ACK        0x10    // Acknowledgment field significant
#define TCP_FLAG_PSH        0x08    // Push function
#define TCP_FLAG_RST        0x04    // Reset the connection
#define TCP_FLAG_SYN        0x02    // Synchronize sequence numbers
#define TCP_FLAG_FIN        0x01    // No more data from sender

typedef struct TCPHeader
{
    u16 src;    // source port
    u16 dst;    // destination port

    s32 seq;    // sequence number
    s32 ack;    // acknowledgment number

    u16 flag;   // 4:data offset, 6:reserved, 1:URG, 1:ACK, 1:PSH, 1:RST, 1:SYN, 1:FIN
    u16 win;    // window
    u16 sum;    // checksum
    u16 urg;    // urgent pointer
} TCPHeader;

Description

The TCP byte stream is transferred in segments. In a TCP segment, the TCP header follows the IP header, supplying information specific to the TCP protocol.

A TCP segment is encapsulated in an IP datagram as shown below:

IP header

TCP header

TCP data

See Also

Postel, J. B., ed. 1981 "Transmission Control Protocol", RFC 793 (Sept.).