ioctl

C/C++ Linux MAC Address of all interfaces

故事扮演 提交于 2019-12-04 04:46:14
I am using the following code to retrieve all MAC addresses for current computer: ifreq ifr; ifconf ifc; char buf[1024]; int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (sock == -1) { ... }; ifc.ifc_len = sizeof(buf); ifc.ifc_buf = buf; if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) { ... } ifreq *it = ifc.ifc_req; const ifreq* const end = it + (ifc.ifc_len / sizeof(ifreq)); for (; it != end; ++it) { strcpy(ifr.ifr_name, it->ifr_name); if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) { if (!(ifr.ifr_flags & IFF_LOOPBACK)) { if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) { unsigned char mac_address[6];

How to properly convert a C ioctl call to a python fcntl.ioctl call?

旧巷老猫 提交于 2019-12-04 03:57:27
Following an example on resetting a serial port in Linux I wanted to translate the following snippet fd = open(filename, O_WRONLY); ioctl(fd, USBDEVFS_RESET, 0); close(fd); into valid python code. Here is what I have tried so far file_handler = open(self._port, 'w') fcntl.ioctl(file_handler, termios.USBDEVFS_RESET) file_handler.close() which ends with an error 'module' object has no attribute 'USBDEVFS_RESET' . The termios documentation is not very helpful in this point, as it does not list the possible properties of termios . See also the fcntl documentation for an example of such a termios

Get Terminal width Haskell

此生再无相见时 提交于 2019-12-04 03:28:11
How to get the width of the terminal in Haskell? Things I tried System.Posix.IOCtl (could not figure out how to get it to work) This only has to work unix. Thanks hammar If you don't want a dependency on ncurses, here's a wrapper of the appropriate ioctl() request using the FFI, based on the accepted answer of Getting terminal width in C? TermSize.hsc {-# LANGUAGE ForeignFunctionInterface #-} module TermSize (getTermSize) where import Foreign import Foreign.C.Error import Foreign.C.Types #include <sys/ioctl.h> #include <unistd.h> -- Trick for calculating alignment of a type, taken from -- http

Linux - ioctl with FIONREAD always 0

六眼飞鱼酱① 提交于 2019-12-03 16:58:52
问题 I'm trying to get to know how many bytes there are readable at my TCP socket. I am calling ioctl with the Flag "FIONREAD" which should actually give me this value. When I call the function I get as return val 0 ( so no Error ) but also my integer argument gets the value 0. That would be no problem but when I call the recv() method I actually read some Bytes out of the socket. What am I doing wrong? // here some Code: char recBuffer[BUFFERLENGTH] = {0}; int bytesAv = 0; int bytesRead = 0; int

Using RNDADDENTROPY to add entropy to /dev/random

荒凉一梦 提交于 2019-12-03 13:38:52
I have a device which generates some noise that I want to add to the entropy pool for the /dev/random device in an embedded Linux system. I'm reading the man page on /dev/random and I don't really understand the structure that you pass into the RNDADDENTROPY ioctl call. RNDADDENTROPY Add some additional entropy to the input pool, incrementing the entropy count. This differs from writing to /dev/random or /dev/urandom, which only adds some data but does not increment the entropy count. The following structure is used: struct rand_pool_info { int entropy_count; int buf_size; __u32 buf[0]; };

Inappropriate ioctl for device when trying to SSH

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to SSH few servers and trying to get sudo -l output of each server. Below is the script I'm executing #!/bin/bash serverlist = "/tmp/servers" while IFS =, read - r server netgroup username user do ssh - tt - q root@$server sudo - U $username - l < /dev/ null done < "$serverlist" I have found that -tt option in this script as the cause of this error. Any thought on this? Also i have noted that I don't see this error when i execute below command just for 1 server. ssh -tt -q root@myserver sudo -U cham01 -l Below is the

Windows CDROM Eject

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does anyone know a method to programmatically close the CD tray on Windows 2000 or higher? Open CD tray exists, but I can't seem to make it close especially under W2k. I am especially looking for a method to do this from a batch file, if possible, but API calls would be OK. 回答1: Here is an easy way using the Win32 API: [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)] protected static extern int mciSendString(string lpstrCommand,StringBuilder lpstrReturnString,int uReturnLength,IntPtr hwndCallback); public void

How to set errno in Linux device driver?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am designing a Linux character device driver. I want to set errno when error occurs in ioctl() system call. long my_own_ioctl(struct file *file, unsigned int req, unsigned long arg) { long ret = 0; BOOL isErr = FALSE; // some operation // ... if (isErr) { // set errno // ... <--- What should I do? ret = -1; } return ret; } What should I do to achieve that? Thank you at advance! Please allow me to explain my application with more detail. My device is located in /dev/myCharDev. My user space application is like this: #define _COMMAND (1)

How to find the device instance id of a PCSC reader

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Having only a handle and context to a PCSC reader using winscard on Windows >= XP, is there some way to get its device instance id or something else that can be used in the SetupDi* API to find out which driver is loaded for said reader. SCardGetReaderDeviceInstanceId is only available on Windows 8, so unfortunately not for me. As a plan B, all smart card readers could be enumerated in SetupDi using the smart card reader class guid. But then I would need a unique attribute to be able to correlate a reader between SCard* API and SetupDi* API.

Creating multiple partitions on USB using C#

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Iam trying to use DeviceIOControl to create multiple partiions in USB. It is always creating only one partition. Here is my source code [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); [DllImport("kernel32")] static extern int CloseHandle(IntPtr handle); [DllImport("kernel32")] private static extern int DeviceIoControl (IntPtr deviceHandle, uint