问题
Using ioctl interface various info can be fetched. How do you get extra info like product name, class, vendor name, subsystem name etc?
There are couple of command line tools available such as:
1. lshw -C network
2. detecting nic and ports on systems loaded with linux
You can start a process and get the result but Is there any raw c/c++ method to get above mentioned information?
Cheers
Prashant
回答1:
All the information you seek is in /sys/bus/pci/devices/*/*
:
class
device
driver
modalias
subsystem
subsystem_device
subsystem_vendor
vendor
You can see how lspci(8)
reads through the files with strace -o /tmp/out lspci
, /tmp/out
will have plenty of details. (I don't know any easy way to restrict this to just the NICs; I think both lspci(8)
and the kernel have hard-coded lists of PCI ID -> name mappings.)
回答2:
Look in sysfs or procfs, unfortunately this information has a habit of being changed and so cannot be relied on :(
来源:https://stackoverflow.com/questions/5611124/get-ethernet-name-class-description-vendor-subsystem-etc-using-c-c-on-linu