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 ?
A:
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
2010-01-13 03:33:06
And every "Java" packet capturing library I'm aware of is actually a JNI wrapper around libpcap.
GregS
2010-01-13 03:35:24
There's nothing bad in using a JNI wrapper. I suppose it will be much easier to code same thing in java than in C.
tulskiy
2010-01-13 04:15:19
+1
A:
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
Snowangelic
2010-01-13 07:07:38