internal unsafe void SetFilter(pcap *pcapDescriptor) { if (\u003CModule\u003E.pcap_setfilter(pcapDescriptor, this._bpf) != 0) { throw PcapError.BuildInvalidOperation("Failed setting bpf filter", pcapDescriptor); } }
public static unsafe void Dump(string fileName, PcapDataLink dataLink, int snapshotLength, IEnumerable <Packet> packets) { if (packets == null) { throw new ArgumentNullException("packets"); } pcap *pcapDescriptor = \u003CModule\u003E.pcap_open_dead(dataLink.Value, snapshotLength); if ((IntPtr)pcapDescriptor == IntPtr.Zero) { throw new InvalidOperationException("Unable to open open a dead capture"); } try { using (PacketDumpFile packetDumpFile = new PacketDumpFile(pcapDescriptor, fileName)) { foreach (Packet packet in packets) { packetDumpFile.Dump(packet); } } } finally { \u003CModule\u003E.pcap_close(pcapDescriptor); } }
internal unsafe void Transmit(pcap *pcapDescriptor, [MarshalAs(UnmanagedType.U1)] bool isSync) { if (\u003CModule\u003E.pcap_sendqueue_transmit(pcapDescriptor, this._pcapSendQueue, isSync ? 1 : 0) < (uint)*(int *)((IntPtr)this._pcapSendQueue + 4L)) { throw PcapError.BuildInvalidOperation("Failed transmiting packets from queue", pcapDescriptor); } }
public static unsafe string GetErrorMessage(pcap *pcapDescriptor) { sbyte *numPtr = \u003CModule\u003E.pcap_geterr(pcapDescriptor); if ((IntPtr)numPtr == IntPtr.Zero) { return((string)null); } return(new string(numPtr)); }
private static unsafe pcap *PcapOpen(sbyte *source, int snapshotLength, PacketDeviceOpenAttributes attributes, int readTimeout, pcap_rmtauth *auth) { \u0024ArrayType\u0024\u0024\u0024BY0BAA\u0040D arrayTypeBy0BaAD; pcap *pcapPtr = \u003CModule\u003E.pcap_open(source, snapshotLength, (int)attributes, readTimeout, auth, (sbyte *)&arrayTypeBy0BaAD); if ((IntPtr)pcapPtr == IntPtr.Zero) { throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Unable to open the adapter. Adapter name: {0}. Error: {1}", new object[2] { (object)new string(source), (object)new string((sbyte *)&arrayTypeBy0BaAD) })); } return(pcapPtr); }
internal unsafe PacketCommunicator(pcap *pcapDescriptor, SocketAddress netmask) { }
internal PacketDumpFile(pcap *pcapDescriptor, string filename) { // ISSUE: unable to decompile the method. }
private unsafe void Initialize(pcap *pcapDescriptor, string filterString, IpV4SocketAddress netmask) { // ISSUE: untyped stack allocation long num1 = (long)__untypedstackalloc(\u003CModule\u003E.__CxxQueryExceptionSize()); basic_string\u003Cchar\u002Cstd\u003A\u003Achar_traits\u003Cchar\u003E\u002Cstd\u003A\u003Aallocator\u003Cchar\u003E\u0020\u003E stdAllocatorChar; MarshalingServices.ManagedToUnmanagedString(&stdAllocatorChar, filterString); // ISSUE: fault handler try { uint num2 = 0U; if (netmask != null) { num2 = netmask.Address.ToValue(); } bpf_program *bpfProgramPtr1 = (bpf_program *)\u003CModule\u003E.@new(16UL); bpf_program *bpfProgramPtr2; if ((IntPtr)bpfProgramPtr1 != IntPtr.Zero) { // ISSUE: initblk instruction __memset((IntPtr)bpfProgramPtr1, 0, 16L); bpfProgramPtr2 = bpfProgramPtr1; } else { bpfProgramPtr2 = (bpf_program *)0; } this._bpf = bpfProgramPtr2; try { if (\u003CModule\u003E.pcap_compile(pcapDescriptor, this._bpf, \u003CModule\u003E.std\u002Ebasic_string\u003Cchar\u002Cstd\u003A\u003Achar_traits\u003Cchar\u003E\u002Cstd\u003A\u003Aallocator\u003Cchar\u003E\u0020\u003E\u002Ec_str(&stdAllocatorChar), 1, num2) < 0) { throw new ArgumentException("An error has occured when compiling the filter <" + filterString + ">: " + PcapError.GetErrorMessage(pcapDescriptor)); } } catch (Exception ex1) when( { // ISSUE: unable to correctly present filter uint num3 = (uint)Marshal.GetExceptionCode(); if (\u003CModule\u003E.__CxxExceptionFilter((void *)Marshal.GetExceptionPointers(), (void *)0, 0, (void *)0) != 0) { SuccessfulFiltering; } else { throw; } } ) { uint num4 = 0U; \u003CModule\u003E.__CxxRegisterExceptionObject((void *)Marshal.GetExceptionPointers(), (void *)num1); try { try { \u003CModule\u003E.delete((void *)this._bpf); \u003CModule\u003E._CxxThrowException((void *)0, (_s__ThrowInfo *)0); } catch (Exception ex2) when( { // ISSUE: unable to correctly present filter num4 = (uint)\u003CModule\u003E.__CxxDetectRethrow((void *)Marshal.GetExceptionPointers()); if ((int)num4 != 0) { SuccessfulFiltering; } else { throw; } } ) { } if ((int)num4 != 0) { throw; } }
internal unsafe BerkeleyPacketFilter(pcap *pcapDescriptor, string filterString, IpV4SocketAddress netmask) { this.Initialize(pcapDescriptor, filterString, netmask); }
public static unsafe InvalidOperationException BuildInvalidOperation(string errorMessage, pcap *pcapDescriptor) { StringBuilder stringBuilder = new StringBuilder(errorMessage); if ((IntPtr)pcapDescriptor != IntPtr.Zero) { sbyte *numPtr = \u003CModule\u003E.pcap_geterr(pcapDescriptor); string str = (IntPtr)numPtr != IntPtr.Zero ? new string(numPtr) : (string)null; if (!string.IsNullOrEmpty(str)) { stringBuilder.Append(". WinPcap Error: "); stringBuilder.Append(str); } } return(new InvalidOperationException(stringBuilder.ToString())); }