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