nmap / nmap/npcap

npcap-0.991 dotnet p/invoke with sharppcap

Open
#140 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
3.6k
Forks
592
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SafeNativeMethods.pcap_findalldevs P/Invoke entry point and compare it with the declaration moved into the calling class. Reproduce the behavior for the standalone DeviceList.exe and when launched by IIS, then determine whether completion requires a P/Invoke, IIS process-context, or wpcap.dll configuration fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.