Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Why isn't libwireshark.def autogenerated?

From: Gregory Seidman <gsslist+wireshark@xxxxxxxxxxxxxxxxxx>
Date: Sat, 18 Dec 2010 13:28:38 -0500
On Sat, Dec 18, 2010 at 10:57:29AM +0100, Andreas wrote:
[...]
> The problem I see is that Wireshark doesn't have "The API". It is not 
> obvious which header files, and which declaration are public. When you 
> look at the libwireshark.def it seems that definitions have been added 
> or removed just as the needs appeared.
[...]

Yes, that is probably the most fundamental issue.

> I would propose to _define_ the Wireshark API. This will be a process 
> and I don't expect this to become available in a few days. One way to 
> identify *the Wireshark API* would be to identify this API in the header 
> files.
> 
> With a central macro WIRESHARKAPI(or WSAPI

This is a much better approach than my original idea of autogenerating the
.def file.

> // config.h
> 
> #ifdef MSVC_VARIANT
> // generating libwireshark.DLL
>    #ifdef _NEED_VAR_IMPORT
>      #define WIRESHARKAPI __declspec(dllimport)
>    #else
>      #define WIRESHARKAPI __declspec(dllexport)
>    #endif
> #else
>    // not generating DLL
>    #define WIRESHARKAPI extern
> #endif

I'm not sure if extern is sufficient to mark the function for export if
libtool is using -export-symbols. That may require some tweaking for
non-Windows platforms.

> you can define the API in the header files like this:
> 
> // proto.h
> 
> WIRESHARKAPI proto_tree* proto_tree_create_root(void);
> 
> WIRESHARKAPI proto_item *
> proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
>      const gint start, gint length, const guint encoding);

Looks good to me. Maybe WSPUBLIC or WSEXPORT would be a clearer name, but
that's a detail to be worked out.

> The has some advantages
> 
> - one central place to define how the functions become part of the API 
> in config.h
> 
> - exactly one place of definition if a symbol is part of the API.
> Currently you define the symbol in header and DEF file.
> 
> - It is visible immediately if a declaration in the header files is part 
> if the API or not.

Vital. I keep finding things in header files I want to use, then have to
check the .def file to discover whether it's exported.

> What do you think about it?

I love it! Any objections, or can we get started on it?

> Andy
--Greg