zoukankan      html  css  js  c++  java
  • 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);
    }

  • 相关阅读:
    线程
    简单排序
    SSM的整合
    SpringMVC中的拦截器、异常处理器
    SpringMVC的文件上传
    SpringMVC的数据响应和结果视图
    springMVC的常用注解
    SpringMVC入门
    Spring中声明式事务控制
    JdbcTemplate在spring中的使用
  • 原文地址:https://www.cnblogs.com/zxc2man/p/6760603.html
Copyright © 2011-2022 走看看