hping3: add new package
[feed/packages.git] / net / hping3 / patches / 160_tcp_mss.patch
1 Subject: Add tcp-mss support.
2 Origin: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/net/hping/patches/
3 Bug-Debian: http://bugs.debian.org/409391
4 Last-Update: 2009-09-19
5
6 --- a/main.c
7 +++ b/main.c
8 @@ -44,7 +44,8 @@ unsigned int
9 signlen,
10 lsr_length = 0,
11 ssr_length = 0,
12 - tcp_ack;
13 + tcp_ack,
14 + tcp_mss;
15
16
17 unsigned short int
18 @@ -95,6 +96,7 @@ int
19 opt_tcpexitcode = FALSE,
20 opt_badcksum = FALSE,
21 opt_tr_keep_ttl = FALSE,
22 + opt_tcp_mss = FALSE,
23 opt_tcp_timestamp = FALSE,
24 opt_clock_skew = FALSE,
25 cs_window = DEFAULT_CS_WINDOW,
26 --- a/globals.h
27 +++ b/globals.h
28 @@ -32,7 +32,8 @@ extern unsigned int
29 tcp_seqnum,
30 set_ack,
31 ip_header_length,
32 - tcp_ack;
33 + tcp_ack,
34 + tcp_mss;
35
36 extern unsigned short int
37 data_size;
38 @@ -77,6 +78,7 @@ extern int opt_debug,
39 opt_tcpexitcode,
40 opt_badcksum,
41 opt_tr_keep_ttl,
42 + opt_tcp_mss,
43 opt_tcp_timestamp,
44 opt_clock_skew,
45 cs_window,
46 --- a/parseoptions.c
47 +++ b/parseoptions.c
48 @@ -31,7 +31,7 @@ enum { OPT_COUNT, OPT_INTERVAL, OPT_NUME
49 OPT_RROUTE, OPT_IPPROTO, OPT_ICMP_IPVER, OPT_ICMP_IPHLEN,
50 OPT_ICMP_IPLEN, OPT_ICMP_IPID, OPT_ICMP_IPPROTO, OPT_ICMP_CKSUM,
51 OPT_ICMP_TS, OPT_ICMP_ADDR, OPT_TCPEXITCODE, OPT_FAST, OPT_TR_KEEP_TTL,
52 - OPT_TCP_TIMESTAMP, OPT_TR_STOP, OPT_TR_NO_RTT, OPT_ICMP_HELP,
53 + OPT_TCP_TIMESTAMP, OPT_TCP_MSS, OPT_TR_STOP, OPT_TR_NO_RTT, OPT_ICMP_HELP,
54 OPT_RAND_DEST, OPT_RAND_SOURCE, OPT_LSRR, OPT_SSRR, OPT_ROUTE_HELP,
55 OPT_ICMP_IPSRC, OPT_ICMP_IPDST, OPT_ICMP_SRCPORT, OPT_ICMP_DSTPORT,
56 OPT_ICMP_GW, OPT_FORCE_ICMP, OPT_APD_SEND, OPT_SCAN, OPT_FASTER,
57 @@ -125,6 +125,7 @@ static struct ago_optlist hping_optlist[
58 { '\0', "force-icmp", OPT_FORCE_ICMP, AGO_NOARG },
59 { '\0', "beep", OPT_BEEP, AGO_NOARG },
60 { '\0', "flood", OPT_FLOOD, AGO_NOARG },
61 + { '\0', "tcp-mss", OPT_TCP_MSS, AGO_NEEDARG|AGO_EXCEPT0 },
62 { '\0', "clock-skew", OPT_CLOCK_SKEW, AGO_NOARG },
63 { '\0', "clock-skew-win", OPT_CS_WINDOW, AGO_NEEDARG},
64 { '\0', "clock-skew-win-shift", OPT_CS_WINDOW_SHIFT, AGO_NEEDARG},
65 @@ -561,6 +562,10 @@ int parse_options(int argc, char **argv)
66 case OPT_FLOOD:
67 opt_flood = TRUE;
68 break;
69 + case OPT_TCP_MSS:
70 + opt_tcp_mss = TRUE;
71 + tcp_mss = strtoul(ago_optarg, NULL, 0);
72 + break;
73 case OPT_CLOCK_SKEW:
74 opt_tcp_timestamp = TRUE;
75 opt_clock_skew = TRUE;
76 --- a/usage.c
77 +++ b/usage.c
78 @@ -87,6 +87,7 @@ void show_usage(void)
79 " -X --xmas set X unused flag (0x40)\n"
80 " -Y --ymas set Y unused flag (0x80)\n"
81 " --tcpexitcode use last tcp->th_flags as exit code\n"
82 +" --tcp-mss enable the TCP MSS option with the given value\n"
83 " --tcp-timestamp enable the TCP timestamp option to guess the HZ/uptime\n"
84 "Clock skew detection\n"
85 " --clock-skew enable clock skew detection. Try with -S against open port\n"
86 --- a/sendtcp.c
87 +++ b/sendtcp.c
88 @@ -28,10 +28,12 @@ void send_tcp(void)
89 char *packet, *data;
90 struct mytcphdr *tcp;
91 struct pseudohdr *pseudoheader;
92 - unsigned char *tstamp;
93 + unsigned char *opts;
94
95 + if (opt_tcp_mss)
96 + tcp_opt_size += 4;
97 if (opt_tcp_timestamp)
98 - tcp_opt_size = 12;
99 + tcp_opt_size += 12;
100
101 packet_size = TCPHDR_SIZE + tcp_opt_size + data_size;
102 packet = malloc(PSEUDOHDR_SIZE + packet_size);
103 @@ -41,7 +43,7 @@ void send_tcp(void)
104 }
105 pseudoheader = (struct pseudohdr*) packet;
106 tcp = (struct mytcphdr*) (packet+PSEUDOHDR_SIZE);
107 - tstamp = (unsigned char*) (packet+PSEUDOHDR_SIZE+TCPHDR_SIZE);
108 + opts = (unsigned char*) (packet+PSEUDOHDR_SIZE+TCPHDR_SIZE);
109 data = (char*) (packet+PSEUDOHDR_SIZE+TCPHDR_SIZE+tcp_opt_size);
110
111 memset(packet, 0, PSEUDOHDR_SIZE+packet_size);
112 @@ -64,14 +66,24 @@ void send_tcp(void)
113 tcp->th_win = htons(src_winsize);
114 tcp->th_flags = tcp_th_flags;
115
116 + /* tcp MSS option */
117 + if (opt_tcp_mss) {
118 + opts[0] = 2;
119 + opts[1] = 4; /* 4 bytes, kind+len+MSS */
120 + opts[2] = tcp_mss >> 8;
121 + opts[3] = tcp_mss & 0xff;
122 + opts += 4;
123 + }
124 +
125 /* tcp timestamp option */
126 if (opt_tcp_timestamp) {
127 __u32 randts = rand() ^ (rand() << 16);
128 - tstamp[0] = tstamp[1] = 1; /* NOOP */
129 - tstamp[2] = 8;
130 - tstamp[3] = 10; /* 10 bytes, kind+len+T1+T2 */
131 - memcpy(tstamp+4, &randts, 4); /* random */
132 - memset(tstamp+8, 0, 4); /* zero */
133 + opts[0] = opts[1] = 1; /* NOOP */
134 + opts[2] = 8;
135 + opts[3] = 10; /* 10 bytes, kind+len+T1+T2 */
136 + memcpy(opts+4, &randts, 4); /* random */
137 + memset(opts+8, 0, 4); /* zero */
138 + opts += 12;
139 }
140
141 /* data */
142 --- a/docs/hping3.8
143 +++ b/docs/hping3.8
144 @@ -98,6 +98,8 @@ hping2 \- send (almost) arbitrary TCP/IP
145 ] [
146 .B \-\-tcpexitcode
147 ] [
148 +.B \-\-tcp-mss
149 +] [
150 .B \-\-tcp-timestamp
151 ] [
152 .B \-\-tr-stop
153 @@ -510,6 +512,9 @@ numbers are predictable.
154 .I -b --badcksum
155 Send packets with a bad UDP/TCP checksum.
156 .TP
157 +.I --tcp-mss
158 +Enable the TCP MSS option and set it to the given value.
159 +.TP
160 .I --tcp-timestamp
161 Enable the TCP timestamp option, and try to guess the timestamp update
162 frequency and the remote system uptime.
163 --- a/docs/french/hping2-fr.8
164 +++ b/docs/french/hping2-fr.8
165 @@ -99,6 +99,8 @@ hping2 \- envoie des paquets TCP/IP (pre
166 ] [
167 .B \-\-tcpexitcode
168 ] [
169 +.B \-\-tcp-mss
170 +] [
171 .B \-\-tcp-timestamp
172 ] [
173 .B \-\-tr-stop
174 @@ -538,6 +540,9 @@ pouvez le voir les numéros de séquence d
175 .I -b --badcksum
176 Envoie des paquets avec une mauvaise somme de contrôle UDP/TCP
177 .TP
178 +.I --tcp-mss
179 +Active l'option TCP MSS et la fixe avec la valeur donnée.
180 +.TP
181 .I --tcp-timestamp
182 Active l'option TCP timestamp, et essaye de deviner la fréquence de mise à
183 jour du timestamp et l'uptime du système distant.