LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 02-09-2006, 03:17 AM   #1
Madhusudhan
LQ Newbie
 
Registered: Feb 2006
Posts: 10

Rep: Reputation: 0
System call for getting MAC address


Hi All,

Can anybody tell me which system call to use to get the MAC address/Hardware address of the machine..

Same thing can be got by ifconfig -a but i need system call for the same to use in the program....

Thanks and regards,
Madhusudhan
 
Old 02-09-2006, 03:50 AM   #2
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 11, Sabayon 3.1
Posts: 1,464

Rep: Reputation: 46
why not use ifconfig then and 'awk' or 'cut' out the relevant data??

please provide such an output and i will explain how to do it...
 
Old 02-09-2006, 04:01 AM   #3
Madhusudhan
LQ Newbie
 
Registered: Feb 2006
Posts: 10

Original Poster
Rep: Reputation: 0
MAC address source code

Actually i wanted use it in a C program to get the MAC address.
So is there any way to get or else where to find the source code of the IFCONFIG ???

Can you please help me ??

thanks ,
Madhusudhan
 
Old 02-09-2006, 04:08 AM   #4
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 11, Sabayon 3.1
Posts: 1,464

Rep: Reputation: 46
oh thats's interesting. not sure to be honest. i thought you were shell scripting...

must be out there.... google? :-)
 
Old 02-09-2006, 04:32 AM   #5
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 53
This should work:

Open a socket
Prepare a ifreq structure with the name of the interface (eg eth0)
Pass the socket and the structure to ioctl , asking for ioctl SIOCGIFADDR
Then the MAC address is in ifreq.ifr_hwaddr, you can strcpy to your string
 
Old 02-09-2006, 09:06 PM   #6
Madhusudhan
LQ Newbie
 
Registered: Feb 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks a lot !!!!!!!!!!!!!!!
This worked ,
using ioctl we can do it...
infact i got entire program itself in LinuxQuestions.org > Forums > Non-*NIX Forums > Programming forum....
name of the Post is "read IP address in C module progarm" by linux_lover2005.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find an IP address from the MAC address of a remote machine ? jitz Linux - General 3 01-03-2006 07:55 AM
How to find IP address of a machine if I know their MAC Address dysenteryduke Linux - Networking 13 09-12-2005 10:21 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM
Setting IP Address to an Interface using System Call Kirthi Linux - Networking 1 01-30-2005 11:20 AM
DHCP Server MAC Address found, IP address not assigned wmburke Linux - Wireless Networking 17 11-17-2004 10:33 AM


All times are GMT -5. The time now is 04:01 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration