41static void mac_random_ether_addr (
unsigned char *addr);
42void mac_generate_random_mac(
void);
43char *mac_read_mac (
void);
49static void mac_random_ether_addr(
unsigned char *addr)
56 random = fopen(
"/dev/urandom",
"r");
57 count = fread(addr, 1, 6, random);
66 log_warning(
"MAC generation failed!\n");
69void mac_generate_random_mac (
void)
73 unsigned char addr[6];
77 log_debug(
"Getting random usb ethernet mac\n");
78 mac_random_ether_addr(addr);
80 g_ether = fopen(
"/etc/modprobe.d/g_ether.conf",
"w");
83 log_warning(
"Failed to write mac address to /etc/modprobe.d/g_ether.conf\n");
86 fprintf(g_ether,
"options g_ether host_addr=");
90 fprintf(g_ether,
"%02x:",addr[i]);
92 fprintf(g_ether,
"%02x\n",addr[i]);
96char * mac_read_mac(
void)
101 char *mac = NULL, *ret = NULL;
105 g_ether = fopen(
"/etc/modprobe.d/g_ether.conf",
"r");
108 log_warning(
"Failed to read mac address from /etc/modprobe.d/g_ether.conf\n");
111 test = fseek(g_ether, 26, SEEK_SET);
119 read = fread(mac, 1, 17, g_ether);
121 ret = strndup(mac,17);