This is a static, read-only archive of Wireshark Q&A. Older questions and answers from October 2017 and earlier can be found at osqa-ask.wireshark.org.
0

Modbus UDP versus TCP

asked Jan 30 '26

updated Feb 04 '26

When using Wireshark to capture Modbus TCP packets, it will detect and display if one TCP packet contains more than one query. This is correct according to the Modbus TCP specification, where the transaction ID in the header is used to identify each query.

But when using UDP instead of TCP, then Wireshark does not show if there are more than one Query in the packet. In the packet data, I can see that there are several queries, but Wireshark does not display this, as it does for the Modbus TCP.

Is this something that can be fixed in Wireshark?

Here is a link to a wireshark log file, using modbus UDP.

IPm8460_to_IPm6350_RapidFire_Modbus_UDP.pcapng

Here is a link to a wireshark log file, using modbus TCP

IPm8460_to_IPm6350_RapidFire_Modbus_TCP.pcapng

Here is a link to the part of the modbus TCP implementation guide, with rule nr. 4 describing how this works.

Modbus Rapidfire.jpg

Comments

Can you provide a sample capture with multiple queries in a UDP frame?
Any links to a standard or RFC that support this?

epan/dissectors/packet-mbtcp.c:

dissect_mbudp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    if (!is_mbtcp(tvb, pinfo))
        return 0;

    /* Make entries in Protocol column on summary display */
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "Modbus/UDP");
    col_clear(pinfo->cinfo, COL_INFO);

    return dissect_mbtcp_pdu_common(tvb, pinfo, tree, proto_mbudp, global_mbus_udp_ports);
}

Looks like the code just does the first PDU for UDP.

User 2763 ( Jan 30 '26 )

I tried to copy capture file in here, but looks like I need more points to do that. I can copy the bytes from the message here, if that helps.

The format follows the Modbus Messaging on TCP/IP Implementation Guide V1.0b from october 2006, chapter 4.2.1.1, and rule number 4. It uses the transaction identifier to relate queries and responses.

Here is the hex dump of the bytes from the UDP request containing the 4 queries in one UDP telegram. The transaction identifiers are 0,1,2 and 3, to identify each query. I have marked each transaction identifier in bold.

0000 00 a0 1d 2c b7 98 00 a0 1d 13 b0 1f 08 00 45 00 0010 00 4c b8 50 40 00 40 11 f6 f4 c0 a8 85 09 c0 a8 0020 85 01 da ce 01 f6 00 38 91 a5 00 00 00 00 00 06 0030 01 03 00 00 00 64 00 01 00 00 00 06 01 02 00 00 0040 00 64 00 02 00 00 00 06 01 01 00 00 00 64 00 03 0050 00 00 00 06 01 04 00 00 00 64

The response hex dump is also packed into one UDP telegram as follows, and I have marked the related transaction identifiers in bold also here.

0000 00 a0 1d 13 b0 1f 00 a0 1d 2c b7 98 08 00 45 00 0010 01 ea 00 00 40 00 40 11 ad a7 c0 a8 85 01 c0 a8 0020 85 09 01 f6 da ce 01 d6 d1 6c 00 00 00 00 00 cb 0030 01 03 c8 00 00 00 00 00 00 00 00 00 00 00 00 00 0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00f0 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 0100 10 01 02 0d 00 00 00 00 00 00 00 00 00 00 00 00 0110 00 00 02 00 00 00 10 01 01 0d 00 00 00 00 00 00 0120 00 00 00 00 00 00 00 00 03 00 00 00 cb 01 04 c8 0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01a0 00 00

User 14171 ( Feb 02 '26 )

(The comment above had reached max comment size so reposting as two comments)

I tried to copy capture file in here, but looks like I need more points to do that. I can copy the bytes from the message here, if that helps.

The format follows the Modbus Messaging on TCP/IP Implementation Guide V1.0b from october 2006, chapter 4.2.1.1, and rule number 4. It uses the transaction identifier to relate queries and responses.

Here is the hex dump of the bytes from the UDP request containing the 4 queries in one UDP telegram. The transaction identifiers are 0,1,2 and 3, to identify each query. I have marked each transaction identifier in bold.

0000   00 a0 1d 2c b7 98 00 a0 1d 13 b0 1f 08 00 45 00
0010   00 4c b8 50 40 00 40 11 f6 f4 c0 a8 85 09 c0 a8
0020   85 01 da ce 01 f6 00 38 91 a5 **00 00** 00 00 00 06
0030   01 03 00 00 00 64 **00 01** 00 00 00 06 01 02 00 00
0040   00 64 **00 02** 00 00 00 06 01 01 00 00 00 64 **00 03**
0050   00 00 00 06 01 04 00 00 00 64
User 2763 ( Feb 02 '26 )

(Repost second section. This hex dump may be truncated due to max comment size above?)

The response hex dump is also packed into one UDP telegram as follows, and I have marked the related transaction identifiers in bold also here.

0000   00 a0 1d 13 b0 1f 00 a0 1d 2c b7 98 08 00 45 00
0010   01 ea 00 00 40 00 40 11 ad a7 c0 a8 85 01 c0 a8
0020   85 09 01 f6 da ce 01 d6 d1 6c **00 00** 00 00 00 cb
0030   01 03 c8 00 00 00 00 00 00 00 00 00 00 00 00 00
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0050   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0060   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0070   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0080   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0090   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00a0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00b0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00c0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00d0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00e0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00f0   00 00 00 00 00 00 00 00 00 00 00 **00 01** 00 00 00
0100   10 01 02 0d 00 00 00 00 00 00 00 00 00 00 00 00
0110   00 **00 02** 00 00 00 10 01 01 0d 00 00 00 00 00 00
0120   00 00 00 00 00 00 00 **00 03** 00 00 00 cb 01 04 c8
0130   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0140   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0150   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0160   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0170   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0180   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0190   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01a0   00 00
User 2763 ( Feb 02 '26 )

I tried to copy capture file in here, but looks like I need more points to do that.


The capture file can be placed on a public file share then the question updated with a link to it.

User 2763 ( Feb 02 '26 )

I did put the files on github, and updated the question with links. Hope they are accessible now.

User 14171 ( Feb 02 '26 )

1 Answer

0

answered Feb 04 '26

updated Feb 04 '26

There doesn't seem to be a protocol spec for Modbus UDP on the Modbus site:
Specifications and Implementation Guides

Modbus Technical Resources - other sites lists several libraries that have implemented Modbus UDP. They are all different languages and it hasn't been verified if they all agree on what the UDP data should look like.

Thank you for providing the sample captures.
At this point it's worth opening a Wireshark enhancement request to add this to the Modbus UDP dissector.
It is a bit more than I want to tackle and also not sure about corner cases like trailer bytes after the Modus data or if the data is large and is split into IP fragments.

Enhancement requests are added as a Feature Request in the Wireshark Issues on GitLab.

Until it can be added properly, here is a lua script to decode UDP data containing multiple ADUs.
No warranty - Caveat emptor - but seems to work with the sample UDP capture provided.

-- Modbus_ADUs.lua
-- https://ask.wireshark.org/question/37817/modbus-udp-versus-tcp/
-- 

-- Step 1 - document as you go. See header above and set_plugin_info().
local modbus_adus_info =
{
    version = "1.0.0",
    author = "Good Coder",
    description = "Modbus UDP - multiple ADUs",
    repository = "Floppy in top drawer"
}

set_plugin_info(modbus_adus_info)

-- grab the original dissector to call from our loop below
local mbudp_dissector = Dissector.get("mbudp")

-- Step 2 - create a protocol to attach new fields to
local modbus_adus_p = Proto.new("modbus_adus","Modbus/UDP/ADUs")

-- Steps 3 and 4 deleted for readability
-- See https://wiki.wireshark.org/lua/ for original EASYPOST.lua with all steps

-- Step 5 - create the dissector function that will run on each frame/packet
function modbus_adus_p.dissector(tvb,pinfo,tree)
    local subtree = nil
    local tvb_len =tvb:captured_len()
    local offset = 0

    if not subtree then
        subtree = tree:add(modbus_adus_p)
    end

    while offset < tvb_len do
        new_tvb = tvb:range(offset):tvb()
        mbudp_len = new_tvb:range(4,2):int() + 6
        mbudp_dissector:call(new_tvb, pinfo, tree)
        offset = offset + mbudp_len
    end
end

-- Step 6 - replace original mbudp dissector with modbus_adus dissector
local udp_port_table = DissectorTable.get("udp.port")
udp_port_table:set(502, modbus_adus_p)


Frame 2: Packet, 504 bytes on wire (4032 bits), 504 bytes captured (4032 bits) on interface xxx
Ethernet II, Src: xxx, Dst: xxx
Internet Protocol Version 4, Src: xxx (xxx), Dst: xxx (xxx)
User Datagram Protocol, Src Port: 502, Dst Port: 56014
Modbus/UDP/ADUs
Modbus/UDP
Modbus
Modbus/UDP
Modbus
Modbus/UDP
Modbus
Modbus/UDP
Modbus

cc-by-sa Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.