LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Get Network Card name by C (https://www.linuxquestions.org/questions/linux-general-1/get-network-card-name-by-c-235655/)

Jamesminh 09-27-2004 02:05 AM

Get Network Card name by C
 
Dear all,

I am current working at network programming. And I get some trouble on the Network card info.

I don't know what api that I can used to get network card info (card name, vender id, vender name). I think this can't do by socket right? If not or have another way, please let me know you opinion.

Thank you so much for your help.
James.

btmiller 09-27-2004 02:47 AM

One easy way to tell the manufacturer is look at the first part of the MAC address, it's specific to manufacturer (you can see this if you do an ethereal sniff that shows the ethernet packets, for instance -- note MAC addresses can be reset, so this may not be reliable). Otherwise, it's kind of tough. You might want to look at the sources for ifconfig and mii-tool and see how they gather info (a strace suggests that many disgusting ioctls are involved). You may well have to be executing within the kernel to get full info.

Question for you: Why on earth do you actually want to do this? If you're not writing a network card driver, the low level nitty gritties of the ethernet card affect your programming nil. I suppose if you're writing an app that sends lots of data over a LAN, you might care about the speed the NIC has negotiated, but why let the flow control properties of TCP take care of this for you, in that case?

Of course, if you're just doing it to see if it can be done, more power to you! :D

maroonbaboon 09-27-2004 06:00 AM

The 'lspci' command gives you this information (probably /sbin/lspci). You could have a look at the source code. I guess it is must depend on the kernel's pci driver e.g.

kernel-source-2.6.7/drivers/pci/pci.c


All times are GMT -5. The time now is 03:09 AM.