ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
on my machine its not showing any entries.
Quote:
root@bond:/proc/net# cat arp
IP address HW type Flags HW address Mask Device
root@bond:/proc/net#
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:
less /proc/net/arp
IP address HW type Flags HW address Mask Device
iii.jjj.kkk.lll 0x1 0x2 00:50:8D:74:xx:xx * eth0
xxx.yyy.zzz.xxx 0x1 0x2 00:0D:72:66:xx:xx * eth0
(It's never a good idea to advertise an IP address or a MAC address, hence the "edits" to this sample output)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.