NetSim Source Code Help
Loading...
Searching...
No Matches
TCP_Header.h
Go to the documentation of this file.
1#pragma once
2/************************************************************************************
3* Copyright (C) 2020 *
4* TETCOS, Bangalore. India *
5* *
6* Tetcos owns the intellectual property rights in the Product and its content. *
7* The copying, redistribution, reselling or publication of any or all of the *
8* Product or its content without express prior written consent of Tetcos is *
9* prohibited. Ownership and / or any other right relating to the software and all *
10* intellectual property rights therein shall remain at all times with Tetcos. *
11* *
12* Author: Shashi Kant Suman *
13* *
14* ---------------------------------------------------------------------------------*/
15
16#ifndef _NETSIM_TCP_HEADER_H_
17#define _NETSIM_TCP_HEADER_H_
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22 //If TCP.h file is not included in .c file.
23#ifndef _NETSIM_TCP_H_
24#define PNETSIM_SOCKET void*
25#endif
26
27 typedef enum enum_tcp_packet
28 {
35
36 typedef enum enum_tcp_option
37 {
44 TCP_OPTION_ECHO, //obsoleted by option 8
45 TCP_OPTION_ECHOREPLY, //obsoleted by option 8
48
49 typedef struct stru_tcp_option
50 {
52 void* option;
56
57/*
58 TCP Header Format
59
60
61 0 1 2 3
62 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
63 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 | Source Port | Destination Port |
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 | Sequence Number |
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 | Acknowledgment Number |
69 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 | Data | |U|A|P|R|S|F| |
71 | Offset| Reserved |R|C|S|S|Y|I| Window |
72 | | |G|K|H|T|N|N| |
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 | Checksum | Urgent Pointer |
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 | Options | Padding |
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 | data |
79 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80
81 TCP Header Format
82 */
83 //Looks little different than RFC as below is used in Linux or windows.
84 typedef struct stru_tcp_header
85 {
103#define TCP_HDR_SIZE 20 //Bytes
104#define MAX_TCP_OPT_LEN 40 //Bytes
105#define MAX_TCP_HDR_SIZE (TCP_HDR_SIZE+MAX_TCP_OPT_LEN)
106
108 {
109 if (packet &&
110 packet->pstruTransportData &&
113 return NULL;
114 }
115
116 typedef struct stru_mss_option
117 {
122#define MSS_OPTION_LEN 4 //Bytes
123
125 {
129#define SACKPERMITTED_OPTION_LEN 2 //Bytes
130
131 typedef struct stru_sack_data
132 {
136#define SACKDATA_LEN 8 //Bytes
137
138 typedef struct stru_sack_option
139 {
144#define SACK_OPTION_FIX_LEN 2 //Bytes
145#define SACK_OPTION_LEN(n) ((UINT8)(SACK_OPTION_FIX_LEN+(n)*SACKDATA_LEN)) //Bytes
146#define get_sack_data_count(sack) ((sack->len-SACK_OPTION_FIX_LEN)/SACKDATA_LEN)
147
149 {
152#define EXTRA_OPTION_LEN 1 //Bytes
153
155 {
160#define WSOPT_LEN 3 //Bytes
161
163 {
169#define TSOPT_LEN 10 //Bytes
170
171 //Function prototype
175 void set_tcp_option(PTCP_SEGMENT_HDR hdr, void* option, TCP_OPTION type, UINT32 size);
176
177 //SACK
178 void set_sack_option(PNETSIM_SOCKET s, PTCP_SEGMENT_HDR hdr, double time);
180
181 //Window Scaling
183
184 //TimeStamp option
187 PTSopt opt);
188
189#ifdef __cplusplus
190}
191#endif
192#endif //_NETSIM_TCP_HEADER_H_
#define UINT32
Definition: Linux.h:35
#define UINT16
Definition: Linux.h:33
#define UINT8
Definition: Linux.h:31
@ TX_PROTOCOL_TCP
Definition: Stack.h:180
struct stru_sack_option SACK_OPTION
enum enum_tcp_packet TCPPACKET
struct stru_tcp_extra_option * PEXTRA_OPTION
enum_tcp_packet
Definition: TCP_Header.h:28
@ TCPPACKET_SYNACK
Definition: TCP_Header.h:30
@ TCPPACKET_ACK
Definition: TCP_Header.h:33
@ TCPPACKET_SYN
Definition: TCP_Header.h:29
@ TCPPACKET_FIN
Definition: TCP_Header.h:31
@ TCPPACKET_RST
Definition: TCP_Header.h:32
struct stru_sack_data * PSACKDATA
struct stru_mss_option * PMSS_OPTION
void free_tcp_hdr(PTCP_SEGMENT_HDR hdr)
Definition: TCP_Packet.c:576
struct stru_tcp_window_scale_option Wsopt
struct stru_tcp_timestamp_option * PTSopt
struct stru_sack_permitted_option * PSACKPERMITTED_OPTION
void set_window_scaling(PNETSIM_SOCKET s, PWsopt opt)
Definition: WindowScale.c:18
PTCP_SEGMENT_HDR copy_tcp_hdr(PTCP_SEGMENT_HDR hdr)
Definition: TCP_Packet.c:493
void set_tcp_option(PTCP_SEGMENT_HDR hdr, void *option, TCP_OPTION type, UINT32 size)
Definition: TCP_Packet.c:45
struct stru_sack_permitted_option SACKPERMITTED_OPTION
struct stru_tcp_option * PTCPOPTION
struct stru_sack_option * PSACK_OPTION
void set_timestamp_value(PNETSIM_SOCKET s, PTCP_SEGMENT_HDR hdr, PTSopt opt)
Definition: TCB.c:427
void set_sack_option(PNETSIM_SOCKET s, PTCP_SEGMENT_HDR hdr, double time)
Definition: SACK.c:68
struct stru_sack_data SACKDATA
struct stru_tcp_extra_option EXTRA_OPTION
struct stru_tcp_option TCPOPTION
struct stru_tcp_window_scale_option * PWsopt
void receive_sack_option(PNETSIM_SOCKET s, PTCP_SEGMENT_HDR hdr)
Definition: SACK.c:280
struct stru_tcp_header TCP_SEGMENT_HDR
enum enum_tcp_option TCP_OPTION
struct stru_mss_option MSS_OPTION
struct stru_tcp_header * PTCP_SEGMENT_HDR
struct stru_tcp_timestamp_option TSopt
enum_tcp_option
Definition: TCP_Header.h:37
@ TCP_OPTION_WINDOW_SCALE
Definition: TCP_Header.h:41
@ TCP_OPTION_ECHO
Definition: TCP_Header.h:44
@ TCP_OPTION_TIMESTAMP
Definition: TCP_Header.h:46
@ TCP_OPTION_SACK
Definition: TCP_Header.h:43
@ TCP_OPTION_MSS
Definition: TCP_Header.h:40
@ TCP_OPTION_SACK_PERMITTED
Definition: TCP_Header.h:42
@ TCP_OPTION_ECHOREPLY
Definition: TCP_Header.h:45
@ TCP_OPTION_NOOPERATION
Definition: TCP_Header.h:39
@ TCP_OPTION_END
Definition: TCP_Header.h:38
void * get_tcp_option(PTCP_SEGMENT_HDR hdr, TCP_OPTION type)
Definition: TCP_Packet.c:65
static PTCP_SEGMENT_HDR TCP_GET_SEGMENT_HDR(NetSim_PACKET *packet)
Definition: TCP_Header.h:107
TRANSPORT_LAYER_PROTOCOL nTransportProtocol
Definition: Packet.h:186
struct stru_NetSim_Packet_TransportLayer * pstruTransportData
Definition: Packet.h:274
UINT32 leftEdge
Definition: TCP_Header.h:133
UINT32 rightEdge
Definition: TCP_Header.h:134
PSACKDATA * sackData
Definition: TCP_Header.h:142
PTCPOPTION option
Definition: TCP_Header.h:101
UINT32 Reserved
Definition: TCP_Header.h:97
UINT32 HdrLength
Definition: TCP_Header.h:90
UINT16 DstPort
Definition: TCP_Header.h:87
UINT16 Checksum
Definition: TCP_Header.h:99
UINT16 SrcPort
Definition: TCP_Header.h:86
TCP_OPTION type
Definition: TCP_Header.h:51
struct stru_tcp_option * next
Definition: TCP_Header.h:54