Ask Your Question
0

CMake steps for C dissector 2.4 -> 2.6 migration? (e.g. linker errors)

asked 2018-06-28 09:47:23 +0000

StefanMUC gravatar image

updated 2018-06-29 17:33:12 +0000

Guy Harris gravatar image

I have a Wireshark 2.4 private dissector plugin written in C which is running like a charm. Now that Wireshark 2.6 is out, I want to upgrade my source code to support the new version, but I'm quite struggling with the transition. Is there a guide or "developer release notes" that I can read to get the changes and use to adjust my code and build configuration to match the new standard?

I already solved some problems with comparing to other dissectors, but I can't solve this: During compilation I get this linker error:

packet-protocolname.obj : error LNK2019: unresolved external symbol __imp_proto_register_protocol referenced in function proto_register_protocolname

From other dissectors I see that there wireshark.lib, wiretap.lib, wsutil.lib are included in linker, but not in my dissector. If I want to add them to my dissector using these lines in my CMakeLists.txt:

target_link_libraries(../../../run/$(ConfigurationName)/wireshark.lib)
target_link_libraries(../../../run/$(ConfigurationName)/wiretap.lib)
target_link_libraries(../../../run/$(ConfigurationName)/wsutil.lib)

I get this error message:

>  Cannot specify link libraries for target
>  "../../../run/$(ConfigurationName)/wireshark.lib" which is not built by this project.

This is my current CMakeLists.txt:

include(WiresharkPlugin)

# Plugin name and version info (major minor micro extra)
set_module_info(protocolname 0 1 2 3)

set(DISSECTOR_SRC
    packet-protocolname.c
)

set(PLUGIN_FILES
    ${DISSECTOR_SRC}
)

set(CLEAN_FILES
    ${PLUGIN_FILES}
)

if (WERROR_COMMON_FLAGS)
    set_source_files_properties(
        ${CLEAN_FILES}
        PROPERTIES
        COMPILE_FLAGS ${WERROR_COMMON_FLAGS}
    )
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(some/directory/i/need)

set(CUSTOM_DISSECTOR_SRC
    ${DISSECTOR_SRC}
)

add_plugin_library(protocolname protocolname)

get_filename_component(_dll_output_dir "${_libwireshark_location}" PATH)
file (TO_NATIVE_PATH "${_dll_output_dir}" _dll_output_dir_win )
add_custom_command(TARGET protocolname PRE_BUILD
    [... some command I need]
)


install(TARGETS protocolname
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/plugins/${CPACK_PACKAGE_VERSION} NAMELINK_SKIP
    RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/plugins/${CPACK_PACKAGE_VERSION}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/plugins/${CPACK_PACKAGE_VERSION}
)

file(GLOB DISSECTOR_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
CHECKAPI(
    NAME
      protocolname
    SWITCHES
      -g abort -g termoutput -build
    SOURCES
      ${DISSECTOR_SRC}
      ${DISSECTOR_HEADERS}
)

I'm on Windows, switched from Wireshark 2.4 (Visual Studio 2013) to Wireshark 2.6 (Visual Studio 2017)

Thanks in advance!

edit retag flag offensive close merge delete

Comments

Your CMakeLists.txt seems to have a lot of unnecessary additions. Try using the CMakeLists.txt of an existing plugin, e.g. Gryphon as a basis and change the names, the source files, and add plugin-specific external (non-wireshark) includes and libraries. CMake will handle the Wireshark ones.

grahamb gravatar imagegrahamb ( 2018-06-28 20:57:15 +0000 )edit

Thanks grahamb for your response. I don't have any unneccessary addition, I started with CMakeLists.txt from Gryphon as written in the manual. What you think of "unnecessary additions" are the examples written there ;)

See my answer below for the changes I had to do to comply to 2.6 standard.

StefanMUC gravatar imageStefanMUC ( 2018-06-29 07:16:24 +0000 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-28 11:27:24 +0000

StefanMUC gravatar image

updated 2018-06-29 07:12:02 +0000

So I finally solved it :) I found the gryphon plugin again that's mentioned in documentation to be taken as example (which I did as I started development with Wireshark 2.2) and compared it to my current file.

There were more things to take care of:

replaced register function:

register_dissector_files(

seems to be replaced by

register_plugin_files(

additional paramter

add_plugin_library(

has a new destination parameter

new functions

There's a two new function

target_link_libraries(protocolname epan)
set_source_files_properties(

you will have to add, that solved my linker errrors

replaced install function:

install(TARGETS protocolname

seems to be replaced by

install_plugin(protocolname destination)

After doing all the changes and re-adding plugin.c to PLUGIN_FILES (seems to be generated through one of the functions I was missing), the dissector worked again without any source code change - great!

edit flag offensive delete link more

Comments

Additionally plugin files are now not located at /plugins folder but at /plugins/major.minor which needs adjustment on my build script

StefanMUC gravatar imageStefanMUC ( 2018-06-29 07:41:41 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-06-28 09:47:23 +0000

Seen: 1,103 times

Last updated: Jun 29 '18