Listing 3. Sample EVIOCGID ioctl /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include int main (int argc, char **argv) { int fd = -1; struct input_id device_info; /* ioctl() requires a file descriptor, so we check we got one, and then open it */ if (argc != 2) { fprintf(stderr, "usage: %s event-device - probably /dev/input/event0\n", argv[0]); exit(1); } if ((fd = open(argv[1], O_RDONLY)) < 0) { perror("evdev open"); exit(1); } /* suck out some device information */ if(ioctl(fd, EVIOCGID, &device_info)) { perror("evdev ioctl"); } /* the EVIOCGID ioctl() returns input_devinfo * structure - see * So we work through the various elements, displaying * each of them */ printf("vendor 0x%04hx product 0x%04hx version 0x%04hx is on", device_info.vendor, device_info.product, device_info.version); switch ( device_info.bustype) { case BUS_PCI : printf(" a PCI bus\n"); break; case BUS_ISAPNP : printf(" a Plug-n-pray ISA bus\n"); break; case BUS_USB : printf(" a Universal Serial Bus\n"); break; case BUS_HIL : printf(" some weird PA-RISC Bus\n"); break; case BUS_ISA : printf(" a legacy ISA bus\n"); break; case BUS_I8042 : printf(" an I8042 (or similar) controller\n"); break; case BUS_XTKBD : printf(" a IBM XT bus\n"); break; case BUS_RS232 : printf(" a RS232 serial bus\n"); break; case BUS_GAMEPORT : printf(" a gameport\n"); break; case BUS_PARPORT : printf(" a parallel port\n"); break; case BUS_AMIGA : printf(" an Amiga unique interface\n"); break; case BUS_ADB : printf(" an Apple Desktop Bus\n"); break; case BUS_I2C : printf(" a inter-integrated circuit bus\n"); break; case BUS_HOST : printf(" a device on the main board\n"); break; default: printf(" an unknown bus type: 0x%04hx\n", device_info.bustype); } close(fd); exit(0); }