Wireshark-dev: Re: [Wireshark-dev] Dissect using val_to_str from external file

From: Graham Bloice <graham.bloice@xxxxxxxxxxxxx>
Date: Wed, 11 Nov 2015 14:40:47 +0000


On 11 November 2015 at 13:38, Jo <wireshark@xxxxxxxxxxx> wrote:
Hello,

I did this now for the functions in my other question
(http://seclists.org/wireshark/2015/Nov/78) but I have no idea how to
get this working for val_to_str() in my plugin file.

In my source file, i include <epan/ipproto.h> and Visual Studio does
only complain at compile time about unresolved external symbols
(LNK2001). Can someone please help me on how to access ipproto_val_ext
from a plugin?

No plugin from the Wireshark sources seem to use external val_to_str()
calls as of now.



I just tested with a quick hack to the plugin packet-wimaxasncp that compiled and linked without errors:

diff --git a/epan/ipproto.h b/epan/ipproto.h
index 3477507..ba15f93 100644
--- a/epan/ipproto.h
+++ b/epan/ipproto.h
@@ -191,7 +191,7 @@
 #define IP_PROTO_AX4000         173     /* AX/4000 Testblock - non IANA */
 #define IP_PROTO_NCS_HEARTBEAT  224     /* Novell NCS Heartbeat - http://support.novell.com/cgi-bin/search/searchtid.cgi?/10071158.htm */

-extern value_string_ext ipproto_val_ext;
+WS_DLL_PUBLIC value_string_ext ipproto_val_ext;
 WS_DLL_PUBLIC const char *ipprotostr(const int proto);

 #endif /* ipproto.h */
diff --git a/plugins/wimaxasncp/packet-wimaxasncp.c b/plugins/wimaxasncp/packet-wimaxasncp.c
index 64c5cb3..08dffbf 100644
--- a/plugins/wimaxasncp/packet-wimaxasncp.c
+++ b/plugins/wimaxasncp/packet-wimaxasncp.c
@@ -1328,10 +1328,13 @@ static void wimaxasncp_dissect_tlv_value(
             {
                 guint16      protocol;
                 const gchar *protocol_name;
+                const char *s;

                 protocol = tvb_get_ntohs(tvb, offset);
                 protocol_name = ipprotostr(protocol);

+               s = try_val_to_str_ext(protocol, &ipproto_val_ext);
+
                 proto_tree_add_uint_format(
                     protocol_list_tree, tlv_info->hf_protocol,
                     tvb, offset, 2, protocol,

This was on the master branch, building with VS2013 using CMake.

As you can see, I added the WS_DLL_PUBLIC def to ipproto_val_ext, and then used that in the plugin.

--
Graham Bloice