ioctl

User Permission check on ioctl command

依然范特西╮ 提交于 2019-12-10 14:12:53
问题 I am implementing char driver ( Linux) and there are certain IOCTL commands are there in my driver which needs to be only executed by ADMIN. My question is how can I check user permission under my ioctl command implementation and restrict unprivileged user from accessing IOCTL. 回答1: You can use bool capable(int cap) function, which returns true if user has capability requested. Possible values of cap are listed in kernel sources at include/uapi/linux/capability.h (macros started with CAP_ ).

why does ioctl return “bad address”

旧时模样 提交于 2019-12-10 13:47:54
问题 I use the the code below to output data from SPI port of an embedded board (olimex imx233-micro -- it is not a board specific question). When I run the code ioctl return " bad address ". I am modifying the code on http://twilight.ponies.cz/spi-test.c which works fine. Could anyone tell me what am I doing wrong? root@ubuntu:/home# gcc test.c -o test test.c:20: warning: conflicting types for ‘msg_send’ test.c:16: note: previous implicit declaration of ‘msg_send’ was here root@ubuntu:/home# .

Get IPv6 addresses in linux using ioctl

做~自己de王妃 提交于 2019-12-10 02:28:34
问题 I trying to get IPv6 addresses in my linux OS like following: sd = Socket_m(AF_INET6_m, SOCK_DGRAM_m, 0); ifc.ifc_buf = buffer_p; ifc.ifc_len = buffSize; Ioctl_m(sd, SIOCGIFCONF, &ifc); It works succesfully if any IPv4 address are configured for interface, but if interface has only one IPv6 address it is not returned by ioctl. For example, I unable to get IPv6 address of the followith interface because only IPv6 address is configured: br1 Link encap:Ethernet HWaddr 00:10:18:2D:BB:34 inet6

How to set errno in Linux device driver?

别等时光非礼了梦想. 提交于 2019-12-10 02:02:16
问题 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

C/C++ Linux MAC Address of all interfaces

对着背影说爱祢 提交于 2019-12-09 17:10:49
问题 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

Having a problem figuring out how to get Ethernet interface info on Mac OS X using ioctl/SIOCGIFADDR/SIOCGIFCONF?

爷,独闯天下 提交于 2019-12-09 12:55:48
问题 Are you having a problem figuring out how to get interface info on Mac OS X using ioctl/SIOCGIFADDR/SIOCGIFCONF? I had a lot of trouble getting code that worked fine on Linux to work on Mac OS X today. 回答1: Copy-paste to main.c and gcc main.c && ./a.out should work (lists all network interfaces, their ipv4/6 address, netmask and MAC address if associated): Works fine on Mac OSX and iOS iPad/iPhone : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include

Using RNDADDENTROPY to add entropy to /dev/random

柔情痞子 提交于 2019-12-09 10:44:01
问题 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

Writing to framebuffer directly on Android

情到浓时终转凉″ 提交于 2019-12-09 07:14:19
问题 I've a rooted phone with Android 4.2.2. I'd like to use minui API used (source here) in bootloader code to draw stuff on the screen. minui is much simpler than native OpenGL and I don't need any complex functionality exposed by OpenGL. The problem is that I can't write stuff directly to fb0 device. FBIOPUT_VSCREENINFO fails for unknown reason. How can I draw directly to fb0 on Android, or how can I use minui outside the bootloader mode? 回答1: device node:/dev/graphics/fb0 you can build in

unlocked_ioctl vs normal ioctl

前提是你 提交于 2019-12-09 04:38:59
问题 In my driver's file_operations structure, I have: struct file_operations Fops = { read: device_read, write: device_write, unlocked_ioctl: device_ioctl, ... }; I.e. there is no ioctl field used. Is this sufficient to avoid Big Kernel Lock and enter into device_ioctl() without any synchronization? Or do I have to change ioctl() calls in userspace part of the code too? 回答1: Read this LWN article: http://lwn.net/Articles/119652/ Also sometime between 2.6.33 and a 2.6.35 rc (use git-diff to find

Call “expect” script in C++ process

爱⌒轻易说出口 提交于 2019-12-08 12:17:34
问题 I realized a shell using expect/spawn and send commands to SCP files from a remote server which send automatically the password when it is needed. The script works fine on UNIX terminal. Nevertheless, I tried to use this script throough a C++ process. It has been called by system() or even popen() function without sucess. This error is returned: "ioctl(raw): I/O error" Someone could have any clue? This is my script: #!/bin/bash targetHost=$1 password=$2 sourceFile=$3 destRep=$4 expect -c "