public static IntPtr Resolver(string libraryName, Assembly assembly, DllImportSearchPath?searchPath) { if (libraryName != PCAP_DLL) { // Use default resolver return(IntPtr.Zero); } var names = new List <string>(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { names.Add("libpcap.so"); names.Add("libpcap.so.0"); names.Add("libpcap.so.0.8"); names.Add("libpcap.so.1"); } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { names.Add("libpcap.dylib"); } foreach (var name in names) { if (NativeLibraryHelper.TryLoad(name, out var handle)) { return(handle); } } return(IntPtr.Zero); }
/// <summary> /// The class NativeLibrary is only available since .NET Core 3.0 /// It's not available in .NET Framework, /// but that does not affect us since we would use the Windows dll name wpcap /// </summary> private static void RegisterResolver() { NativeLibraryHelper.SetDllImportResolver(typeof(LibPcapSafeNativeMethods).Assembly, Resolver); }