vxworks如何修改mac地址
我这里有程序可以读到目标机的mac地址,可是我怎样去更改目标机的mac地址呢?请高人指点。附上读mac地址的代码,作为参考。
[code=C/C++]#include "vxWorks.h"
#include "stdio.h"
#include "netinet/in.h"
#include "net/if.h"
#include "netinet/if_ether.h"
#include "sys/ioctl.h"
#include "ioLib.h"
#include "inetLib.h"
#include "string.h"
#include "netinet/in_var.h"
#include "ipProto.h"
#include "end.h"
#include "private/muxLibP.h"
extern struct in_ifaddr* in_ifaddr;
int
getmac()
{
struct in_ifaddr* ia;
for (ia = in_ifaddr; ia != 0; ia = ia->ia_next)
{
struct ifnet* ifp = ia->ia_ifa.ifa_ifp;
if (ifp != 0)
{
int level;
IP_DRV_CTRL *pDrvCtrl;
END_OBJ *pEnd;
unsigned char PhyAddr[10];
if(ifp->if_type != M2_ifType_ethernetCsmacd)
{
continue;
}
level = intLock();
pDrvCtrl = (IP_DRV_CTRL *)ifp->pCookie;
pEnd = PCOOKIE_TO_ENDOBJ(pDrvCtrl->pIpCookie);
pEnd->pFuncTable->ioctl(pEnd, EIOCGADDR, PhyAddr);
printf("%x:%x:%x:%x:%x:%x\n", PhyAddr[0], PhyAddr[1], PhyAddr[2], PhyAddr[3], PhyAddr[4], PhyAddr[5]);
intUnlock(level);
}
}
}
/code]
[解决办法]
我以前用860时是修改启动配置存储在FLASH上然后下次启动生效,后来写网口驱动觉可调用ioctl,你既然都用ioctl EIOCGADDR命令读出来了,当然也可以写,只要驱动做了这部分程序,就可以改。标准的templateEnd.c驱动模板中就有EIOCSADDR,