Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add random mac generator for g_ether so networking tools and scripts …
…on host side are easier to use/automate Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
- Loading branch information
1 parent
e4e0be4
commit 7f05c41
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
@file usb_moded-mac.c | ||
Copyright (C) 2013 Jolla. All rights reserved. | ||
@author: Philippe De Swert <philippe.deswert@jollamobile.com> | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the Lesser GNU General Public License | ||
version 2 as published by the Free Software Foundation. | ||
This program is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
You should have received a copy of the Lesser GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
02110-1301 USA | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "usb_moded-mac.h" | ||
|
||
static void random_ether_addr(unsigned char *addr) | ||
{ | ||
FILE *random; | ||
|
||
random = fopen("/dev/urandom", "r"); | ||
fread(addr, 1, 6, random); | ||
fclose(random); | ||
|
||
addr [0] &= 0xfe; /* clear multicast bit */ | ||
addr [0] |= 0x02; /* set local assignment bit (IEEE802) */ | ||
} | ||
|
||
void generate_random_mac (void) | ||
{ | ||
unsigned char addr[6]; | ||
int i; | ||
FILE *g_ether; | ||
|
||
printf("Getting random usb ethernet mac\n"); | ||
random_ether_addr(addr); | ||
|
||
g_ether = fopen("/etc/modprobe.d/g_ether.conf", "w"); | ||
fprintf(g_ether, "options g_ether host_addr="); | ||
|
||
for(i=0; i<5; i++) | ||
{ | ||
fprintf(g_ether, "%02x:",addr[i]); | ||
} | ||
fprintf(g_ether, "%02x",addr[i]); | ||
fclose(g_ether); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
@file usb_moded-mac.h | ||
Copyright (C) 2013 Jolla. All rights reserved. | ||
@author: Philippe De Swert <philippe.deswert@jollamobile.com> | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the Lesser GNU General Public License | ||
version 2 as published by the Free Software Foundation. | ||
This program is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
You should have received a copy of the Lesser GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
02110-1301 USA | ||
*/ | ||
|
||
void generate_random_mac (void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters