private int SendNetifLevel3Output(byte *buffer, int offset, int length) { if (offset < 0 || length < 0) { return(~0); } if (buffer == null) { int num = (offset + length); if (0 == num) { return(0); } return(~0); } lock (this) { NativeNetif.OVERLAPPED *overlapped = stackalloc NativeNetif.OVERLAPPED[1]; NativeNetif.memset(overlapped, 0, sizeof(NativeNetif.OVERLAPPED)); if (!NativeNetif.WriteFile(this.Handle, &buffer[offset], length, out int lpNumberOfBytesWritten, overlapped)) { lpNumberOfBytesWritten = 0; if (!NativeNetif.GetOverlappedResult(this.Handle, overlapped, ref lpNumberOfBytesWritten, true)) { lpNumberOfBytesWritten = ~0; } } return(lpNumberOfBytesWritten); } }
private void ListenNetifLevel3Input(Action <byte[], int> callback) { NativeNetif.OVERLAPPED *overlapped = stackalloc NativeNetif.OVERLAPPED[1]; byte[] buffer = new byte[MTU]; while (0 == Interlocked.CompareExchange(ref this._disposed, 0, 0)) { NativeNetif.memset(overlapped, 0, sizeof(NativeNetif.OVERLAPPED)); int nNumberOfBytesToRead = 0; if (!NativeNetif.ReadFile(this.Handle, buffer, MTU, ref nNumberOfBytesToRead, ref *overlapped)) { if (!NativeNetif.GetOverlappedResult(this.Handle, overlapped, ref nNumberOfBytesToRead, true)) { callback?.Invoke(buffer, ~0); break; } } callback?.Invoke(buffer, nNumberOfBytesToRead); } }