Wireshark-bugs: [Wireshark-bugs] [Bug 5753] New dissector for the openSAFETY protocol

Date: Sun, 20 Mar 2011 11:19:26 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5753

--- Comment #7 from Guy Harris <guy@xxxxxxxxxxxx> 2011-03-20 11:19:24 PDT ---
The preferred solution is that proto_reg_handoff_opensafety() look like


void
proto_reg_handoff_opensafety(void)
{
    static int opensafety_inited = FALSE;

    if ( !opensafety_inited )
    {
        /* Default UDP only based dissector */
        dissector_add_uint("udp.port", UDP_PORT_OPENSAFETY,
find_dissector("opensafety"));

        /* Sercos III dissector does not handle UDP transport, has to be
handled
         *  separately, everything else should be caught by the heuristic
dissector
         */
        dissector_add_uint("udp.port", UDP_PORT_SIII,
find_dissector("opensafety_siii"));

        heur_dissector_add("epl", dissect_heur_opensafety_epl,
proto_opensafety);

        /* For SercosIII we have to register as a heuristic dissector, as
SercosIII
         *  is implemented as a plugin, and therefore the heuristic dissector
is not
         *  added by the time this method is being called
         */
        heur_dissector_add("sercosiii", dissect_heur_opensafety_siii,
proto_opensafety);
    }
}

and that dissect_heur_opensafety_siii() look like

static gboolean
dissect_heur_opensafety_siii(tvbuff_t *message_tvb _U_, packet_info *pinfo _U_,
proto_tree *tree _U_)
{
    guint32 constData;
    guint8 firstByte;

    /* We have a SERCOS III package */
    firstByte = ( tvb_get_guint8(message_tvb, 0) << 1 );
    /* No frames can be sent in AT messages, therefore those get filtered right
away */
    if ( ( (!firstByte) & 0x40 ) == 0x40 )
        return FALSE;

    constData = 0x0;
    if ( pinfo->private_data != NULL )
        memcpy(&constData, pinfo->private_data, sizeof(guint32));

    if ( pinfo->private_data == NULL || ( constData !=
OPENSAFETY_PINFO_CONST_DATA ) )
    {
        constData = OPENSAFETY_PINFO_CONST_DATA;
        pinfo->private_data = (void*)g_malloc(sizeof(guint32));
        memcpy(pinfo->private_data, &constData, sizeof(guint32));
        return dissect_opensafety_siii(message_tvb, pinfo, tree);
    }

    return FALSE;
}

as that will work (and *does* work for me).

-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.