public
Created

  • Download Gist
ioctl_test.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#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) {
perror("open");
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");
close(fd);
//if(ioctl(fd, READ_IOCTL, buf) < 0)
//perror("second ioctl");
 
//printf("message: %s\n", buf);
return 0;
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.