I'm having problems with portability issues while developing a network analyzer application using vc++ 2008.
I'm developing an application that analyzes packets using winpcap. However, recently I've been required that my app should also run on solaris and linux .. what I want to ask that I'm using winpcap functions like PacketOpenAdapter to sniff on an adapter .. do I have to rewrite all the capturing code from start to make it work on operating systems other than windows? shall I only use the pcap.h to make my application portable? do I need to use libpcap? in short, what should I do to make it portable?
thx in advance.
what I want to ask that I'm using winpcap functions like PacketOpenAdapter to sniff on an adapter .. do I have to rewrite all the capturing code from start to make it work on operating systems other than windows?
You need to use only functions that are in wpcap.dll
; you must not use any packet.dll
functions, unless you don't need to use them and the program will still work if you don't use them, in which case use them only on Windows.
In addition, don't use wpcap.dll
functions that are only available on Windows, such as pcap_open()
; use only pcap_open_live()
to open a device on which to capture and use only pcap_open_offline()
to open saved capture files.
shall I only use the pcap.h to make my application portable?
Yes.
do I need to use libpcap?
Use libpcap on UN*X (Solaris, Linux, OS X, *BSD, HP-UX, AIX, etc.), use WinPcap (which is libpcap ported to Windows) on Windows, and use only functions that are available in the versions of libpcap you will be using on UN*X and in the version of WinPcap you're using on Windows.
Then make sure everything else you use is either portable between UN*X and Windows or, if you have to use platform-specific functions, make sure you use the ones appropriate for a particular platform only on that platform.