Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#define MY_MACIG 'G'
#define READ_IOCTL _IOR(MY_MACIG, 0, int)
//#define WRITE_IOCTL _IOW(MY_MACIG, 1, int)
/* attribute structures */
struct ioctl_test_t {
char field1;
char field2;
} testStruct;
#define IOCTL_TEST _IOW(0, 6, struct ioctl_test_t)
int main(){
char buf[200];
int fd = -1;
if ((fd = open("/proc/ioctl_test", O_RDWR)) < 0) {
return -1;
testStruct.field1 = 1; //1 char in my first initial
testStruct.field2 = 'K';
printf("size of testStruct.field1 = %d\n", sizeof(testStruct.field1));
printf("size of testStruct.field2 = %d\n", sizeof(testStruct.field2));
if(ioctl(fd, IOCTL_TEST, &testStruct ) < 0)
perror("first ioctl");
//if(ioctl(fd, READ_IOCTL, buf) < 0)
//perror("second ioctl");
//printf("message: %s\n", buf);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.