Define some fcns & vars as static...
[metze/wireshark/wip.git] / epan / dissectors / packet-echo.c
1 /* packet-echo.c
2  * Routines for ECHO packet disassembly (RFC862)
3  *
4  * Only useful to mark the packets as ECHO in the summary and in the
5  * protocol hierarchy statistics (since not so many fields to decode ;-)
6  *
7  * Laurent Deniel <laurent.deniel@free.fr>
8  *
9  * $Id$
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <glib.h>
35 #include <epan/packet.h>
36
37 #define ECHO_PORT       7
38
39 static int proto_echo = -1;
40
41 static int hf_echo_data = -1;
42 static int hf_echo_request = -1;
43 static int hf_echo_response = -1;
44
45 static gint ett_echo = -1;
46
47 static void dissect_echo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
48 {
49   
50   proto_tree   *echo_tree = NULL;
51   proto_item   *ti, *hidden_item;
52   int           offset = 0;
53   gboolean      request = FALSE;
54   const guint8 *data = tvb_get_ptr(tvb, offset, -1);
55
56   if (pinfo->destport == ECHO_PORT) {
57     request = TRUE;
58   }
59
60   col_set_str(pinfo->cinfo, COL_PROTOCOL, "ECHO");
61
62   if (check_col(pinfo->cinfo, COL_INFO)) {
63     col_set_str(pinfo->cinfo, COL_INFO, 
64                  (request) ? "Request" : "Response");
65   }
66   
67   if (tree) {
68
69     ti = proto_tree_add_item(tree, proto_echo, tvb, offset, -1, FALSE);
70     echo_tree = proto_item_add_subtree(ti, ett_echo);
71
72     if (request) {
73       hidden_item = proto_tree_add_boolean(echo_tree, hf_echo_request, tvb, 0, 0, 1);
74     } else {
75       hidden_item = proto_tree_add_boolean(echo_tree, hf_echo_response, tvb, 0, 0, 1);
76     }
77     PROTO_ITEM_SET_HIDDEN(hidden_item);
78
79     proto_tree_add_bytes(echo_tree, hf_echo_data, tvb, offset, -1, data);
80
81   }
82
83 } /* dissect_echo */
84
85 void proto_register_echo(void) 
86 {
87
88   static hf_register_info hf[] = {
89     { &hf_echo_data,
90       { "Echo data",    "echo.data", 
91         FT_BYTES,       BASE_NONE,      NULL,   0x0,
92         NULL, HFILL }},
93     { &hf_echo_request,
94       { "Echo request", "echo.request", 
95         FT_BOOLEAN,     BASE_NONE,      NULL,   0x0,
96         "Echo data", HFILL }},
97     { &hf_echo_response,
98       { "Echo response","echo.response", 
99         FT_BOOLEAN,     BASE_NONE,      NULL,   0x0,
100         "Echo data", HFILL }}
101   };
102
103   static gint *ett[] = {
104     &ett_echo
105   };
106
107   proto_echo = proto_register_protocol("Echo", "ECHO", "echo");
108   proto_register_field_array(proto_echo, hf, array_length(hf));
109   proto_register_subtree_array(ett, array_length(ett));
110
111 }
112
113 void proto_reg_handoff_echo(void) 
114 {
115
116   dissector_handle_t echo_handle;
117
118   echo_handle = create_dissector_handle(dissect_echo, proto_echo);
119
120   dissector_add("udp.port", ECHO_PORT, echo_handle);
121   dissector_add("tcp.port", ECHO_PORT, echo_handle);
122
123 }
124