PcapPlusPlus icon indicating copy to clipboard operation
PcapPlusPlus copied to clipboard

RawPacketsVector concurrent

Open KevinSmild opened this issue 5 years ago • 10 comments

Hi. I would like to thank you for this nice library, it's much more simpler and C++ish than npcap or libpcap.

I would like to ask a question. Is there any way of making the Async capture with a vector thread concurrent without changing the library code?

KevinSmild avatar Sep 05 '19 05:09 KevinSmild

thanks for the kind words :)

Could you please clarify your question? what do you mean by async capture with a vector thread?

seladb avatar Sep 05 '19 06:09 seladb

Sorry. What I meant is if there is a way of making "Asynchronous packet capture using a packet list (vector)" thread safe.

KevinSmild avatar Sep 05 '19 06:09 KevinSmild

I want to capture packets and process them at the same time (without stopping the capture). It would be nicer if I can process a bunch of packets at the same time instead of processing one by one. Hence, I would like to use the "Asynchronous packet capture using a packet list (vector)" capture mode of your library.

That being said, I have (at least) two threads trying to use the same pcpp::RawPacketsVector, so I was wondering if there is a way of making it thread safe. Or do you have any other suggestion?

KevinSmild avatar Sep 05 '19 06:09 KevinSmild

Thanks for clarifying your question. If I understand your ask, you're currently using the API:

PcapLiveDevice::startCapture(RawPacketVector& capturedPacketsVector)

And you're looking for a way to start using the packets in the RawPacketVector before stopping the capture.

Unfortunately RawPacketVector (which is based on std::vector) is not thread safe so this may not work. But it's should be pretty easy to make it thread safe by adding a locking mechanism to that class. Please let me know what you think

seladb avatar Sep 05 '19 07:09 seladb

Thanks for your reply. I'll work on that.

KevinSmild avatar Sep 06 '19 05:09 KevinSmild

Thanks. Please create a PR once you're done and I'll review and merge it

seladb avatar Sep 06 '19 05:09 seladb

hi @KevinSmild please let me know if you have the time to work on this

seladb avatar Oct 08 '19 07:10 seladb

@gx740 what do you think about this?

seladb avatar Nov 12 '19 08:11 seladb

@seladb If it helps, i want to work on this issue and create PR if done.

jafar75 avatar May 29 '21 11:05 jafar75

Sure @jafar75 you're more than welcome! Please go for it, thank you!

seladb avatar May 29 '21 16:05 seladb

To be honest, I don't think this is something worth investigating. I'll close this issue

seladb avatar Oct 11 '22 03:10 seladb