Created
January 7, 2015 15:17
-
-
Save rakesh-gopal/12d4094e2b882b44cb1d to your computer and use it in GitHub Desktop.
Unix code to list USB devices (lsusb equilent)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compile with -lusb | |
*/ | |
#include <stdio.h> | |
#include <usb.h> | |
main(){ | |
struct usb_bus *bus; | |
struct usb_device *dev; | |
usb_init(); | |
usb_find_busses(); | |
usb_find_devices(); | |
for (bus = usb_busses; bus; bus = bus->next) | |
for (dev = bus->devices; dev; dev = dev->next){ | |
printf("Trying device %s/%s\n", bus->dirname, dev->filename); | |
printf("\tID_VENDOR = 0x%04x\n", dev->descriptor.idVendor); | |
printf("\tID_PRODUCT = 0x%04x\n", dev->descriptor.idProduct); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment