nmap / npcap

Nmap Project's Windows packet capture and transmission library
https://npcap.com
Other
2.92k stars 508 forks source link

npcap-0.991 dotnet p/invoke with sharppcap #140

Open cbwang505 opened 4 years ago

cbwang505 commented 4 years ago

my operation system is win10 1903 x64,i uninstall npcap-0.9982,then install npcap-0.991, if i use the flowing p/invoke code, call the pcap_findalldevs function is in the class named SafeNativeMethods

 result = SafeNativeMethods.pcap_findalldevs(ref devicePtr,
                    errorBuffer);

the return devicePtr alway be IntPtr.Zero,this makes a error then i move SafeNativeMethods.pcap_findalldev function method to the same class where i call that,like this following code

[DllImport(SafeNativeMethods.PCAP_DLL, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]        
        private static extern int pcap_findalldevs(ref IntPtr devicelist,
            StringBuilder errbuf);
    private static List<WinPcapDevice> Devices(string rpcapString,
            RemoteAuthentication remoteAuthentication)
        {
            var retval = new List<WinPcapDevice>();
            IntPtr devicePtr=IntPtr.Zero ;
            StringBuilder errorBuffer = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE);           
            int result = pcap_findalldevs(ref devicePtr,
                errorBuffer);
}

it works allright with no error,and devicePtr return is not IntPtr.Zero ,this flowing code run successfully but i still caught a error when i start the same exe in iis like this

Process   _guardProcess = new Process();
                _guardProcess.StartInfo.CreateNoWindow = true;
                _guardProcess.StartInfo.UseShellExecute = false;
                _guardProcess.StartInfo.WorkingDirectory = ConfigurationManager.AppSettings["PeachRoot"];
                _guardProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                _guardProcess.StartInfo.LoadUserProfile = true;
                string tid = DateTime.Now.Ticks.ToString();
                _guardProcess.StartInfo.Arguments = tid;
                _guardProcess.StartInfo.FileName =  
                @"E:\git\PeachProject\PeachAdmin\DeviceList\bin\Debug\DeviceList.exe";
                _guardProcess.Start();

the exe in run in no gui window ,till in run to this code pcap_findalldevs , this devicePtr return is IntPtr.Zero agin i do not known is there some thing error with p/invoke or iis config or wpcap.dll

chmorgan commented 4 years ago

@cbwang505 does this reproduce with the latest npcap release without installing winpcap compatibility api?