91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 833B
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-11
  • 語言: 其他
  • 標簽: LinuxC??

資源簡介

linux C獲取PCI設備名和廠商名,編譯時加上-lpci

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
#include?

#define?PREPATH?“/sys/bus/pci/devices/“
int?get_pci_vendor_device_id(?char?*pciAddress?int?*vendor?int?*device?);
int?get_pci_name(?int?vendor?int?device?char?*name?);

int
main(?int?argc?char?**argv?)
{
int?vendor?device;
char?name[?256?]?=?{?0?};
if(?argc?!=?2?)
{
fprintf(?stderr?“usage:?%s?pciAddress\n“?argv[?0?]?);
return?-1;
}

if(?get_pci_vendor_device_id(?argv[?1?]?&vendor?&device?)?)?
{
fprintf(?stderr?“fail?to?get?vendor?and?device?id\n“?);
return?-1;
}
printf(?“vendor?id[?%x?]?device?id[?%x?]\n“?vendor?device?);

if(?get_pci_name(?vendor?device?name?)?)
{
fprintf(?stderr?“fail?to?get?pci?device?name\n“?);
return?-1;
}
return?0;
}


int?
get_pci_vendor_device_id(?char?*pciAddress?int?*vendor?int?*device?)
{
char?vendorPath[?256?]?=?{?0?};
char?devicePath[?256?]?=?{?0?};
char?buf[?256?]?=?{?0?};
int??fd?len;
strcpy(?vendorPath?PREPATH?);
strcat(?vendorPath?pciAddress?);
strcat(?vendorPath?“/“?);
strcpy(?devicePath?vendorPath?);

strcat(?vendorPath?“vendor“?);
strcat(?devicePath?“device“?);

if(?(?fd?=?open(?vendorPath?O_RDONLY?)?)? {
fprintf(?stderr?“path:?%s\n“?vendorPath?);
perror(?“open“?);
return?-1;
}

if(?(?len?=?read(?fd?buf?256?)?)?>?0?)
{
buf[?len?]?=?‘\0‘;
sscanf(?buf?“%x“?vendor?);
}
close(?fd?);

if(?(?fd?=?open(?devicePath?O_RDONLY?)?)? {
fprintf(?stderr?“path:?%s\n“?devicePath?);
perror(?“open“?);
return?-1;
}

if(?(?len?=?read(?fd?buf?256?)?)?>?0?)
{
buf[?len?]?=?‘\0‘;
sscanf(?buf?“%x“?device?);
}
close(?fd?);

return?0;
}

int?
get_pci_name(?int?vendor?int?device?char?*name?)
{
struct?pci_access?*pacc;
pacc?=?pci_alloc();
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?);
return?0;
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????2242??2016-02-03?16:04??PCIname\pci_name.c

?????目錄??????????0??2016-02-03?16:09??PCIname

-----------?---------??----------?-----??----

?????????????????2242????????????????????2


評論

共有 條評論