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