Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KarenWest
Created September 19, 2013 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarenWest/6629582 to your computer and use it in GitHub Desktop.
Save KarenWest/6629582 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment