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
8 @@ -44,7 +44,8 @@ unsigned int
19 opt_tcpexitcode = 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,
28 @@ -32,7 +32,8 @@ extern unsigned int
36 extern unsigned short int
38 @@ -77,6 +78,7 @@ extern int opt_debug,
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)
71 + tcp_mss = strtoul(ago_optarg, NULL, 0);
74 opt_tcp_timestamp = TRUE;
75 opt_clock_skew = TRUE;
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"
88 @@ -28,10 +28,12 @@ void send_tcp(void)
91 struct pseudohdr *pseudoheader;
92 - unsigned char *tstamp;
93 + unsigned char *opts;
97 if (opt_tcp_timestamp)
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)
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);
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;
116 + /* tcp MSS option */
119 + opts[1] = 4; /* 4 bytes, kind+len+MSS */
120 + opts[2] = tcp_mss >> 8;
121 + opts[3] = tcp_mss & 0xff;
125 /* tcp timestamp option */
126 if (opt_tcp_timestamp) {
127 __u32 randts = rand() ^ (rand() << 16);
128 - tstamp[0] = tstamp[1] = 1; /* NOOP */
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 */
135 + opts[3] = 10; /* 10 bytes, kind+len+T1+T2 */
136 + memcpy(opts+4, &randts, 4); /* random */
137 + memset(opts+8, 0, 4); /* zero */
144 @@ -98,6 +98,8 @@ hping2 \- send (almost) arbitrary TCP/IP
153 @@ -510,6 +512,9 @@ numbers are predictable.
155 Send packets with a bad UDP/TCP checksum.
158 +Enable the TCP MSS option and set it to the given value.
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
174 @@ -538,6 +540,9 @@ pouvez le voir les numéros de séquence d
176 Envoie des paquets avec une mauvaise somme de contrôle UDP/TCP
179 +Active l'option TCP MSS et la fixe avec la valeur donnée.
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.