Use tvb_memeql() and tvb_memcpy().
[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
55   if (pinfo->destport == ECHO_PORT) {
56     request = TRUE;
57   }
58
59   col_set_str(pinfo->cinfo, COL_PROTOCOL, "ECHO");
60
61   if (check_col(pinfo->cinfo, COL_INFO)) {
62     col_set_str(pinfo->cinfo, COL_INFO,
63                  (request) ? "Request" : "Response");
64   }
65
66   if (tree) {
67
68     ti = proto_tree_add_item(tree, proto_echo, tvb, offset, -1, FALSE);
69     echo_tree = proto_item_add_subtree(ti, ett_echo);
70
71     if (request) {
72       hidden_item = proto_tree_add_boolean(echo_tree, hf_echo_request, tvb, 0, 0, 1);
73     } else {
74       hidden_item = proto_tree_add_boolean(echo_tree, hf_echo_response, tvb, 0, 0, 1);
75     }
76     PROTO_ITEM_SET_HIDDEN(hidden_item);
77
78     proto_tree_add_item(echo_tree, hf_echo_data, tvb, offset, -1, ENC_NA);
79
80   }
81
82 } /* dissect_echo */
83
84 void proto_register_echo(void)
85 {
86
87   static hf_register_info hf[] = {
88     { &hf_echo_data,
89       { "Echo data",    "echo.data",
90         FT_BYTES,       BASE_NONE,      NULL,   0x0,
91         NULL, HFILL }},
92     { &hf_echo_request,
93       { "Echo request", "echo.request",
94         FT_BOOLEAN,     BASE_NONE,      NULL,   0x0,
95         "Echo data", HFILL }},
96     { &hf_echo_response,
97       { "Echo response","echo.response",
98         FT_BOOLEAN,     BASE_NONE,      NULL,   0x0,
99         "Echo data", HFILL }}
100   };
101
102   static gint *ett[] = {
103     &ett_echo
104   };
105
106   proto_echo = proto_register_protocol("Echo", "ECHO", "echo");
107   proto_register_field_array(proto_echo, hf, array_length(hf));
108   proto_register_subtree_array(ett, array_length(ett));
109
110 }
111
112 void proto_reg_handoff_echo(void)
113 {
114
115   dissector_handle_t echo_handle;
116
117   echo_handle = create_dissector_handle(dissect_echo, proto_echo);
118
119   dissector_add_uint("udp.port", ECHO_PORT, echo_handle);
120   dissector_add_uint("tcp.port", ECHO_PORT, echo_handle);
121
122 }
123