Ejemplo n.º 1
0
int detect_mirror(char * device) {
	int fd;
	struct hidraw_devinfo hrdi;
	glob_t globbuf;
	unsigned int i;
	int exit_value = -1;
	
	
	glob_devices(&globbuf);
	for(i=0;i<globbuf.gl_pathc;i++) {
		if((fd=open(globbuf.gl_pathv[i], O_RDONLY)) < 0) {
			printf("error while opening %s.\n", globbuf.gl_pathv[i]);
			continue;
		}
		ioctl(fd,HIDIOCGRAWINFO,&hrdi);
		if(hrdi.vendor == 0x1da8 && hrdi.product == 0x1301) {
			//printf("Found device: %s\n", globbuf.gl_pathv[i]);
			//chmod(globbuf.gl_pathv[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
			//fwrite(globbuf.gl_pathv[i], strlen(globbuf.gl_pathv[i]),1, fh);
			sprintf(device,"%s",globbuf.gl_pathv[i]);
			exit_value = 0;
		}
		close(fd);
	}

	return exit_value;
}
Ejemplo n.º 2
0
char *	mirror_discover	(void) {
	int fd;
	int len;
	struct hidraw_devinfo hrdi;
	glob_t globbuf;
	unsigned int i;
	char	*path	=	NULL;
	

	glob_devices(&globbuf);
	for(i=0;i<globbuf.gl_pathc;i++) {
		if((fd=open(globbuf.gl_pathv[i], O_RDONLY)) < 0) {
			printf("error while opening %s.\n", globbuf.gl_pathv[i]);
			continue;
		}
		ioctl(fd,HIDIOCGRAWINFO,&hrdi);
		if(hrdi.vendor == 0x1da8 && hrdi.product == 0x1301) {
			printf("Found device: %s\n", globbuf.gl_pathv[i]);
			path		=	strdup(globbuf.gl_pathv[i]);
			}
		close(fd);
	}
	return path;
}