Skip to content

@KarenWest /ioctl_test.c
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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
Something went wrong with that request. Please try again.