Example #1
0
main ()
{
  int file_desc, ret_val;
  char *msg = "Message passed by ioctl\n";
  file_desc = open(DEVICE_FILE_NAME, 0);
  if (file_desc < 0) {
    printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
    exit(-1);
  }

  ioctl_get_nth_byte(file_desc);
  ioctl_get_msg(file_desc);
  ioctl_set_msg(file_desc, msg);

  close(file_desc);
}
Example #2
0
/*
  main()
//*/
int main(void)
{
    int fd=0, ret=0;
    char* msg = "message passed by ioctl\n";

    fd = open(DEVICE_FILE_NAME, 0);
    if(0 > fd) {
        printf("can't open device file: %s\n", DEVICE_FILE_NAME);
        exit(EXIT_FAILURE);
    }

    ioctl_get_nth_byte(fd);
    ioctl_get_msg(fd);
    ioctl_set_msg(fd, msg);

    close(fd);
}
Example #3
0
/*
 * Main - Call the ioctl functions
 */
int main(int argc, char *argv[])
{
	int file_desc;
	char buf[1024];
	struct  timeval    tv;

	file_desc = open(DEVICE_FILE_NAME, 0);
	if (file_desc < 0) {
		printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
		exit(-1);
	}
	gettimeofday(&tv, NULL);

	snprintf(buf, 1024, "%ld.%06ld:Message passed by ioctl\n", tv.tv_sec, tv.tv_usec);
	ioctl_get_nth_byte(file_desc);
	ioctl_get_msg(file_desc);
	ioctl_set_msg(file_desc, buf);

	close(file_desc);
	return 0;
}
Example #4
0
int main(int argc,char **argv) 
{
	char msg[80];
	int fd=-1;

	if(argc!=2) {
		printf("Usage <dev file name>\n");
		return -1;
	}
	fd=open(argv[1],O_RDONLY|O_WRONLY);	
	if(fd < 0) {
		printf("Unable to open the device file\n");
		return -2;
	}
	printf("calling ioctl_get_msg function\n");
	ioctl_get_msg(fd);
	printf("calling ioctl_set_msg function\n");
	strcpy(msg,"Hello world\n");
	ioctl_set_msg(fd,msg);
	printf("calling ioctl_get_nth_byte functio\n");
	ioctl_get_nth_byte(fd);
	close(fd);
}