View Full Version : use of SIOCSIFHWADDR in ioctl() to change mac address
shenoy
09-13-2006, 07:44 AM
I am getting the mac address displayed on the console using ioctl().....
not able to understand how to change that ....wre to write the new value?
RobSeace
09-13-2006, 07:41 PM
Not sure I understand your problem... To do it, you fill in the "ifr_hwaddr" member
of "struct ifreq" with the raw MAC address, then pass a pointer to that struct as the
argument to SIOCSIFHWADDR... See the source to "ifconfig" for an example usage...
(Or, just use "ifconfig" to do the address changing, unless you really need to do it
from your own code for some reason...)
mlampkin
09-16-2006, 02:27 AM
Um...
MAC addresses are assigned numbers... and really aren't supposed to be changed...
Having said that... there are some which can only be changed temporarily ( you really aren't changing the interface mac, just what the system sees it as )... some allow you to permanently change it... the latter is simply because of the way those interfaces were manufactured ( e.g. so could be programmed w/ mac after full material construction )...
But the thing is...
Even if the hardware allows it to be done ( and again - not all of them allow - at least a permanent - change )... the way you do it is ( at the lowest level ) interface / vendor specific ( which means driver dependent )... and the driver may not implement it all... so even an interface that allows the mac to be permanently changed, you may end up really just change it 'temporarily' instead of writing it out to your card...
Hmmm... I edited this to try to make it clearer but think I've done the opposite...
Anyway... here is a hint if you are having troubles with ifconfig or lower level functions... bring the interface DOWN before trying to change the mac... then change it... then bring it back up...
Michael
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.