Created
September 8, 2010 15:47
-
-
Save philips/570317 to your computer and use it in GitHub Desktop.
pci-lookup.c
This file contains 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
#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