Skip to content

Instantly share code, notes, and snippets.

@rakesh-gopal
Created January 7, 2015 15:17
Show Gist options
  • Save rakesh-gopal/12d4094e2b882b44cb1d to your computer and use it in GitHub Desktop.
Save rakesh-gopal/12d4094e2b882b44cb1d to your computer and use it in GitHub Desktop.
Unix code to list USB devices (lsusb equilent)
/*
* 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