*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
* 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 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.
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * -- Based on the function code in the header, and the fact that the packet is
- * either a query or a response, the different fields in the payload can be
+ * -- Based on the function code in the header, and the fact that the packet is
+ * either a query or a response, the different fields in the payload can be
/* Initialize the subtree pointers */
static gint ett_mbtcp = -1;
static gint ett_modbus_hdr = -1;
/* Initialize the subtree pointers */
static gint ett_mbtcp = -1;
static gint ett_modbus_hdr = -1;
if ( ( 502 == pinfo->srcport && 502 != pinfo->destport ) ||
( 502 != pinfo->srcport && 502 == pinfo->destport ) ) {
/* the slave is receiving queries on port 502 */
if ( ( 502 == pinfo->srcport && 502 != pinfo->destport ) ||
( 502 != pinfo->srcport && 502 == pinfo->destport ) ) {
/* the slave is receiving queries on port 502 */
* "Open Modbus/TCP Specification", release 1 by Andy Swales. */
static char *
function_string(guint16 func_code)
* "Open Modbus/TCP Specification", release 1 by Andy Swales. */
static char *
function_string(guint16 func_code)
* packets in one TCP packet */
guint8 exception_code = 0, exception_returned = 0;
* packets in one TCP packet */
guint8 exception_code = 0, exception_returned = 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Modbus/TCP");
if (check_col(pinfo->cinfo, COL_INFO))
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Modbus/TCP");
if (check_col(pinfo->cinfo, COL_INFO))
/* Make entries in Info column on summary display (updated after building proto tree) */
tvb_memcpy(tvb, (guint8 *)&mh, offset, sizeof(mbtcp_hdr));
/* Make entries in Info column on summary display (updated after building proto tree) */
tvb_memcpy(tvb, (guint8 *)&mh, offset, sizeof(mbtcp_hdr));
- mh.transaction_id = ntohs(mh.transaction_id);
- mh.protocol_id = ntohs(mh.protocol_id);
- mh.len = ntohs(mh.len);
+ mh.transaction_id = g_ntohs(mh.transaction_id);
+ mh.protocol_id = g_ntohs(mh.protocol_id);
+ mh.len = g_ntohs(mh.len);
break;
case cannot_classify : strcpy(err_str, "Unable to classify as query or response.");
strcpy(pkt_type_str, "unknown");
break;
case cannot_classify : strcpy(err_str, "Unable to classify as query or response.");
strcpy(pkt_type_str, "unknown");
}
if ( exception_returned )
strcpy(err_str, "Exception returned ");
}
if ( exception_returned )
strcpy(err_str, "Exception returned ");
- col_add_fstr(pinfo->cinfo, COL_INFO,
- "%8s [%2u pkt(s)]: trans: %5u; unit: %3u, func: %3u: %s. %s",
- pkt_type_str, 1, mh.transaction_id, (unsigned char) mh.mdbs_hdr.unit_id,
+ col_add_fstr(pinfo->cinfo, COL_INFO,
+ "%8s [%2u pkt(s)]: trans: %5u; unit: %3u, func: %3u: %s. %s",
+ pkt_type_str, 1, mh.transaction_id, (unsigned char) mh.mdbs_hdr.unit_id,
/* build up protocol tree */
do {
/* Avoids alignment problems on many architectures. */
tvb_memcpy(tvb, (guint8 *)&mh, offset, sizeof(mbtcp_hdr));
/* build up protocol tree */
do {
/* Avoids alignment problems on many architectures. */
tvb_memcpy(tvb, (guint8 *)&mh, offset, sizeof(mbtcp_hdr));
- mh.transaction_id = ntohs(mh.transaction_id);
- mh.protocol_id = ntohs(mh.protocol_id);
- mh.len = ntohs(mh.len);
-
+ mh.transaction_id = g_ntohs(mh.transaction_id);
+ mh.protocol_id = g_ntohs(mh.protocol_id);
+ mh.len = g_ntohs(mh.len);
+
if ( mh.mdbs_hdr.function_code & 0x80 ) {
tvb_memcpy(tvb, (guint8 *)&exception_code, offset + sizeof(mbtcp_hdr), 1);
mh.mdbs_hdr.function_code ^= 0x80;
exception_returned = 1;
if ( mh.mdbs_hdr.function_code & 0x80 ) {
tvb_memcpy(tvb, (guint8 *)&exception_code, offset + sizeof(mbtcp_hdr), 1);
mh.mdbs_hdr.function_code ^= 0x80;
exception_returned = 1;
/* if a tree exists, perform operations to add fields to it */
if (tree) {
packet_len = sizeof(mbtcp_hdr) - sizeof(modbus_hdr) + mh.len;
/* if a tree exists, perform operations to add fields to it */
if (tree) {
packet_len = sizeof(mbtcp_hdr) - sizeof(modbus_hdr) + mh.len;
- mi = proto_tree_add_protocol_format(tree, proto_mbtcp, tvb, offset,
+ mi = proto_tree_add_protocol_format(tree, proto_mbtcp, tvb, offset,
packet_len, "Modbus/TCP");
mbtcp_tree = proto_item_add_subtree(mi, ett_mbtcp);
packet_len, "Modbus/TCP");
mbtcp_tree = proto_item_add_subtree(mi, ett_mbtcp);
- proto_tree_add_uint(mbtcp_tree, hf_mbtcp_transid, tvb, offset, 2,
+ proto_tree_add_uint(mbtcp_tree, hf_mbtcp_transid, tvb, offset, 2,
- proto_tree_add_uint(mbtcp_tree, hf_mbtcp_protid, tvb, offset + 2, 2,
+ proto_tree_add_uint(mbtcp_tree, hf_mbtcp_protid, tvb, offset + 2, 2,
- proto_tree_add_uint(mbtcp_tree, hf_mbtcp_len, tvb, offset + 4, 2,
+ proto_tree_add_uint(mbtcp_tree, hf_mbtcp_len, tvb, offset + 4, 2,
- mf = proto_tree_add_text(mbtcp_tree, tvb, offset + 6, packet_end,
+ mf = proto_tree_add_text(mbtcp_tree, tvb, offset + 6, packet_end,
- modbus_tree = proto_item_add_subtree(mf, ett_modbus_hdr);
- proto_tree_add_item(modbus_tree, hf_mbtcp_unitid, tvb, offset + 6, 1,
+ modbus_tree = proto_item_add_subtree(mf, ett_modbus_hdr);
+ proto_tree_add_item(modbus_tree, hf_mbtcp_unitid, tvb, offset + 6, 1,
- mi = proto_tree_add_item(modbus_tree, hf_mbtcp_functioncode, tvb, offset + 7, 1,
+ mi = proto_tree_add_item(modbus_tree, hf_mbtcp_functioncode, tvb, offset + 7, 1,
- if ( 0 == exception_code )
- proto_item_set_text(mi, "function %u: %s", mh.mdbs_hdr.function_code,
+ if ( 0 == exception_code )
+ proto_item_set_text(mi, "function %u: %s", mh.mdbs_hdr.function_code,
- else
- proto_item_set_text(mi, "function %u: %s. Exception: %s",
- mh.mdbs_hdr.function_code, func_string, exception_string(exception_code));
-
+ else
+ proto_item_set_text(mi, "function %u: %s. Exception: %s",
+ mh.mdbs_hdr.function_code, func_string, exception_string(exception_code));
+
- proto_tree_add_text(modbus_tree, tvb, offset + 8, packet_end,
+ proto_tree_add_text(modbus_tree, tvb, offset + 8, packet_end,
"Modbus data");
}
offset = offset + sizeof(mbtcp_hdr) + (mh.len - sizeof(modbus_hdr));
packet_num++;
} while ( tvb_reported_length_remaining(tvb, offset) > 0 );
"Modbus data");
}
offset = offset + sizeof(mbtcp_hdr) + (mh.len - sizeof(modbus_hdr));
packet_num++;
} while ( tvb_reported_length_remaining(tvb, offset) > 0 );
/* Update entries in Info column on summary display */
if (check_col(pinfo->cinfo, COL_INFO))
{
switch ( packet_type ) {
/* Update entries in Info column on summary display */
if (check_col(pinfo->cinfo, COL_INFO))
{
switch ( packet_type ) {
break;
case cannot_classify : strcpy(err_str, "Unable to classify as query or response.");
strcpy(pkt_type_str, "unknown");
break;
case cannot_classify : strcpy(err_str, "Unable to classify as query or response.");
strcpy(pkt_type_str, "unknown");
}
if ( exception_returned )
strcpy(err_str, "Exception returned ");
}
if ( exception_returned )
strcpy(err_str, "Exception returned ");
- col_add_fstr(pinfo->cinfo, COL_INFO,
- "%8s [%2u pkt(s)]: trans: %5u; unit: %3u, func: %3u: %s. %s",
- pkt_type_str, packet_num, mh.transaction_id, (unsigned char) mh.mdbs_hdr.unit_id,
- (unsigned char) mh.mdbs_hdr.function_code, func_string, err_str);
+ col_add_fstr(pinfo->cinfo, COL_INFO,
+ "%8s [%2u pkt(s)]: trans: %5u; unit: %3u, func: %3u: %s. %s",
+ pkt_type_str, packet_num, mh.transaction_id, (unsigned char) mh.mdbs_hdr.unit_id,
+ (unsigned char) mh.mdbs_hdr.function_code, func_string, err_str);
/* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = {
/* Modbus/TCP header fields */
{ &hf_mbtcp_transid,
{ "transaction identifier", "modbus_tcp.trans_id",
/* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = {
/* Modbus/TCP header fields */
{ &hf_mbtcp_transid,
{ "transaction identifier", "modbus_tcp.trans_id",
- FT_UINT16, BASE_DEC, NULL, 0x0,
+ FT_UINT16, BASE_DEC, NULL, 0x0,
- FT_UINT16, BASE_DEC, NULL, 0x0,
+ FT_UINT16, BASE_DEC, NULL, 0x0,
- FT_UINT16, BASE_DEC, NULL, 0x0,
+ FT_UINT16, BASE_DEC, NULL, 0x0,
"", HFILL }
},
/* Modbus header fields */
{ &hf_mbtcp_unitid,
{ "unit identifier", "modbus_tcp.unit_id",
"", HFILL }
},
/* Modbus header fields */
{ &hf_mbtcp_unitid,
{ "unit identifier", "modbus_tcp.unit_id",
- FT_UINT8, BASE_DEC, NULL, 0x0,
+ FT_UINT8, BASE_DEC, NULL, 0x0,
"", HFILL }
},
{ &hf_mbtcp_functioncode,
{ "function code ", "modbus_tcp.func_code",
"", HFILL }
},
{ &hf_mbtcp_functioncode,
{ "function code ", "modbus_tcp.func_code",
- FT_UINT8, BASE_DEC, NULL, 0x0,
+ FT_UINT8, BASE_DEC, NULL, 0x0,