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

How to parse clientbound and serverbound packets differently?

asked Aug 14 '25

I'm dealing with a UDP format that has mildly different formats between the client-to-server protocol and the server-to-client protocol. How do I handle this in a way where I can parse these packets in different ways? Do I have to register 2 different dissectors?

1 Answer

0

answered Aug 14 '25

Can you determine direction programmatically?

One way of doing that is comparing the source and destination port numbers.
Search code for string port >.

epan/dissectors/packet-udp.c:

    /* check direction and get ua lists */
    direction = cmp_address(&pinfo->src, &pinfo->dst);
    /* if the addresses are equal, match the ports instead */
    if (direction == 0) {
        direction = (pinfo->srcport > pinfo->destport) ? 1 : -1;
    }


epan/dissectors/packet-tpm20.c:

    if (pinfo->srcport > pinfo->destport) {
        col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, " [TPM Request]");
        if (length >= TPM_COMMAND_HEADER_LEN)
            dissect_tpm20_tpm_command(tvb, pinfo, tpm_tree);
        else
            dissect_tpm20_platform_command(tvb, pinfo, tpm_tree);

    } else {
        col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, " [TPM Response]");
        if (length >= TPM_COMMAND_HEADER_LEN)
            dissect_tpm20_tpm_response(tvb, pinfo, tpm_tree);
        else
            dissect_tpm20_platform_response(tvb, pinfo, tpm_tree);
    }

Comments

Pinfo->dir might be of use.

User 9023 ( Aug 17 '25 )
cc-by-sa Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.