diff options
author | Guy Harris <guy@alum.mit.edu> | 2011-07-09 19:58:19 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2011-07-09 19:58:19 +0000 |
commit | 9988c54700a96245b017d24559531e1b9a675095 (patch) | |
tree | e76f8815d636ca6c5c1fc5ef9fed1af227c204f1 | |
parent | a53bf09cc1ab8c93f51d3969c0bf4e7430a3e86e (diff) |
Put Modbus/UDP support back.
svn path=/trunk/; revision=37947
-rw-r--r-- | epan/dissectors/packet-mbtcp.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/epan/dissectors/packet-mbtcp.c b/epan/dissectors/packet-mbtcp.c index b27c58ae44..283a07dad1 100644 --- a/epan/dissectors/packet-mbtcp.c +++ b/epan/dissectors/packet-mbtcp.c @@ -394,6 +394,29 @@ dissect_mbtcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) return tvb_length(tvb); } +static int +dissect_mbudp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + /* Make sure there's at least enough data to determine its a Modbus packet */ + if (!tvb_bytes_exist(tvb, 0, 8)) + return 0; + + /* check that it actually looks like Modbus/UDP */ + /* protocol id == 0 */ + if(tvb_get_ntohs(tvb, 2) != 0 ){ + return 0; + } + /* length is at least 2 (unit_id + function_code) */ + if(tvb_get_ntohs(tvb, 4) < 2 ){ + return 0; + } + + /* dissect the PDU */ + dissect_mbtcp_pdu(tvb, pinfo, tree); + + return tvb_length(tvb); +} + /* Code to allow special handling of mbtcp data */ static void dissect_mbtcp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 function_code, gint payload_start, gint payload_len) @@ -1235,11 +1258,14 @@ proto_register_modbus(void) void proto_reg_handoff_mbtcp(void) { - dissector_handle_t mbtcp_handle; + dissector_handle_t mbtcp_handle, mbudp_handle; mbtcp_handle = new_create_dissector_handle(dissect_mbtcp, proto_mbtcp); dissector_add_uint("tcp.port", PORT_MBTCP, mbtcp_handle); + mbudp_handle = new_create_dissector_handle(dissect_mbudp, proto_mbtcp); + dissector_add_uint("udp.port", PORT_MBTCP, mbudp_handle); + modbus_handle = new_create_dissector_handle(dissect_modbus, proto_modbus); dissector_add_uint("mbtcp.prot_id", MODBUS_PROTOCOL_ID, modbus_handle); } |