I use gopacket in my program. on linux, it runs perfectly. But on windows the whole program crashes if i did not install WinPcap before.
My plan was to check if WinPcap is installed, and if not to inform the user that he needs this to use 100% of all features.
But i dont come to this point. i cant use gopacket if WinPcap is not available. I mean... not a single line of code of it (=> crash)
Has anyone an idea how i can solve this? im do not need gopacket actually. My plan was, if it is installed, fine, super! If not, dont care... do other things.
But now i have 2 choices... remove gopacket totally or find a way to start my program without the need of wpcap.dll. at least to tell the user that he needs it.
Please help me :(
You're wrong in that you are «not [using] a single line of code of it»: it's not hard to see that its Windows-specific code calls into winpcap.dll
.
What is more fun, is that its Unix-specific code calls into libpcap.so
, and this means you have it working on your local system simply due to the fact you have libpcap
package installed (or whatever it's named in your code).
All this means that currently your program is not really portable anyway (I mean, in the sense you supposedly think it is portable). You can run something like
$ ldd ./yourbinary
and see it printing a reference to libpcap.so
of some version.
There are several ways to solve this.
The easiest is to just try shipping winpcap.dll
with your binary. Windows by default looks for DLLs in the current directory of the application trying to load them. Since gopacket
uses cgo
, it means the winpcap.dll
is attempted to be linked it at the application startup, so the application has no chance of changing its working directory before that library is attempted to be found and linked in.
A more complicated approach is to make (or obtain) a static version of the winpcap library (remember that DLL is a library, just a special form of it) and then jump around building gopacket
so that it picks that static library.