Example #1
0
        /// <summary>
        /// Clones the specified <see cref="source" />.
        /// </summary>
        /// <param name="source">The request.</param>
        /// <returns><see cref="Native.NdisApi.ETH_M_REQUEST_U" />.</returns>
        public unsafe Native.NdisApi.ETH_M_REQUEST_U *CloneUnsafeEthMRequest(ref Native.NdisApi.ETH_M_REQUEST_U * source)
        {
            var destination = CreateUnsafeEthMRequest(source->dwPacketsNumber);

            CloneUnsafeEthMRequest(ref source, ref destination);
            return(destination);
        }
Example #2
0
        /// <summary>
        /// Zeroes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public unsafe void ZeroUnsafeEthMRequest(ref Native.NdisApi.ETH_M_REQUEST_U *request)
        {
            request->hAdapterHandle = IntPtr.Zero;
            var packets = request->GetPackets();

            for (int i = 0; i < request->dwPacketsNumber; i++)
            {
                Kernel32.ZeroMemory(packets[i]._buffer, Native.NdisApi.IntermediateBufferSize);
            }
        }
Example #3
0
        /// <summary>
        /// Clones the specified request.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        public unsafe void CloneUnsafeEthMRequest(ref Native.NdisApi.ETH_M_REQUEST_U *source, ref Native.NdisApi.ETH_M_REQUEST_U *destination)
        {
            destination->hAdapterHandle   = source->hAdapterHandle;
            destination->dwPacketsSuccess = source->dwPacketsSuccess;
            destination->dwPacketsNumber  = source->dwPacketsNumber;

            var requestPackets = source->GetPackets();
            var nextPackets    = destination->GetPackets();

            for (int i = 0; i < source->dwPacketsSuccess; i++)
            {
                Kernel32.CopyMemory(nextPackets[i]._buffer, requestPackets[i]._buffer, (uint)Native.NdisApi.IntermediateBufferSize);
            }
        }
Example #4
0
        /// <summary>
        /// Sends the packets to MSTCP or adapter.
        /// </summary>
        /// <param name="ethMRequest">The ether multiple request.</param>
        /// <param name="packets">The optional packets.</param>
        /// <returns><c>true</c> if successful, <c>false</c> otherwise.</returns>
        public unsafe bool SendPackets(Native.NdisApi.ETH_M_REQUEST_U *ethMRequest, Native.NdisApi.NDISRD_ETH_Packet[] packets = null)
        {
            lock (_lock)
            {
                _ethPacketsToAdapter.dwPacketsSuccess = 0;
                _ethPacketsToMstcp.dwPacketsSuccess   = 0;
                _ethPacketsToAdapter.dwPacketsNumber  = 0;
                _ethPacketsToMstcp.dwPacketsNumber    = 0;
                _ethPacketsToAdapter.hAdapterHandle   = ethMRequest->hAdapterHandle;
                _ethPacketsToMstcp.hAdapterHandle     = ethMRequest->hAdapterHandle;

                packets = packets ?? ethMRequest->GetPackets();

                foreach (var packet in packets)
                {
                    var buffer = (Native.NdisApi.INTERMEDIATE_BUFFER_U *)packet._buffer;

                    if (buffer->m_dwDeviceFlags == Native.NdisApi.PACKET_FLAG.PACKET_FLAG_ON_SEND)
                    {
                        _ethPacketsToAdapter._ethPacket[_ethPacketsToAdapter.dwPacketsNumber++]._buffer = packet._buffer;
                    }
                    else
                    {
                        _ethPacketsToMstcp._ethPacket[_ethPacketsToMstcp.dwPacketsNumber++]._buffer = packet._buffer;
                    }
                }

                var success = true;

                if (_ethPacketsToMstcp.dwPacketsNumber > 0)
                {
                    success = SendPacketsToMstcp(ref _ethPacketsToMstcp);
                }

                if (_ethPacketsToAdapter.dwPacketsNumber > 0)
                {
                    success = SendPacketsToAdapter(ref _ethPacketsToAdapter) && success;
                }

                return(success);
            }
        }
Example #5
0
 /// <summary>
 /// Disposes the specified object.
 /// </summary>
 /// <param name="obj">The object.</param>
 public unsafe void DisposeObject(Native.NdisApi.ETH_M_REQUEST_U *obj)
 {
     _pinnedManagedArrayAllocator.FreeArray((IntPtr)obj);
 }
Example #6
0
 /// <summary>
 /// Sends the packets to MSTCP.
 /// </summary>
 /// <param name="ethMRequest">The ether multiple request.</param>
 /// <returns><c>true</c> if successful, <c>false</c> otherwise.</returns>
 public unsafe bool SendPacketsToMstcp(Native.NdisApi.ETH_M_REQUEST_U *ethMRequest)
 {
     return(Native.NdisApi.SendPacketsToMstcp(Handle, ethMRequest));
 }
Example #7
0
 /// <summary>
 /// Reads the packets to the specified <see cref="ethMRequest" />.
 /// </summary>
 /// <param name="ethMRequest">The ether multiple request.</param>
 /// <remarks>The adapter handle needs to be set.</remarks>
 /// <returns><c>true</c> if successful, <c>false</c> otherwise.</returns>
 public unsafe bool ReadPackets(Native.NdisApi.ETH_M_REQUEST_U *ethMRequest)
 {
     return(Native.NdisApi.ReadPackets(Handle, ethMRequest));
 }