One, interface
Char *pci_lookup_name (struct pci_access *a, char *buf, intsize, int flags, ...) Pci_abi;
(/usr/include/pci/pci.h)
Second, describe
The VendorID of PCI devices (obtained from vendor files) can be read below the/sys/bus/pci/devices/<pci address> directory, DeviceId (obtained from device files), But the text description of the vendor and the text description of the device are not.
1 at the beginning of the time using LSPCI to obtain vendor and device text description, but low efficiency;
2) now use the Pci_lookup_name () interface to obtain the text description of vendor and device;
Pacc->id_lookup_mode = 0;
The default installed PCI development library must be initialized to 0 before calling Pci_lookup_name (). Otherwise, Pci_lookup_name () segment fault if the/usr/share/hwdata/pci.ids file does not exist, or if the description of the vendor ID (device ID) is not found in the Pci.ids file.
struct pci_access *pacc;
PACC = Pci_alloc ();
Pacc->id_lookup_mode = 0;
if (!pci_lookup_name (PACC, name, 256,
Pci_lookup_vendor,
vendor,device))
{
fprintf (stderr, "fail to Get PCI vendor\n ");
return-1;
}
printf ("Vendor:%s\n", name);
if (!pci_lookup_name (PACC, name, 256,
Pci_lookup_device,
vendor,device))
{
fprintf, stderr, " Fail to get PCI device\n ");
return-1;
}
printf ("Device:%s\n", name);
Pci_cleanup (PACC);
Third, sample output
Four, sample code
http://download.csdn.net/detail/qq123386926/9426785
Five, note
1) When compiling, add-lpci;
2) When the g++ is compiled, the header file is introduced
#ifdef __cplusplus
extern "C" {
#endif
#include <pci/pci.h>
#ifdef __cplusplus
}
#endif
Otherwise, the undefine symbol error will be reported when the interface inside the pci.h is invoked at runtime, even if the compilation is passed.