ifpps: remove voff increment from functions
[netsniff.git] / src / mops_tcp.c
blob4d788bd58660f7f5dc22daab4e64af33a89cc793
1 /*
2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 * details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
20 #include "mz.h"
21 #include "mops.h"
22 #include "cli.h"
24 // Calculates the number of TCP transmissions based on SQNR range
25 u_int32_t mops_tcp_complexity_sqnr (struct mops * mp)
27 u_int32_t a,b,t,result;
29 a = mp->tcp_seq_start;
30 b = mp->tcp_seq_stop;
31 t = mp->tcp_seq_delta;
33 if (!t) return 1; // delta set to zero means no range
35 if (a<b) // regular case
36 result = ceill ((b-a)/t);
37 else // range wraps around
38 result = ceill (((0xffffffff-a) + b)/t);
40 return result;
44 // Calculates the number of TCP transmissions based on SQNR range
45 u_int32_t mops_tcp_complexity_acknr (struct mops * mp)
47 u_int32_t a,b,t,result;
49 a = mp->tcp_ack_start;
50 b = mp->tcp_ack_stop;
51 t = mp->tcp_ack_delta;
53 if (!t) return 1; // delta set to zero means no range
55 if (a<b) // regular case
56 result = ceill ((b-a)/t);
57 else // range wraps around
58 result = ceill (((0xffffffff-a) + b)/t);
60 return result;
66 // *****TODO: TCP Options ******
68 // Remove all options
69 int mops_tcp_option_remove_all (struct mops* mp)
72 return 0;
76 // Prints current flag settings in the provided string 'str'.
77 // NOTE that str must be at least 32 bytes!
78 // *** BETTER USE 64 bytes (for future compatibility) ***
79 //
80 int mops_tcp_flags2str (struct mops* mp, char *str)
82 if (mp==NULL) {
83 sprintf(str, "(no valid mops)\n");
84 return 1;
87 sprintf(str, "%s-%s-%s-%s-%s-%s-%s-%s",
88 (mp->tcp_ctrl_CWR) ? "CRW" : "---",
89 (mp->tcp_ctrl_ECE) ? "ECE" : "---",
90 (mp->tcp_ctrl_URG) ? "URG" : "---",
91 (mp->tcp_ctrl_ACK) ? "ACK" : "---",
92 (mp->tcp_ctrl_PSH) ? "PSH" : "---",
93 (mp->tcp_ctrl_RST) ? "RST" : "---",
94 (mp->tcp_ctrl_SYN) ? "SYN" : "---",
95 (mp->tcp_ctrl_FIN) ? "FIN" : "---");
97 return 0;
100 // Add TCP options
102 // TODO: currently all params are ignored and a default option combination is added.
104 int mops_tcp_add_option (struct mops* mp,
105 int mss,
106 int sack,
107 int scale,
108 u_int32_t tsval,
109 u_int32_t tsecr)
112 u_int8_t tcp_default_options[] = {
113 0x02, 0x04, 0x05, 0xac, // MSS
114 0x04, 0x02, // SACK permitted
115 0x08, 0x0a, 0x19, 0x35, 0x90, 0xc3, 0x00, 0x00, 0x00, 0x00, // Timestamps
116 0x01, // NOP
117 0x03, 0x03, 0x05 // Window Scale 5
121 /* Kind: 8
122 Length: 10 bytes
124 +-------+-------+---------------------+---------------------+
125 |Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)|
126 +-------+-------+---------------------+---------------------+
127 1 1 4 4
129 * The Timestamps option carries two four-byte timestamp fields. The
130 * Timestamp Value field (TSval) contains the current value of the
131 * timestamp clock of the TCP sending the option.
133 * The Timestamp Echo Reply field (TSecr) is only valid if the ACK bit
134 * is set in the TCP header; if it is valid, it echos a times- tamp
135 * value that was sent by the remote TCP in the TSval field of a
136 * Timestamps option. When TSecr is not valid, its value must be zero.
137 * The TSecr value will generally be from the most recent Timestamp
138 * option that was received; however, there are exceptions that are
139 * explained below.
141 * A TCP may send the Timestamps option (TSopt) in an initial <SYN>
142 * segment (i.e., segment containing a SYN bit and no ACK bit), and
143 * may send a TSopt in other segments only if it re- ceived a TSopt in
144 * the initial <SYN> segment for the connection.
148 memcpy((void*) mp->tcp_option, (void*) tcp_default_options, 20);
149 mp->tcp_option_s = 20;
150 mp->tcp_option_used = 1;
152 return 0;