How to get my MAC Address using c code?
I'm trying to develop program that can get MAC Address by using c language, anyone can guide me or give example of code....Thank you!!!
|
I take it that a system call to /sbin/ifconfig isn't allowed? It certainly wouldn't be very portable or make nice code, but it would be fairly easy to implement.
|
i have to implement like a software to automatic send MAC Address to database, so i have to use c code to get the MAC Address.
|
Cribbed from the Sourceforge BACnet for Linux package:
Code:
/* LQanalyze.c: get MAC for specified interface Code:
LQanalyze eth0 |
Thank you!! so much...
|
What if there are - say - two ethernet cards in the machine? Would that be a problem to you? Or maybe you can be sure that there will only ever be one.
|
Quote:
|
I have another problem that i also write code for get the IP Address and the result is 127.0.0.1 T_T seem like it take the IP Address from local loop back, so i can't get MAC Address too. Could anyone help how to get eth0 instead of lo.
analyze@ubuntu:~/Desktop$ ifconfig eth0 Link encap:Ethernet HWaddr 00:16:D3:A4:F6:79 inet addr:192.168.1.33 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::216:d3ff:fea4:f679/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:499 errors:0 dropped:0 overruns:0 frame:0 TX packets:416 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:229934 (224.5 KiB) TX bytes:61790 (60.3 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:300 (300.0 b) TX bytes:300 (300.0 b) |
Quote:
|
All times are GMT -5. The time now is 07:39 PM. |