示例#1
0
 private void CloseTunDev(IntPtr handle)
 {
     if (handle != IntPtr.Zero)
     {
         NativeNetif.CloseHandle(handle);
     }
 }
示例#2
0
        protected bool DeviceIoControl(uint commands, byte[] contents)
        {
            IntPtr hEvent = NativeNetif.CreateEvent(IntPtr.Zero, false, false, null);

            try
            {
                NativeNetif.OVERLAPPED overlapped = new NativeNetif.OVERLAPPED();
                overlapped.hEvent = hEvent;

                uint dw           = 0;
                uint content_size = 0;
                if (contents == null)
                {
                    if (!NativeNetif.DeviceIoControl(this.Handle, commands,
                                                     contents, 0, contents, 0, ref dw, ref overlapped))
                    {
                        NativeNetif.WaitForSingleObject(hEvent, Timeout.Infinite);
                        return(overlapped.Internal == NativeNetif.ERROR_SUCCESS);
                    }
                }
                else
                {
                    content_size = (uint)contents.Length;
                    if (!NativeNetif.DeviceIoControl(this.Handle, commands,
                                                     contents, content_size, contents, content_size, ref dw, ref overlapped))
                    {
                        NativeNetif.WaitForSingleObject(hEvent, Timeout.Infinite);
                        return(overlapped.Internal == NativeNetif.ERROR_SUCCESS);
                    }
                }
                return(true);
            }
            finally
            {
                if (hEvent != IntPtr.Zero)
                {
                    NativeNetif.CloseHandle(hEvent);
                }
            }
        }