private static bool DoIoctl(IoctlCode code, IntPtr data)
        {
            int err;

            if ((err = LibCWrapper.Ioctl(fd, (int)code, data)) < 0)
            {
                var lastErrorCode    = Marshal.GetLastWin32Error();
                var lastErrorMessage = LibCWrapper.Strerror(lastErrorCode);

                loggingParent.Log(LogLevel.Error, "There was an error when executing the {0} ioctl: {1} (0x{2:X})", Enum.GetName(typeof(IoctlCode), code), lastErrorMessage, lastErrorCode);
                LibCWrapper.Close(fd);
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        } // end property _NativeIoctl

        public int Ioctl(IoctlCode ioctlType, object data)
        {
            uint     size = (uint)Marshal.SizeOf(data);
            GCHandle gch  = GCHandle.Alloc(data, GCHandleType.Pinned);
            int      err  = -1;

            try
            {
                IntPtr ptr = gch.AddrOfPinnedObject();
                err = _NativeIoctl((ushort)ioctlType, ptr, size);
            }
            finally
            {
                gch.Free();
            }
            return(err);
        } // end Ioctl