diff options
Diffstat (limited to 'epan/dissectors/packet-tcpros.c')
-rw-r--r-- | epan/dissectors/packet-tcpros.c | 238 |
1 files changed, 119 insertions, 119 deletions
diff --git a/epan/dissectors/packet-tcpros.c b/epan/dissectors/packet-tcpros.c index d00106e0..b519b7de 100644 --- a/epan/dissectors/packet-tcpros.c +++ b/epan/dissectors/packet-tcpros.c @@ -25,51 +25,51 @@ void proto_register_tcpros(void); void proto_reg_handoff_tcpros(void); -static int proto_tcpros = -1; +static int proto_tcpros; static dissector_handle_t tcpros_handle; /** desegmentation of TCPROS over TCP */ -static gboolean tcpros_desegment = TRUE; - - -static int hf_tcpros_connection_header = -1; -static int hf_tcpros_connection_header_length = -1; -static int hf_tcpros_connection_header_content = -1; -static int hf_tcpros_connection_header_field = -1; -static int hf_tcpros_connection_header_field_length = -1; -static int hf_tcpros_connection_header_field_data = -1; -static int hf_tcpros_connection_header_field_name = -1; -static int hf_tcpros_connection_header_field_value = -1; -static int hf_tcpros_clock = -1; -static int hf_tcpros_clock_length = -1; -static int hf_tcpros_message = -1; -static int hf_tcpros_message_length = -1; -static int hf_tcpros_message_body = -1; -static int hf_tcpros_message_header = -1; -static int hf_tcpros_message_header_seq = -1; -static int hf_tcpros_message_header_stamp = -1; -static int hf_tcpros_message_header_stamp_sec = -1; -static int hf_tcpros_message_header_stamp_nsec = -1; -static int hf_tcpros_message_header_frame = -1; -static int hf_tcpros_message_header_frame_length = -1; -static int hf_tcpros_message_header_frame_value = -1; -static int hf_tcpros_message_payload = -1; - -static gint ett_tcpros = -1; +static bool tcpros_desegment = true; + + +static int hf_tcpros_connection_header; +static int hf_tcpros_connection_header_length; +static int hf_tcpros_connection_header_content; +static int hf_tcpros_connection_header_field; +static int hf_tcpros_connection_header_field_length; +static int hf_tcpros_connection_header_field_data; +static int hf_tcpros_connection_header_field_name; +static int hf_tcpros_connection_header_field_value; +static int hf_tcpros_clock; +static int hf_tcpros_clock_length; +static int hf_tcpros_message; +static int hf_tcpros_message_length; +static int hf_tcpros_message_body; +static int hf_tcpros_message_header; +static int hf_tcpros_message_header_seq; +static int hf_tcpros_message_header_stamp; +static int hf_tcpros_message_header_stamp_sec; +static int hf_tcpros_message_header_stamp_nsec; +static int hf_tcpros_message_header_frame; +static int hf_tcpros_message_header_frame_length; +static int hf_tcpros_message_header_frame_value; +static int hf_tcpros_message_payload; + +static int ett_tcpros; /** * This is the ROS connection header dissector. The general packet format is described * here: http://wiki.ros.org/ROS/TCPROS * In short, a connection header looks like such: '4-byte length + [4-byte field length + "field=value" ]*' */ -static gint -dissect_ros_connection_header_field(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, gint offset) +static int +dissect_ros_connection_header_field(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset) { proto_item *ti; proto_tree *field_tree; - guint32 fLen = 0; - gint sep, ret = 0; + uint32_t fLen = 0; + int sep, ret = 0; /** Do we have enough for a length field? (ie: 4 bytes) */ if( tvb_reported_length_remaining(tvb, offset) > SIZE_OF_LENGTH_FIELD ) { @@ -86,11 +86,11 @@ dissect_ros_connection_header_field(tvbuff_t *tvb, proto_tree *tree, packet_info ti = proto_tree_add_item(field_tree, hf_tcpros_connection_header_field_data, tvb, offset, fLen, ENC_UTF_8); /** Look for the '=' separator */ - sep = (tvb_find_guint8(tvb, offset, fLen, '=') - offset); + sep = (tvb_find_uint8(tvb, offset, fLen, '=') - offset); /** If we find a separator, then split field name and value */ if( sep > 0 ) { - const guint8* field; + const uint8_t* field; field_tree = proto_item_add_subtree(ti, ett_tcpros); proto_tree_add_item_ret_string(field_tree, hf_tcpros_connection_header_field_name, tvb, offset, sep, ENC_UTF_8|ENC_NA, pinfo->pool, &field); proto_tree_add_item(field_tree, hf_tcpros_connection_header_field_value, tvb, offset+sep+1, fLen - sep - 1, ENC_UTF_8); @@ -103,14 +103,14 @@ dissect_ros_connection_header_field(tvbuff_t *tvb, proto_tree *tree, packet_info return ret; } -static gint -dissect_ros_connection_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint offset) +static int +dissect_ros_connection_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, int offset) { proto_item *ti; proto_tree *sub_tree; - gint consumed_len = 0; - guint32 header_len = tvb_get_letohl(tvb, offset); + int consumed_len = 0; + uint32_t header_len = tvb_get_letohl(tvb, offset); col_append_str(pinfo->cinfo, COL_INFO, "[ROS Conn] Metadata: ["); @@ -126,13 +126,13 @@ dissect_ros_connection_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info header_len += SIZE_OF_LENGTH_FIELD; - while( consumed_len < (gint)header_len ) { - gint len = dissect_ros_connection_header_field(tvb, sub_tree, pinfo, offset + consumed_len); + while( consumed_len < (int)header_len ) { + int len = dissect_ros_connection_header_field(tvb, sub_tree, pinfo, offset + consumed_len); consumed_len += len; if( len == 0 ) { break; } - if( consumed_len < (gint)header_len ) { + if( consumed_len < (int)header_len ) { col_append_str(pinfo->cinfo, COL_INFO, ","); } } @@ -142,14 +142,14 @@ dissect_ros_connection_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info } -static gint -dissect_ros_message_header_stamp(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint offset) +static int +dissect_ros_message_header_stamp(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, int offset) { proto_item *ti; proto_tree *sub_tree; - gint consumed_len = 0; - guint32 sec, nsec; + int consumed_len = 0; + uint32_t sec, nsec; ti = proto_tree_add_item(root_tree, hf_tcpros_message_header_stamp, tvb, offset + consumed_len, SIZE_OF_LENGTH_STAMP, ENC_LITTLE_ENDIAN); sub_tree = proto_item_add_subtree(ti, ett_tcpros); @@ -170,13 +170,13 @@ dissect_ros_message_header_stamp(tvbuff_t *tvb, proto_tree *root_tree, packet_in return consumed_len; } -static gint -dissect_ros_clock(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint offset) +static int +dissect_ros_clock(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, int offset) { proto_item *ti; proto_tree *sub_tree; - gint consumed_len = 0; + int consumed_len = 0; col_append_str(pinfo->cinfo, COL_INFO, "[ROS Clock] "); @@ -192,17 +192,17 @@ dissect_ros_clock(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint return consumed_len; } -static gint -dissect_ros_message_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint offset) +static int +dissect_ros_message_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, int offset) { proto_item *ti; proto_tree *sub_tree; - gint consumed_len = 0; - guint32 frame_id_len; - guint32 seq; - guint header_len; - const guint8* frame_str; + int consumed_len = 0; + uint32_t frame_id_len; + uint32_t seq; + unsigned header_len; + const uint8_t* frame_str; frame_id_len = tvb_get_letohl(tvb, offset + consumed_len + SIZE_OF_LENGTH_FIELD + SIZE_OF_LENGTH_STAMP); @@ -242,15 +242,15 @@ dissect_ros_message_header(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pi * However, every packet has the same header as defined here: http://docs.ros.org/api/std_msgs/html/msg/Header.html * So, we can break this one down and display it. */ -static gint -dissect_ros_message(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint offset) +static int +dissect_ros_message(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, int offset) { proto_item *ti; proto_tree *sub_tree; - gint consumed_len = 0; - guint32 total_len = tvb_get_letohl(tvb, offset); - guint payload_len; + int consumed_len = 0; + uint32_t total_len = tvb_get_letohl(tvb, offset); + unsigned payload_len; col_append_str(pinfo->cinfo, COL_INFO, "[ROS Msg] "); @@ -281,125 +281,125 @@ dissect_ros_message(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gi /** * This is the poor man's way to differentiate between a connection header packet and a message packet. */ -static gboolean -is_connection_header(tvbuff_t *tvb, packet_info *pinfo _U_ , guint offset) +static bool +is_connection_header(tvbuff_t *tvb, packet_info *pinfo _U_ , unsigned offset) { - gboolean is_con_header = FALSE; - guint32 len1 = tvb_get_letohl(tvb, offset); - guint32 len2 = tvb_get_letohl(tvb, offset + SIZE_OF_LENGTH_FIELD); + bool is_con_header = false; + uint32_t len1 = tvb_get_letohl(tvb, offset); + uint32_t len2 = tvb_get_letohl(tvb, offset + SIZE_OF_LENGTH_FIELD); if( len1 > len2 ) { - is_con_header = TRUE; + is_con_header = true; } return is_con_header; } -static gboolean -is_rosheaderfield(tvbuff_t *tvb, packet_info *pinfo _U_ , guint offset) +static bool +is_rosheaderfield(tvbuff_t *tvb, packet_info *pinfo _U_ , unsigned offset) { /** ROS Header Field: 4-byte len + string */ - gint available = tvb_reported_length_remaining(tvb, offset); - guint32 string_len = 0; - guint32 i; + int available = tvb_reported_length_remaining(tvb, offset); + uint32_t string_len = 0; + uint32_t i; if( available < 4 ) - return FALSE; + return false; string_len = tvb_get_letohl(tvb, offset); /** If we don't have enough data for the whole string, assume its not */ - if( (guint)available < (string_len + 4) ) - return FALSE; + if( (unsigned)available < (string_len + 4) ) + return false; /** Check for a valid ascii character and not nil */ for( i = 0; i < string_len; i++ ) { - gint8 ch = tvb_get_guint8(tvb, offset + 4 + i); + int8_t ch = tvb_get_uint8(tvb, offset + 4 + i); if( !g_ascii_isalnum(ch) || 0x00 == ch ) - return FALSE; + return false; } /** Assume it is */ - return TRUE; + return true; } -static gboolean -is_rosconnection_header(tvbuff_t *tvb, packet_info *pinfo _U_ , guint offset) +static bool +is_rosconnection_header(tvbuff_t *tvb, packet_info *pinfo _U_ , unsigned offset) { /** ROS Connection Headers: http://wiki.ros.org/ROS/Connection%20Header 4-byte length + [4-byte length + string] */ - gint available = tvb_reported_length_remaining(tvb, offset); - guint32 msg_len = 0; + int available = tvb_reported_length_remaining(tvb, offset); + uint32_t msg_len = 0; if( available < 8+1 ) - return FALSE; + return false; msg_len = tvb_get_letohl(tvb, offset); if( msg_len < 4+1 ) - return FALSE; + return false; /** Check first header field */ if( !is_rosheaderfield(tvb, pinfo, offset + 4) ) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean -is_rosclock(tvbuff_t *tvb, packet_info *pinfo _U_ , guint offset) +static bool +is_rosclock(tvbuff_t *tvb, packet_info *pinfo _U_ , unsigned offset) { /** ROS Clock message: http://docs.ros.org/api/rosgraph_msgs/html/msg/Clock.html 4-byte length + 8-byte timestamp == 12 bytes exactly */ - gint available = tvb_reported_length_remaining(tvb, offset); + int available = tvb_reported_length_remaining(tvb, offset); if( available != 12 ) - return FALSE; + return false; if( tvb_get_letohl(tvb, offset) != 8 ) - return FALSE; + return false; /** This is highly likely a clock message. */ - return TRUE; + return true; } -static gboolean -is_rosmsg(tvbuff_t *tvb, packet_info *pinfo _U_ , guint offset) +static bool +is_rosmsg(tvbuff_t *tvb, packet_info *pinfo _U_ , unsigned offset) { /** Most ROS messages start with a header: http://docs.ros.org/jade/api/std_msgs/html/msg/Header.html 4-byte size + 4-byte sequence id + 8-byte timestamp + 4-byte frame id length + frame id */ - gint available = tvb_reported_length_remaining(tvb, offset); - guint32 string_len = 0; - guint32 msg_len = 0; + int available = tvb_reported_length_remaining(tvb, offset); + uint32_t string_len = 0; + uint32_t msg_len = 0; if( available < 20 ) - return FALSE; + return false; msg_len = tvb_get_letohl(tvb, offset); if( msg_len < 16 ) - return FALSE; + return false; /** Check to see if the frame id length is reasonable */ string_len = tvb_get_letohl(tvb, offset + 4 + 4 + 8); if( string_len > (msg_len - (4 + 8 + 4)) ) - return FALSE; + return false; /** If we don't have enough data for the whole string, assume its not */ - if( (guint)available < (string_len + 4) ) - return FALSE; + if( (unsigned)available < (string_len + 4) ) + return false; /** This is highly likely a ROS message. */ - return TRUE; + return true; } static void -dissect_ros_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean is_tcp _U_ ) +dissect_ros_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bool is_tcp _U_ ) { proto_item *ti; proto_tree *root_tree; - guint offset; + unsigned offset; /** Clear out stuff in the info column */ @@ -411,9 +411,9 @@ dissect_ros_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean offset = 0; while(offset < tvb_reported_length(tvb)) { - gint available = tvb_reported_length_remaining(tvb, offset); + int available = tvb_reported_length_remaining(tvb, offset); - if( (available < SIZE_OF_LENGTH_FIELD) || ((guint)available < tvb_get_letohl(tvb, offset)) ) { + if( (available < SIZE_OF_LENGTH_FIELD) || ((unsigned)available < tvb_get_letohl(tvb, offset)) ) { /** we ran out of data: ask for more */ pinfo->desegment_offset = offset; pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT; @@ -441,10 +441,10 @@ dissect_ros_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean } -static guint +static unsigned get_tcpros_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_) { - guint32 plen; + uint32_t plen; /* * Get the length of the TCPROS packet. @@ -463,7 +463,7 @@ dissect_tcpros_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* da { col_set_str(pinfo->cinfo, COL_PROTOCOL, "TCPROS"); - dissect_ros_common(tvb, pinfo, tree, TRUE); + dissect_ros_common(tvb, pinfo, tree, true); return tvb_reported_length(tvb); } @@ -555,7 +555,7 @@ proto_register_tcpros(void) }; - static gint *ett[] = { + static int *ett[] = { &ett_tcpros, }; @@ -580,36 +580,36 @@ proto_register_tcpros(void) } /* Heuristics test */ -static gboolean +static bool test_tcpros(packet_info *pinfo, tvbuff_t *tvb, int offset, void *data _U_) { if (tvb_captured_length(tvb) < 8) - return FALSE; + return false; if( is_rosclock(tvb, pinfo, offset) ) - return TRUE; + return true; if( is_rosmsg(tvb, pinfo, offset) ) - return TRUE; + return true; if( is_rosconnection_header(tvb, pinfo, offset) ) - return TRUE; + return true; - return FALSE; + return false; } -static gboolean +static bool dissect_tcpros_heur_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { conversation_t *conversation; if (!test_tcpros(pinfo, tvb, 0, data)) - return FALSE; + return false; conversation = find_or_create_conversation(pinfo); conversation_set_dissector(conversation, tcpros_handle); dissect_tcpros(tvb, pinfo, tree, data); - return (TRUE); + return true; } |