1 /* packet-pingpongprotocol.c
2 * Routines for the Ping Pong Protocol, a test application of the
3 * rsplib RSerPool implementation
4 * http://www.tdr.wiwi.uni-due.de/forschung/forschungsprojekte/reliable-server-pooling//
6 * Copyright 2006 by Thomas Dreibholz <dreibh [AT] exp-math.uni-essen.de>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * Copied from README.developer
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/packet.h>
34 #include <epan/sctpppids.h>
37 #define PINGPONGPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY 0x29097602
40 /* Initialize the protocol and registered fields */
41 static int proto_pingpongprotocol
= -1;
42 static int hf_message_type
= -1;
43 static int hf_message_flags
= -1;
44 static int hf_message_length
= -1;
45 static int hf_ping_messageno
= -1;
46 static int hf_ping_data
= -1;
47 static int hf_pong_messageno
= -1;
48 static int hf_pong_replyno
= -1;
49 static int hf_pong_data
= -1;
52 /* Initialize the subtree pointers */
53 static gint ett_pingpongprotocol
= -1;
55 /* Dissectors for messages. This is specific to PingPongProtocol */
56 #define MESSAGE_TYPE_LENGTH 1
57 #define MESSAGE_FLAGS_LENGTH 1
58 #define MESSAGE_LENGTH_LENGTH 2
60 #define MESSAGE_TYPE_OFFSET 0
61 #define MESSAGE_FLAGS_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
62 #define MESSAGE_LENGTH_OFFSET (MESSAGE_FLAGS_OFFSET + MESSAGE_FLAGS_LENGTH)
63 #define MESSAGE_VALUE_OFFSET (MESSAGE_LENGTH_OFFSET + MESSAGE_LENGTH_LENGTH)
66 #define PING_MESSAGENO_LENGTH 8
68 #define PING_MESSAGENO_OFFSET MESSAGE_VALUE_OFFSET
69 #define PING_DATA_OFFSET (PING_MESSAGENO_OFFSET + PING_MESSAGENO_LENGTH)
71 #define PONG_MESSAGENO_LENGTH 8
72 #define PONG_REPLYNO_LENGTH 8
74 #define PONG_MESSAGENO_OFFSET MESSAGE_VALUE_OFFSET
75 #define PONG_REPLYNO_OFFSET (PONG_MESSAGENO_OFFSET + PONG_MESSAGENO_LENGTH)
76 #define PONG_DATA_OFFSET (PONG_REPLYNO_OFFSET + PONG_REPLYNO_LENGTH)
79 #define PINGPONG_PING_MESSAGE_TYPE 0x01
80 #define PINGPONG_PONG_MESSAGE_TYPE 0x02
84 static const value_string message_type_values
[] = {
85 { PINGPONG_PONG_MESSAGE_TYPE
, "PingPongProtocol Pong" },
86 { PINGPONG_PING_MESSAGE_TYPE
, "PingPongProtocol Ping" },
92 dissect_pingpongprotocol_ping_message(tvbuff_t
*message_tvb
, proto_tree
*message_tree
)
94 guint16 ping_data_length
;
96 proto_tree_add_item(message_tree
, hf_ping_messageno
, message_tvb
, PING_MESSAGENO_OFFSET
, PING_MESSAGENO_LENGTH
, ENC_BIG_ENDIAN
);
98 ping_data_length
= tvb_get_ntohs(message_tvb
, MESSAGE_LENGTH_OFFSET
) - PING_DATA_OFFSET
;
99 if (ping_data_length
> 0)
100 proto_tree_add_item(message_tree
, hf_ping_data
, message_tvb
, PING_DATA_OFFSET
, ping_data_length
, ENC_NA
);
104 dissect_pingpongprotocol_pong_message(tvbuff_t
*message_tvb
, proto_tree
*message_tree
)
106 guint16 pong_data_length
;
108 proto_tree_add_item(message_tree
, hf_pong_messageno
, message_tvb
, PONG_MESSAGENO_OFFSET
, PONG_MESSAGENO_LENGTH
, ENC_BIG_ENDIAN
);
109 proto_tree_add_item(message_tree
, hf_pong_replyno
, message_tvb
, PONG_REPLYNO_OFFSET
, PONG_REPLYNO_LENGTH
, ENC_BIG_ENDIAN
);
111 pong_data_length
= tvb_get_ntohs(message_tvb
, MESSAGE_LENGTH_OFFSET
) - PONG_DATA_OFFSET
;
112 if (pong_data_length
> 0) {
113 proto_tree_add_item(message_tree
, hf_pong_data
, message_tvb
, PONG_DATA_OFFSET
, pong_data_length
, ENC_NA
);
119 dissect_pingpongprotocol_message(tvbuff_t
*message_tvb
, packet_info
*pinfo
, proto_tree
*pingpongprotocol_tree
)
123 type
= tvb_get_guint8(message_tvb
, MESSAGE_TYPE_OFFSET
);
124 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s ", val_to_str_const(type
, message_type_values
, "Unknown PingPongProtocol type"));
126 proto_tree_add_item(pingpongprotocol_tree
, hf_message_type
, message_tvb
, MESSAGE_TYPE_OFFSET
, MESSAGE_TYPE_LENGTH
, ENC_BIG_ENDIAN
);
127 proto_tree_add_item(pingpongprotocol_tree
, hf_message_flags
, message_tvb
, MESSAGE_FLAGS_OFFSET
, MESSAGE_FLAGS_LENGTH
, ENC_BIG_ENDIAN
);
128 proto_tree_add_item(pingpongprotocol_tree
, hf_message_length
, message_tvb
, MESSAGE_LENGTH_OFFSET
, MESSAGE_LENGTH_LENGTH
, ENC_BIG_ENDIAN
);
130 case PINGPONG_PING_MESSAGE_TYPE
:
131 dissect_pingpongprotocol_ping_message(message_tvb
, pingpongprotocol_tree
);
133 case PINGPONG_PONG_MESSAGE_TYPE
:
134 dissect_pingpongprotocol_pong_message(message_tvb
, pingpongprotocol_tree
);
140 dissect_pingpongprotocol(tvbuff_t
*message_tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
142 proto_item
*pingpongprotocol_item
;
143 proto_tree
*pingpongprotocol_tree
;
145 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "PingPongProtocol");
147 /* In the interest of speed, if "tree" is NULL, don't do any work not
148 necessary to generate protocol tree items. */
150 /* create the pingpongprotocol protocol tree */
151 pingpongprotocol_item
= proto_tree_add_item(tree
, proto_pingpongprotocol
, message_tvb
, 0, -1, ENC_NA
);
152 pingpongprotocol_tree
= proto_item_add_subtree(pingpongprotocol_item
, ett_pingpongprotocol
);
154 pingpongprotocol_tree
= NULL
;
156 /* dissect the message */
157 dissect_pingpongprotocol_message(message_tvb
, pinfo
, pingpongprotocol_tree
);
161 /* Register the protocol with Wireshark */
163 proto_register_pingpongprotocol(void)
166 /* Setup list of header fields */
167 static hf_register_info hf
[] = {
168 { &hf_message_type
, { "Type", "pingpongprotocol.message_type", FT_UINT8
, BASE_DEC
, VALS(message_type_values
), 0x0, NULL
, HFILL
} },
169 { &hf_message_flags
, { "Flags", "pingpongprotocol.message_flags", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
170 { &hf_message_length
, { "Length", "pingpongprotocol.message_length", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
171 { &hf_ping_messageno
, { "MessageNo", "pingpongprotocol.ping_messageno", FT_UINT64
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
172 { &hf_ping_data
, { "Ping_Data", "pingpongprotocol.ping_data", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} },
173 { &hf_pong_messageno
, { "MessageNo", "pingpongprotocol.pong_messageno", FT_UINT64
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
174 { &hf_pong_replyno
, { "ReplyNo", "pingpongprotocol.pong_replyno", FT_UINT64
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
175 { &hf_pong_data
, { "Pong_Data", "pingpongprotocol.pong_data", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} },
178 /* Setup protocol subtree array */
179 static gint
*ett
[] = {
180 &ett_pingpongprotocol
183 /* Register the protocol name and description */
184 proto_pingpongprotocol
= proto_register_protocol("Ping Pong Protocol", "PingPongProtocol", "pingpongprotocol");
186 /* Required function calls to register the header fields and subtrees used */
187 proto_register_field_array(proto_pingpongprotocol
, hf
, array_length(hf
));
188 proto_register_subtree_array(ett
, array_length(ett
));
192 proto_reg_handoff_pingpongprotocol(void)
194 dissector_handle_t pingpongprotocol_handle
;
196 pingpongprotocol_handle
= new_create_dissector_handle(dissect_pingpongprotocol
, proto_pingpongprotocol
);
197 dissector_add_uint("sctp.ppi", PINGPONGPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY
, pingpongprotocol_handle
);
198 dissector_add_uint("sctp.ppi", PPP_PAYLOAD_PROTOCOL_ID
, pingpongprotocol_handle
);