2006-06-09 21:41:02 +00:00
|
|
|
/* packet-pingpongprotocol.c
|
|
|
|
* Routines for the Ping Pong Protocol, a test application of the
|
|
|
|
* rsplib RSerPool implementation
|
2011-11-12 21:16:43 +00:00
|
|
|
* http://www.tdr.wiwi.uni-due.de/forschung/forschungsprojekte/reliable-server-pooling//
|
2006-06-09 21:41:02 +00:00
|
|
|
*
|
|
|
|
* Copyright 2006 by Thomas Dreibholz <dreibh [AT] exp-math.uni-essen.de>
|
|
|
|
*
|
2006-06-09 21:45:06 +00:00
|
|
|
* $Id$
|
2006-06-09 21:41:02 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from README.developer
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 23:18:38 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-06-09 21:41:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2011-02-10 12:54:20 +00:00
|
|
|
#include <epan/sctpppids.h>
|
2006-06-09 21:41:02 +00:00
|
|
|
|
|
|
|
|
2011-02-10 12:54:20 +00:00
|
|
|
#define PINGPONGPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY 0x29097602
|
2006-06-09 21:41:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_pingpongprotocol = -1;
|
|
|
|
static int hf_message_type = -1;
|
|
|
|
static int hf_message_flags = -1;
|
|
|
|
static int hf_message_length = -1;
|
|
|
|
static int hf_ping_messageno = -1;
|
|
|
|
static int hf_ping_data = -1;
|
|
|
|
static int hf_pong_messageno = -1;
|
|
|
|
static int hf_pong_replyno = -1;
|
|
|
|
static int hf_pong_data = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_pingpongprotocol = -1;
|
|
|
|
|
|
|
|
/* Dissectors for messages. This is specific to PingPongProtocol */
|
|
|
|
#define MESSAGE_TYPE_LENGTH 1
|
|
|
|
#define MESSAGE_FLAGS_LENGTH 1
|
|
|
|
#define MESSAGE_LENGTH_LENGTH 2
|
|
|
|
|
|
|
|
#define MESSAGE_TYPE_OFFSET 0
|
|
|
|
#define MESSAGE_FLAGS_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
|
|
|
|
#define MESSAGE_LENGTH_OFFSET (MESSAGE_FLAGS_OFFSET + MESSAGE_FLAGS_LENGTH)
|
|
|
|
#define MESSAGE_VALUE_OFFSET (MESSAGE_LENGTH_OFFSET + MESSAGE_LENGTH_LENGTH)
|
|
|
|
|
|
|
|
|
|
|
|
#define PING_MESSAGENO_LENGTH 8
|
|
|
|
|
|
|
|
#define PING_MESSAGENO_OFFSET MESSAGE_VALUE_OFFSET
|
|
|
|
#define PING_DATA_OFFSET (PING_MESSAGENO_OFFSET + PING_MESSAGENO_LENGTH)
|
|
|
|
|
|
|
|
#define PONG_MESSAGENO_LENGTH 8
|
|
|
|
#define PONG_REPLYNO_LENGTH 8
|
|
|
|
|
|
|
|
#define PONG_MESSAGENO_OFFSET MESSAGE_VALUE_OFFSET
|
|
|
|
#define PONG_REPLYNO_OFFSET (PONG_MESSAGENO_OFFSET + PONG_MESSAGENO_LENGTH)
|
|
|
|
#define PONG_DATA_OFFSET (PONG_REPLYNO_OFFSET + PONG_REPLYNO_LENGTH)
|
|
|
|
|
|
|
|
|
|
|
|
#define PINGPONG_PING_MESSAGE_TYPE 0x01
|
|
|
|
#define PINGPONG_PONG_MESSAGE_TYPE 0x02
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const value_string message_type_values[] = {
|
|
|
|
{ PINGPONG_PONG_MESSAGE_TYPE, "PingPongProtocol Pong" },
|
|
|
|
{ PINGPONG_PING_MESSAGE_TYPE, "PingPongProtocol Ping" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_pingpongprotocol_ping_message(tvbuff_t *message_tvb, proto_tree *message_tree)
|
|
|
|
{
|
|
|
|
guint16 ping_data_length;
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(message_tree, hf_ping_messageno, message_tvb, PING_MESSAGENO_OFFSET, PING_MESSAGENO_LENGTH, ENC_BIG_ENDIAN);
|
2006-06-09 21:41:02 +00:00
|
|
|
|
|
|
|
ping_data_length = tvb_get_ntohs(message_tvb, MESSAGE_LENGTH_OFFSET) - PING_DATA_OFFSET;
|
|
|
|
if (ping_data_length > 0)
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(message_tree, hf_ping_data, message_tvb, PING_DATA_OFFSET, ping_data_length, ENC_NA);
|
2006-06-09 21:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_pingpongprotocol_pong_message(tvbuff_t *message_tvb, proto_tree *message_tree)
|
|
|
|
{
|
|
|
|
guint16 pong_data_length;
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(message_tree, hf_pong_messageno, message_tvb, PONG_MESSAGENO_OFFSET, PONG_MESSAGENO_LENGTH, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(message_tree, hf_pong_replyno, message_tvb, PONG_REPLYNO_OFFSET, PONG_REPLYNO_LENGTH, ENC_BIG_ENDIAN);
|
2006-06-09 21:41:02 +00:00
|
|
|
|
|
|
|
pong_data_length = tvb_get_ntohs(message_tvb, MESSAGE_LENGTH_OFFSET) - PONG_DATA_OFFSET;
|
|
|
|
if (pong_data_length > 0) {
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(message_tree, hf_pong_data, message_tvb, PONG_DATA_OFFSET, pong_data_length, ENC_NA);
|
2006-06-09 21:41:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_pingpongprotocol_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *pingpongprotocol_tree)
|
|
|
|
{
|
|
|
|
guint8 type;
|
|
|
|
|
|
|
|
type = tvb_get_guint8(message_tvb, MESSAGE_TYPE_OFFSET);
|
2011-11-12 20:17:43 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO)) {
|
2006-06-09 21:41:02 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str(type, message_type_values, "Unknown PingPongProtocol type"));
|
|
|
|
}
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(pingpongprotocol_tree, hf_message_type, message_tvb, MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_LENGTH, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(pingpongprotocol_tree, hf_message_flags, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(pingpongprotocol_tree, hf_message_length, message_tvb, MESSAGE_LENGTH_OFFSET, MESSAGE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
|
2006-06-09 21:41:02 +00:00
|
|
|
switch (type) {
|
|
|
|
case PINGPONG_PING_MESSAGE_TYPE:
|
|
|
|
dissect_pingpongprotocol_ping_message(message_tvb, pingpongprotocol_tree);
|
|
|
|
break;
|
|
|
|
case PINGPONG_PONG_MESSAGE_TYPE:
|
|
|
|
dissect_pingpongprotocol_pong_message(message_tvb, pingpongprotocol_tree);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_pingpongprotocol(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_item *pingpongprotocol_item;
|
|
|
|
proto_tree *pingpongprotocol_tree;
|
|
|
|
|
2011-11-12 20:17:43 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PingPongProtocol");
|
2006-06-09 21:41:02 +00:00
|
|
|
|
|
|
|
/* In the interest of speed, if "tree" is NULL, don't do any work not
|
|
|
|
necessary to generate protocol tree items. */
|
|
|
|
if (tree) {
|
|
|
|
/* create the pingpongprotocol protocol tree */
|
2011-10-21 02:10:19 +00:00
|
|
|
pingpongprotocol_item = proto_tree_add_item(tree, proto_pingpongprotocol, message_tvb, 0, -1, ENC_NA);
|
2006-06-09 21:41:02 +00:00
|
|
|
pingpongprotocol_tree = proto_item_add_subtree(pingpongprotocol_item, ett_pingpongprotocol);
|
|
|
|
} else {
|
|
|
|
pingpongprotocol_tree = NULL;
|
|
|
|
};
|
|
|
|
/* dissect the message */
|
|
|
|
dissect_pingpongprotocol_message(message_tvb, pinfo, pingpongprotocol_tree);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the protocol with Wireshark */
|
|
|
|
void
|
|
|
|
proto_register_pingpongprotocol(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Setup list of header fields */
|
|
|
|
static hf_register_info hf[] = {
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
{ &hf_message_type, { "Type", "pingpongprotocol.message_type", FT_UINT8, BASE_DEC, VALS(message_type_values), 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_message_flags, { "Flags", "pingpongprotocol.message_flags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_message_length, { "Length", "pingpongprotocol.message_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_ping_messageno, { "MessageNo", "pingpongprotocol.ping_messageno", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_ping_data, { "Ping_Data", "pingpongprotocol.ping_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_pong_messageno, { "MessageNo", "pingpongprotocol.pong_messageno", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_pong_replyno, { "ReplyNo", "pingpongprotocol.pong_replyno", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
|
|
|
|
{ &hf_pong_data, { "Pong_Data", "pingpongprotocol.pong_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
|
2006-06-09 21:41:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_pingpongprotocol
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_pingpongprotocol = proto_register_protocol("Ping Pong Protocol", "PingPongProtocol", "pingpongprotocol");
|
|
|
|
|
|
|
|
/* Required function calls to register the header fields and subtrees used */
|
|
|
|
proto_register_field_array(proto_pingpongprotocol, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_pingpongprotocol(void)
|
|
|
|
{
|
|
|
|
dissector_handle_t pingpongprotocol_handle;
|
|
|
|
|
|
|
|
pingpongprotocol_handle = new_create_dissector_handle(dissect_pingpongprotocol, proto_pingpongprotocol);
|
2011-02-10 12:54:20 +00:00
|
|
|
dissector_add_uint("sctp.ppi", PINGPONGPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY, pingpongprotocol_handle);
|
|
|
|
dissector_add_uint("sctp.ppi", PPP_PAYLOAD_PROTOCOL_ID, pingpongprotocol_handle);
|
2006-06-09 21:41:02 +00:00
|
|
|
}
|