kernel随机生成MAC地址的接口

/**  * eth_random_addr - Generate software assigned random Ethernet address  

* @addr: Pointer to a six-byte array containing the Ethernet address  *  

* Generate a random Ethernet address (MAC) that is not multicast  

* and has the local assigned bit set.  */

static inline void eth_random_addr(u8 *addr)

{  

  get_random_bytes(addr, ETH_ALEN);  

  addr[0] &= 0xfe; /* clear multicast bit */  

  addr[0] |= 0x02; /* set local assignment bit (IEEE802) */

}

#define random_ether_addr(addr) eth_random_addr(addr)

 

/**
 * eth_hw_addr_random - Generate software assigned random Ethernet and
 * set device flag
 * @dev: pointer to net_device structure
 *
 * Generate a random Ethernet address (MAC) to be used by a net device
 * and set addr_assign_type so the state can be read by sysfs and be
 * used by userspace.
 */
static inline void eth_hw_addr_random(struct net_device *dev)
{
 dev->addr_assign_type = NET_ADDR_RANDOM;
 eth_random_addr(dev->dev_addr);
}

转载于:https://www.cnblogs.com/zxc2man/p/6760603.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值