get ethernet name, class, description vendor, subsystem, etc using c/c++ on linux based systems

前提是你 提交于 2019-12-12 02:26:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!