Show CWR and ECN flags in TCP. Ulrich Kiermayr <kie@thp.univie.ac.at>
[obnox/wireshark/wip.git] / packet-tcp.c
1 /* packet-tcp.c
2  * Routines for TCP packet disassembly
3  *
4  * $Id: packet-tcp.c,v 1.83 2000/09/14 21:58:48 gram Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #ifdef HAVE_NETINET_IN_H
35 # include <netinet/in.h>
36 #endif
37
38 #include <stdio.h>
39 #include <glib.h>
40
41 #ifdef NEED_SNPRINTF_H
42 # include "snprintf.h"
43 #endif
44
45 #include "globals.h"
46 #include "resolv.h"
47 #include "follow.h"
48 #include "prefs.h"
49 #include "plugins.h"
50 #include "packet-tcp.h"
51 #include "packet-ip.h"
52 #include "conversation.h"
53 #include "strutil.h"
54
55 /* Place TCP summary in proto tree */
56 gboolean g_tcp_summary_in_tree = TRUE;
57
58 extern FILE* data_out_file;
59
60 guint16 tcp_urgent_pointer;
61
62 static gchar info_str[COL_MAX_LEN];
63 static int   info_len;
64
65 static int proto_tcp = -1;
66 static int hf_tcp_srcport = -1;
67 static int hf_tcp_dstport = -1;
68 static int hf_tcp_port = -1;
69 static int hf_tcp_seq = -1;
70 static int hf_tcp_ack = -1;
71 static int hf_tcp_hdr_len = -1;
72 static int hf_tcp_flags = -1;
73 static int hf_tcp_flags_cwr = -1;
74 static int hf_tcp_flags_ecn = -1;
75 static int hf_tcp_flags_urg = -1;
76 static int hf_tcp_flags_ack = -1;
77 static int hf_tcp_flags_push = -1;
78 static int hf_tcp_flags_reset = -1;
79 static int hf_tcp_flags_syn = -1;
80 static int hf_tcp_flags_fin = -1;
81 static int hf_tcp_window_size = -1;
82 static int hf_tcp_checksum = -1;
83 static int hf_tcp_urgent_pointer = -1;
84
85 static gint ett_tcp = -1;
86 static gint ett_tcp_flags = -1;
87 static gint ett_tcp_options = -1;
88 static gint ett_tcp_option_sack = -1;
89
90 static dissector_table_t subdissector_table;
91 static heur_dissector_list_t heur_subdissector_list;
92
93 /* TCP Ports */
94
95 #define TCP_PORT_SMTP                   25
96
97 /* TCP structs and definitions */
98
99 typedef struct _e_tcphdr {
100   guint16 th_sport;
101   guint16 th_dport;
102   guint32 th_seq;
103   guint32 th_ack;
104   guint8  th_off_x2; /* combines th_off and th_x2 */
105   guint8  th_flags;
106 #define TH_FIN  0x01
107 #define TH_SYN  0x02
108 #define TH_RST  0x04
109 #define TH_PUSH 0x08
110 #define TH_ACK  0x10
111 #define TH_URG  0x20
112 #define TH_ECN  0x40
113 #define TH_CWR  0x80
114   guint16 th_win;
115   guint16 th_sum;
116   guint16 th_urp;
117 } e_tcphdr;
118
119 /*
120  *      TCP option
121  */
122  
123 #define TCPOPT_NOP              1       /* Padding */
124 #define TCPOPT_EOL              0       /* End of options */
125 #define TCPOPT_MSS              2       /* Segment size negotiating */
126 #define TCPOPT_WINDOW           3       /* Window scaling */
127 #define TCPOPT_SACK_PERM        4       /* SACK Permitted */
128 #define TCPOPT_SACK             5       /* SACK Block */
129 #define TCPOPT_ECHO             6
130 #define TCPOPT_ECHOREPLY        7
131 #define TCPOPT_TIMESTAMP        8       /* Better RTT estimations/PAWS */
132 #define TCPOPT_CC               11
133 #define TCPOPT_CCNEW            12
134 #define TCPOPT_CCECHO           13
135
136 /*
137  *     TCP option lengths
138  */
139
140 #define TCPOLEN_MSS            4
141 #define TCPOLEN_WINDOW         3
142 #define TCPOLEN_SACK_PERM      2
143 #define TCPOLEN_SACK_MIN       2
144 #define TCPOLEN_ECHO           6
145 #define TCPOLEN_ECHOREPLY      6
146 #define TCPOLEN_TIMESTAMP      10
147 #define TCPOLEN_CC             6
148 #define TCPOLEN_CCNEW          6
149 #define TCPOLEN_CCECHO         6
150
151 static void
152 tcp_info_append_uint(const char *abbrev, guint32 val) {
153   int add_len = 0;
154   
155   if (info_len > 0)
156   if(info_len > 0)
157     add_len = snprintf(&info_str[info_len], COL_MAX_LEN - info_len, " %s=%u",
158       abbrev, val);
159   if (add_len > 0)
160     info_len += add_len;
161 }
162
163 static void
164 dissect_tcpopt_maxseg(const ip_tcp_opt *optp, const u_char *opd,
165     int offset, guint optlen, proto_tree *opt_tree)
166 {
167   proto_tree_add_text(opt_tree, NullTVB, offset,      optlen,
168                         "%s: %u bytes", optp->name, pntohs(opd));
169   tcp_info_append_uint("MSS", pntohs(opd));
170 }
171
172 static void
173 dissect_tcpopt_wscale(const ip_tcp_opt *optp, const u_char *opd,
174     int offset, guint optlen, proto_tree *opt_tree)
175 {
176   proto_tree_add_text(opt_tree, NullTVB, offset,      optlen,
177                         "%s: %u bytes", optp->name, *opd);
178   tcp_info_append_uint("WS", *opd);
179 }
180
181 static void
182 dissect_tcpopt_sack(const ip_tcp_opt *optp, const u_char *opd,
183     int offset, guint optlen, proto_tree *opt_tree)
184 {
185   proto_tree *field_tree = NULL;
186   proto_item *tf;
187   guint leftedge, rightedge;
188
189   tf = proto_tree_add_text(opt_tree, NullTVB, offset,      optlen, "%s:", optp->name);
190   offset += 2;  /* skip past type and length */
191   optlen -= 2;  /* subtract size of type and length */
192   while (optlen > 0) {
193     if (field_tree == NULL) {
194       /* Haven't yet made a subtree out of this option.  Do so. */
195       field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
196     }
197     if (optlen < 4) {
198       proto_tree_add_text(field_tree, NullTVB, offset,      optlen,
199         "(suboption would go past end of option)");
200       break;
201     }
202     /* XXX - check whether it goes past end of packet */
203     leftedge = pntohl(opd);
204     opd += 4;
205     optlen -= 4;
206     if (optlen < 4) {
207       proto_tree_add_text(field_tree, NullTVB, offset,      optlen,
208         "(suboption would go past end of option)");
209       break;
210     }
211     /* XXX - check whether it goes past end of packet */
212     rightedge = pntohl(opd);
213     opd += 4;
214     optlen -= 4;
215     proto_tree_add_text(field_tree, NullTVB, offset,      8,
216         "left edge = %u, right edge = %u", leftedge, rightedge);
217     tcp_info_append_uint("SLE", leftedge);
218     tcp_info_append_uint("SRE", rightedge);
219     offset += 8;
220   }
221 }
222
223 static void
224 dissect_tcpopt_echo(const ip_tcp_opt *optp, const u_char *opd,
225     int offset, guint optlen, proto_tree *opt_tree)
226 {
227   proto_tree_add_text(opt_tree, NullTVB, offset,      optlen,
228                         "%s: %u", optp->name, pntohl(opd));
229   tcp_info_append_uint("ECHO", pntohl(opd));
230 }
231
232 static void
233 dissect_tcpopt_timestamp(const ip_tcp_opt *optp, const u_char *opd,
234     int offset, guint optlen, proto_tree *opt_tree)
235 {
236   proto_tree_add_text(opt_tree, NullTVB, offset,      optlen,
237     "%s: tsval %u, tsecr %u", optp->name, pntohl(opd), pntohl(opd + 4));
238   tcp_info_append_uint("TSV", pntohl(opd));
239   tcp_info_append_uint("TSER", pntohl(opd + 4));
240 }
241
242 static void
243 dissect_tcpopt_cc(const ip_tcp_opt *optp, const u_char *opd,
244     int offset, guint optlen, proto_tree *opt_tree)
245 {
246   proto_tree_add_text(opt_tree, NullTVB, offset,      optlen,
247                         "%s: %u", optp->name, pntohl(opd));
248   tcp_info_append_uint("CC", pntohl(opd));
249 }
250
251 static const ip_tcp_opt tcpopts[] = {
252   {
253     TCPOPT_EOL,
254     "EOL",
255     NULL,
256     NO_LENGTH,
257     0,
258     NULL,
259   },
260   {
261     TCPOPT_NOP,
262     "NOP",
263     NULL,
264     NO_LENGTH,
265     0,
266     NULL,
267   },
268   {
269     TCPOPT_MSS,
270     "Maximum segment size",
271     NULL,
272     FIXED_LENGTH,
273     TCPOLEN_MSS,
274     dissect_tcpopt_maxseg
275   },
276   {
277     TCPOPT_WINDOW,
278     "Window scale",
279     NULL,
280     FIXED_LENGTH,
281     TCPOLEN_WINDOW,
282     dissect_tcpopt_wscale
283   },
284   {
285     TCPOPT_SACK_PERM,
286     "SACK permitted",
287     NULL,
288     FIXED_LENGTH,
289     TCPOLEN_SACK_PERM,
290     NULL,
291   },
292   {
293     TCPOPT_SACK,
294     "SACK",
295     &ett_tcp_option_sack,
296     VARIABLE_LENGTH,
297     TCPOLEN_SACK_MIN,
298     dissect_tcpopt_sack
299   },
300   {
301     TCPOPT_ECHO,
302     "Echo",
303     NULL,
304     FIXED_LENGTH,
305     TCPOLEN_ECHO,
306     dissect_tcpopt_echo
307   },
308   {
309     TCPOPT_ECHOREPLY,
310     "Echo reply",
311     NULL,
312     FIXED_LENGTH,
313     TCPOLEN_ECHOREPLY,
314     dissect_tcpopt_echo
315   },
316   {
317     TCPOPT_TIMESTAMP,
318     "Time stamp",
319     NULL,
320     FIXED_LENGTH,
321     TCPOLEN_TIMESTAMP,
322     dissect_tcpopt_timestamp
323   },
324   {
325     TCPOPT_CC,
326     "CC",
327     NULL,
328     FIXED_LENGTH,
329     TCPOLEN_CC,
330     dissect_tcpopt_cc
331   },
332   {
333     TCPOPT_CCNEW,
334     "CC.NEW",
335     NULL,
336     FIXED_LENGTH,
337     TCPOPT_CCNEW,
338     dissect_tcpopt_cc
339   },
340   {
341     TCPOPT_CCECHO,
342     "CC.ECHO",
343     NULL,
344     FIXED_LENGTH,
345     TCPOLEN_CCECHO,
346     dissect_tcpopt_cc
347   }
348 };
349
350 #define N_TCP_OPTS      (sizeof tcpopts / sizeof tcpopts[0])
351
352 /* TCP flags flag */
353 static const true_false_string flags_set_truth = {
354   "Set",
355   "Not set"
356 };
357
358
359 /* Determine if there is a sub-dissector and call it.  This has been */
360 /* separated into a stand alone routine to other protocol dissectors */
361 /* can call to it, ie. socks    */
362
363 void
364 decode_tcp_ports(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
365         int src_port, int dst_port)
366 {
367 /* determine if this packet is part of a conversation and call dissector */
368 /* for the conversation if available */
369
370   if (old_try_conversation_dissector(&pi.src, &pi.dst, PT_TCP,
371                 src_port, dst_port, pd, offset, fd, tree))
372         return;
373
374   /* try to apply the plugins */
375 #ifdef HAVE_PLUGINS
376   {
377     plugin *pt_plug = plugin_list;
378
379     if (enabled_plugins_number > 0) {
380       while (pt_plug) {
381         if (pt_plug->enabled && !strcmp(pt_plug->protocol, "tcp") &&
382             tree && dfilter_apply(pt_plug->filter, tree, pd, fd->cap_len)) {
383           pt_plug->dissector(pd, offset, fd, tree);
384           return;
385         }
386         pt_plug = pt_plug->next;
387       }
388     }
389   }
390 #endif
391
392   /* do lookup with the subdissector table */
393   if (old_dissector_try_port(subdissector_table, src_port, pd, offset, fd, tree) ||
394       old_dissector_try_port(subdissector_table, dst_port, pd, offset, fd, tree))
395     return;
396
397   /* do lookup with the heuristic subdissector table */
398   if (old_dissector_try_heuristic(heur_subdissector_list, pd, offset, fd, tree))
399     return;
400
401   /* Oh, well, we don't know this; dissect it as data. */
402   old_dissect_data(pd, offset, fd, tree);
403 }
404
405
406 static void
407 dissect_tcp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
408   e_tcphdr   th;
409   proto_tree *tcp_tree = NULL, *field_tree = NULL;
410   proto_item *ti, *tf;
411   gchar      flags[64] = "<None>";
412   gchar     *fstr[] = {"FIN", "SYN", "RST", "PSH", "ACK", "URG", "ECN", "CWR" };
413   gint       fpos = 0, i;
414   guint      bpos;
415   guint      hlen;
416   guint      optlen;
417   guint      packet_max = pi.len;
418
419   OLD_CHECK_DISPLAY_AS_DATA(proto_tcp, pd, offset, fd, tree);
420
421   /* To do: Check for {cap len,pkt len} < struct len */
422   /* Avoids alignment problems on many architectures. */
423   memcpy(&th, &pd[offset], sizeof(e_tcphdr));
424   th.th_sport = ntohs(th.th_sport);
425   th.th_dport = ntohs(th.th_dport);
426   th.th_win   = ntohs(th.th_win);
427   th.th_sum   = ntohs(th.th_sum);
428   th.th_urp   = ntohs(th.th_urp);
429   th.th_seq   = ntohl(th.th_seq);
430   th.th_ack   = ntohl(th.th_ack);
431
432   /* Export the urgent pointer, for the benefit of protocols such as
433      rlogin. */
434   tcp_urgent_pointer = th.th_urp;
435  
436   info_len = 0;
437
438   if (check_col(fd, COL_PROTOCOL) || tree) {  
439     for (i = 0; i < 8; i++) {
440       bpos = 1 << i;
441       if (th.th_flags & bpos) {
442         if (fpos) {
443           strcpy(&flags[fpos], ", ");
444           fpos += 2;
445         }
446         strcpy(&flags[fpos], fstr[i]);
447         fpos += 3;
448       }
449     }
450     flags[fpos] = '\0';
451   }
452   
453   hlen = hi_nibble(th.th_off_x2) * 4;  /* TCP header length, in bytes */
454
455   if (check_col(fd, COL_PROTOCOL))
456     col_add_str(fd, COL_PROTOCOL, "TCP");
457   if (check_col(fd, COL_INFO)) {
458     /* Copy the data into info_str in case one of the option handling
459        routines needs to append to it. */
460     if (th.th_flags & TH_URG)
461       info_len = snprintf(info_str, COL_MAX_LEN, "%s > %s [%s] Seq=%u Ack=%u Win=%u Urg=%u Len=%d",
462         get_tcp_port(th.th_sport), get_tcp_port(th.th_dport), flags,
463         th.th_seq, th.th_ack, th.th_win, th.th_urp, pi.len - offset - hlen);
464     else
465       info_len = snprintf(info_str, COL_MAX_LEN, "%s > %s [%s] Seq=%u Ack=%u Win=%u Len=%d",
466         get_tcp_port(th.th_sport), get_tcp_port(th.th_dport), flags,
467         th.th_seq, th.th_ack, th.th_win, pi.len - offset - hlen);
468     /* The info column is actually written after the options are decoded */
469   }
470   
471   if (tree) {
472     if (g_tcp_summary_in_tree) {
473             ti = proto_tree_add_protocol_format(tree, proto_tcp, NullTVB, offset, hlen, "Transmission Control Protocol, Src Port: %s (%u), Dst Port: %s (%u), Seq: %u, Ack: %u", get_tcp_port(th.th_sport), th.th_sport, get_tcp_port(th.th_dport), th.th_dport, th.th_seq, th.th_ack);
474     }
475     else {
476             ti = proto_tree_add_item(tree, proto_tcp, NullTVB, offset, hlen, FALSE);
477     }
478     tcp_tree = proto_item_add_subtree(ti, ett_tcp);
479     proto_tree_add_uint_format(tcp_tree, hf_tcp_srcport, NullTVB, offset, 2, th.th_sport,
480         "Source port: %s (%u)", get_tcp_port(th.th_sport), th.th_sport);
481     proto_tree_add_uint_format(tcp_tree, hf_tcp_dstport, NullTVB, offset + 2, 2, th.th_dport,
482         "Destination port: %s (%u)", get_tcp_port(th.th_dport), th.th_dport);
483     proto_tree_add_uint_hidden(tcp_tree, hf_tcp_port, NullTVB, offset, 2, th.th_sport);
484     proto_tree_add_uint_hidden(tcp_tree, hf_tcp_port, NullTVB, offset + 2, 2, th.th_dport);
485     proto_tree_add_uint(tcp_tree, hf_tcp_seq, NullTVB, offset + 4, 4, th.th_seq);
486     if (th.th_flags & TH_ACK)
487       proto_tree_add_uint(tcp_tree, hf_tcp_ack, NullTVB, offset + 8, 4, th.th_ack);
488     proto_tree_add_uint_format(tcp_tree, hf_tcp_hdr_len, NullTVB, offset + 12, 1, hlen,
489         "Header length: %u bytes", hlen);
490     tf = proto_tree_add_uint_format(tcp_tree, hf_tcp_flags, NullTVB, offset + 13, 1,
491         th.th_flags, "Flags: 0x%04x (%s)", th.th_flags, flags);
492     field_tree = proto_item_add_subtree(tf, ett_tcp_flags);
493     proto_tree_add_boolean(field_tree, hf_tcp_flags_cwr, NullTVB, offset + 13, 1, th.th_flags);
494     proto_tree_add_boolean(field_tree, hf_tcp_flags_ecn, NullTVB, offset + 13, 1, th.th_flags);
495     proto_tree_add_boolean(field_tree, hf_tcp_flags_urg, NullTVB, offset + 13, 1, th.th_flags);
496     proto_tree_add_boolean(field_tree, hf_tcp_flags_ack, NullTVB, offset + 13, 1, th.th_flags);
497     proto_tree_add_boolean(field_tree, hf_tcp_flags_push, NullTVB, offset + 13, 1, th.th_flags);
498     proto_tree_add_boolean(field_tree, hf_tcp_flags_reset, NullTVB, offset + 13, 1, th.th_flags);
499     proto_tree_add_boolean(field_tree, hf_tcp_flags_syn, NullTVB, offset + 13, 1, th.th_flags);
500     proto_tree_add_boolean(field_tree, hf_tcp_flags_fin, NullTVB, offset + 13, 1, th.th_flags);
501     proto_tree_add_uint(tcp_tree, hf_tcp_window_size, NullTVB, offset + 14, 2, th.th_win);
502     proto_tree_add_uint(tcp_tree, hf_tcp_checksum, NullTVB, offset + 16, 2, th.th_sum);
503     if (th.th_flags & TH_URG)
504       proto_tree_add_uint(tcp_tree, hf_tcp_urgent_pointer, NullTVB, offset + 18, 2, th.th_urp);
505   }
506
507   /* Decode TCP options, if any. */
508   if (tree  && hlen > sizeof (e_tcphdr)) {
509     /* There's more than just the fixed-length header.  Decode the
510        options. */
511     optlen = hlen - sizeof (e_tcphdr); /* length of options, in bytes */
512     tf = proto_tree_add_text(tcp_tree, NullTVB, offset +  20, optlen,
513       "Options: (%d bytes)", optlen);
514     field_tree = proto_item_add_subtree(tf, ett_tcp_options);
515     dissect_ip_tcp_options(&pd[offset + 20], offset + 20, optlen,
516       tcpopts, N_TCP_OPTS, TCPOPT_EOL, field_tree);
517   }
518
519   if (check_col(fd, COL_INFO))
520     col_add_str(fd, COL_INFO, info_str);
521
522   /* Skip over header + options */
523   offset += hlen;
524
525   pi.ptype = PT_TCP;
526   pi.srcport = th.th_sport;
527   pi.destport = th.th_dport;
528   
529   /* Check the packet length to see if there's more data
530      (it could be an ACK-only packet) */
531   if (packet_max > offset) {
532     if (th.th_flags & TH_RST) {
533       /*
534        * RFC1122 says:
535        *
536        *        4.2.2.12  RST Segment: RFC-793 Section 3.4
537        *
538        *          A TCP SHOULD allow a received RST segment to include data.
539        *
540        *          DISCUSSION
541        *               It has been suggested that a RST segment could contain
542        *               ASCII text that encoded and explained the cause of the
543        *               RST.  No standard has yet been established for such
544        *               data.
545        *
546        * so for segments with RST we just display the data as text.
547        */
548       proto_tree_add_text(tcp_tree, NullTVB, offset, END_OF_FRAME,
549                             "Reset cause: %s",
550                             format_text(&pd[offset], END_OF_FRAME));
551     } else
552       decode_tcp_ports( pd, offset, fd, tree, th.th_sport, th.th_dport);
553   }
554  
555   if( data_out_file ) {
556     reassemble_tcp( th.th_seq,          /* sequence number */
557         ( pi.len - offset ),            /* data length */
558         ( pd+offset ),                  /* data */
559         ( pi.captured_len - offset ),   /* captured data length */
560         ( th.th_flags & TH_SYN ),       /* is syn set? */
561         &pi.net_src,
562         &pi.net_dst,
563         pi.srcport,
564         pi.destport);
565   }
566 }
567
568 void
569 proto_register_tcp(void)
570 {
571         static hf_register_info hf[] = {
572
573                 { &hf_tcp_srcport,
574                 { "Source Port",                "tcp.srcport", FT_UINT16, BASE_DEC, NULL, 0x0,
575                         "" }},
576
577                 { &hf_tcp_dstport,
578                 { "Destination Port",           "tcp.dstport", FT_UINT16, BASE_DEC, NULL, 0x0,
579                         "" }},
580
581                 { &hf_tcp_port,
582                 { "Source or Destination Port", "tcp.port", FT_UINT16, BASE_DEC, NULL, 0x0,
583                         "" }},
584
585                 { &hf_tcp_seq,
586                 { "Sequence number",            "tcp.seq", FT_UINT32, BASE_DEC, NULL, 0x0,
587                         "" }},
588
589                 { &hf_tcp_ack,
590                 { "Acknowledgement number",     "tcp.ack", FT_UINT32, BASE_DEC, NULL, 0x0,
591                         "" }},
592
593                 { &hf_tcp_hdr_len,
594                 { "Header Length",              "tcp.hdr_len", FT_UINT8, BASE_DEC, NULL, 0x0,
595                         "" }},
596
597                 { &hf_tcp_flags,
598                 { "Flags",                      "tcp.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
599                         "" }},
600
601                 { &hf_tcp_flags_cwr,
602                 { "Congestion Window Reduced (CWR)",                    "tcp.flags.cwr", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_CWR,
603                         "" }},
604
605                 { &hf_tcp_flags_ecn,
606                 { "ECN-Echo",                   "tcp.flags.ecn", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_ECN,
607                         "" }},
608
609                 { &hf_tcp_flags_urg,
610                 { "Urgent",                     "tcp.flags.urg", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_URG,
611                         "" }},
612
613                 { &hf_tcp_flags_ack,
614                 { "Acknowledgment",             "tcp.flags.ack", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_ACK,
615                         "" }},
616
617                 { &hf_tcp_flags_push,
618                 { "Push",                       "tcp.flags.push", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_PUSH,
619                         "" }},
620
621                 { &hf_tcp_flags_reset,
622                 { "Reset",                      "tcp.flags.reset", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_RST,
623                         "" }},
624
625                 { &hf_tcp_flags_syn,
626                 { "Syn",                        "tcp.flags.syn", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_SYN,
627                         "" }},
628
629                 { &hf_tcp_flags_fin,
630                 { "Fin",                        "tcp.flags.fin", FT_BOOLEAN, 8, TFS(&flags_set_truth), TH_FIN,
631                         "" }},
632
633                 { &hf_tcp_window_size,
634                 { "Window size",                "tcp.window_size", FT_UINT16, BASE_DEC, NULL, 0x0,
635                         "" }},
636
637                 { &hf_tcp_checksum,
638                 { "Checksum",                   "tcp.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
639                         "" }},
640
641                 { &hf_tcp_urgent_pointer,
642                 { "Urgent pointer",             "tcp.urgent_pointer", FT_UINT16, BASE_DEC, NULL, 0x0,
643                         "" }},
644         };
645         static gint *ett[] = {
646                 &ett_tcp,
647                 &ett_tcp_flags,
648                 &ett_tcp_options,
649                 &ett_tcp_option_sack,
650         };
651         module_t *tcp_module;
652
653         proto_tcp = proto_register_protocol ("Transmission Control Protocol", "tcp");
654         proto_register_field_array(proto_tcp, hf, array_length(hf));
655         proto_register_subtree_array(ett, array_length(ett));
656
657         /* subdissector code */
658         subdissector_table = register_dissector_table("tcp.port");
659         register_heur_dissector_list("tcp", &heur_subdissector_list);
660
661         /* Register a configuration preferences */
662         tcp_module = prefs_register_module("tcp", "TCP", NULL);
663         prefs_register_bool_preference(tcp_module, "tcp_summary_in_tree",
664             "Show TCP summary in protocol tree",
665 "Whether the TCP summary line should be shown in the protocol tree",
666             &g_tcp_summary_in_tree);
667 }
668
669 void
670 proto_reg_handoff_tcp(void)
671 {
672         old_dissector_add("ip.proto", IP_PROTO_TCP, dissect_tcp);
673 }