get mac address given a specific interface
Hi,
I'd like to get a mac address given a specific interface. How can i do this? A file of the system, the lines of which have the format "ethX mac" would be nice... However, i don't think it exists. Does anybody knoe how can i do this from C/glibc? Thanks |
hi,
highligted one's are the MAC of particular NIC. Quote:
|
If you wanted to get the info from a command, ifconfig will do it. Or, you could read from the /proc/net/arp file. See man proc(5) for more info.
I'd love to test it to see if it works, but I have only BSD boxen and unfortunately my NetBSD machine with the Linux emulation doesn't have a net/arp file in the emulated Linux proc filesystem. :( |
Quote:
Quote:
|
Hi -
The suggestion about parsing "ifconfig" is an excellent one. The way to do it from C/C++ would be with "popen ()" ("man 3 popen", search LQ, or Google for "popen()" samples). The suggestion about using "/proc" is also a good one (although AFAIK it'll only work on Linux). Here's /proc output from my system (I've got two NICs; both are DHCP-assigned, only one of them is plugged in; the other has a null IP): Quote:
'Hope that helps .. PSM |
Code:
#include <stdio.h> |
Thanks everybody. I will probably use some of randyding's code.
|
All times are GMT -5. The time now is 12:17 PM. |