Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596666
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:01:05+00:00 2026-05-18T20:01:05+00:00

I am writing an application that makes use of libwireshark , though the specifics

  • 0

I am writing an application that makes use of libwireshark, though the specifics are not entirely relevant here.

I prepare a packet for the library to dissect and hence call epan_dissect_run(packet), which in turn dissects the given packet and hence calls a callback function that I have specified — using register_tap_listener().

My question is: how can I wrap this process up in a single function, dissected_information* MyDissectPacket(packet)? This applies not just to libwireshark as I have outlined, but libraries that make judicious use of callbacks in general.

Does the answer depend on whether the callback is executed asynchronously, on another thread or both? If the callback is executed synchronously on the same thread, does this make the wrapping code simpler?

Perhaps it is my Google-fu that is weak — I do not know which terms I should be using, as this question has surely been asked many times before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:01:05+00:00Added an answer on May 18, 2026 at 8:01 pm

    If you have no idea about if it is asynchronous or not, you should write your function like if it was.

    It is a producer/consumer problem: is there anything to comsume – is the packet dissected? So semaphores can resolve it to wait until there is something to consume. Your callback function has to signal that the packet dissection is finished – there is something to consume.

    And what I would do is (pseudo code):

    void my_callback()
    {
       semaphore.post()
    }
    
    // ...
    
    dissected_information* MyDissectPacket(packet)
    {
      epan_dissect_run(packet) // asynchronous or not call
      semaphore.wait()         // if it is, it will stop here and wait the post() of the 
                               // callback
                               // if it is not, it will result exaclty like above, but the
                               // semaphore will always be already "posted"; so you will just have
                               // a useless semaphore.
    }
    

    I hope I correctly understood your problem…

    EDIT:
    In case of you get your result through the callback:

    void my_callback(result)
    {
       shared_var_result = result;
       semaphore.post()
    }
    
    // ...
    
    dissected_information* MyDissectPacket(packet)
    {
      epan_dissect_run(packet) // asynchronous or not call
      semaphore.wait()         // if it is, it will stop here and wait the post() of the 
                               // callback
                               // if it is not, it will result exaclty like above, but the
                               // semaphore will always be already "posted"; so you will just have
                               // a useless semaphore.
      return shared_var_result
    }
    

    I can’t see any other reasonable solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application that makes use of libwireshark , though the specifics
I am writing a Cocoa application that makes use of the ParseKit framework (
I'm writing an Fast-CGI application that makes use of sqlAlchemy & MySQL for persistent
I'm writing a C++ application that makes heavy use of OpenCV. Unfortunately, some of
I'm writing an application that makes heavy use of geodjango (on PostGis) and spatial
I'm writing an application that makes use of a tree structure, so of course
I'm writing a Flex application that makes full use of BlazeDS to a Java
When I compile a c++ application I'm writing that makes use of hash_map, I
I'm writing an application that makes use of Java's speech API and FreeTTS. The
I am writing a fairly complex application that makes heavy use of STL containers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.