Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npcap-0.991 dotnet p/invoke with sharppcap #1692

Open
cbwang505 opened this issue Aug 14, 2019 · 1 comment

Comments

@cbwang505
Copy link

commented Aug 14, 2019

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

This comment has been minimized.

Copy link

commented Sep 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.