I want to write a program that has 2 threads , one thread continuously captures packets from the network and dumps them in a buffer every t seconds and the other thread continuously reads this buffer and processes it every t seconds.. Can this be done in C ? or will Java be a better option ?
Asked
Active
Viewed 1,866 times
4
-
Thanks everyone ! I'm used to using threads in java and doing packet capture in C using libpcap.Can threads be used in C with equal ease as in java ? Is there any specific info on net that would help me.. – trinity Jan 13 '10 at 13:44
3 Answers
3
The answer here is the famous "libpcap". Use your favourite language as long as there is a good libpcap wrapper available for it.
- C/C++ is of course a perfect choice if you like it since you don't need any wrapper.
- JNetPcap (http://jnetpcap.com/) is a java winpcap/libpcap wrapper
- Sharpcap (http://www.codeproject.com/KB/IP/sharppcap.aspx?msg=2472909) is a C# libpcap parser. I did some stuff with it some times ago.
- ...
So pick your language, check the existence of the wrapper and go on. If there is no wrapper for this language, either change your choice, or create your own wrapper

almathie
- 731
- 5
- 22
1
It can certainly be done in C.
Doing it in Java will depend on whether you have access to a packet capturing library for Java (assuming you mean that you want to capture arbitrary packets, not just ones specifically directed to your application).

caf
- 233,326
- 40
- 323
- 462
-
And every "Java" packet capturing library I'm aware of is actually a JNI wrapper around libpcap. – President James K. Polk Jan 13 '10 at 03:35
-
1There's nothing bad in using a JNI wrapper. I suppose it will be much easier to code same thing in java than in C. – Denis Tulskiy Jan 13 '10 at 04:15