Skip to content

Instantly share code, notes, and snippets.

@philips
Created September 8, 2010 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philips/570317 to your computer and use it in GitHub Desktop.
Save philips/570317 to your computer and use it in GitHub Desktop.
pci-lookup.c
#include <stdio.h>
#include "pci/pci.h"
/* Compile: gcc pci-lookup.c -lpci -o pci-lookup */
int main(int argc, char **argv)
{
struct pci_access *pacc;
struct pci_dev dev;
char namebuf[1024], *name;
int flags = PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE;
int i = 1;
if (argc < 3 || ((argc - 1) % 2 != 0)) {
printf ("Usage: ./pci-lookup 0x8086 0x151c 0x8086 0x1510\n");
return -1;
}
if (argc > 3)
flags |= PCI_LOOKUP_CACHE;
pacc = pci_alloc();
pci_init(pacc);
for (i = 1; i < argc - 1; i += 2) {
dev.vendor_id = strtol(argv[i], NULL, 16);
dev.device_id = strtol(argv[i+1], NULL, 16);
name = pci_lookup_name(pacc, namebuf, sizeof(namebuf), flags,
dev.vendor_id, dev.device_id);
printf("%04x %04x %s\n", dev.vendor_id, dev.device_id, name);
}
pci_cleanup(pacc);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment