LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-19-2010, 04:49 AM   #1
shockproof
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
Lightbulb set eth0 mac address in smc91xx eeprom via C code


Hi guys.
I'm looking for any snippet to manage MAC address via C code in Linux.
I tried to write some code to change eth0 mac address writing it in smc911xx eeprom.

What I did is the following..


#... some includes...
...
int skfd;
struct ifreq ifr;

struct ethtool_eeprom eeprom;

void main()
{
unsigned char buff[100];
unsigned char *data_buff;
eeprom.len = 7;
eeprom.offset = 0;

if((skfd = socket(AF_INET,SOCK_DGRAM,0))<0)
{
perror("Error opening socket!!!");
exit(1);
}
strncpy(ifr.ifr_name,"eth0",IFNAMSIZ);

if(ioctl(skfd,SIOCGIFFLAGS,&ifr)<0)
{
perror("Error get ioctl!!!");
exit(1);
}
ifr.ifr_flags &= ~IFF_UP;
if(ioctl(skfd,SIOCSIFFLAGS,&ifr)<0)
{
perror("Error set ioctl!!!");
exit(1);
}

eeprom.cmd = ETHTOOL_SEEPROM;
memcpy(buff,&eeprom,sizeof(eeprom));
data_buff = buff + sizeof(eeprom);
data_buff[0] = 0xA5;
/*New mac address */
data_buff[1] = 0x00;
data_buff[2] = 0x00;
data_buff[3] = 0x22;
data_buff[4] = 0x33;
data_buff[5] = 0x44;
data_buff[6] = 0x66;
ifr.ifr_data = buff;

ioctl(skfd,SIOCETHTOOL,&ifr);

if(ioctl(skfd,SIOCGIFFLAGS,&ifr)<0)
{
perror("Error get ioctl!!!");
exit(1);
}
ifr.ifr_flags |= (IFF_UP|IFF_RUNNING);

if(ioctl(skfd,SIOCSIFFLAGS,&ifr)<0)
{
perror("Error set ioctl!!!");
exit(1);
}


}


Please help me, if you can!
Best regards.
 
Old 05-06-2010, 04:45 PM   #2
DragonSlayer48DX
Registered User
 
Registered: Dec 2006
Posts: 1,454
Blog Entries: 1

Rep: Reputation: 74
Hi, and welcome to LQ!

Thank you for marking your thread as "solved" when you found a solution to your problem. Would you mind posting the solution to help others in the future? Thanks.

Cheers
 
  


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
eth0: Device eth0 has different MAC address than expected,ignoring. lin1010 Linux - Networking 5 11-24-2010 07:30 AM
[SOLVED] Trying to set an alt. ip address - eth0:1 just replaces eth0 instead ECRocker Linux - Newbie 1 10-30-2009 12:07 PM
How to get my MAC Address using c code? analyze Programming 8 09-23-2007 10:54 AM
What file to modify to change a mac address or to save eth0 configuration ikw38 Linux - Networking 2 04-26-2006 04:52 PM
eth0 / 1 confused over MAC address?? Nickj Linux - Networking 3 08-22-2005 11:36 AM


All times are GMT -5. The time now is 06:49 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