net: use a random mac address if the current device does not have a valid address
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
7867ceb8dc
commit
e7048e1862
11
net/net.c
11
net/net.c
|
@ -345,12 +345,21 @@ static LIST_HEAD(connection_list);
|
|||
|
||||
static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
|
||||
{
|
||||
struct eth_device *edev = eth_get_current();
|
||||
struct net_connection *con;
|
||||
int ret;
|
||||
|
||||
if (!is_valid_ether_addr(net_ether))
|
||||
if (!edev)
|
||||
return ERR_PTR(-ENETDOWN);
|
||||
|
||||
if (!is_valid_ether_addr(net_ether)) {
|
||||
char str[sizeof("xx:xx:xx:xx:xx:xx")];
|
||||
random_ether_addr(net_ether);
|
||||
ethaddr_to_string(net_ether, str);
|
||||
printf("warning: No MAC address set. Using random address %s\n", str);
|
||||
dev_set_param(&edev->dev, "ethaddr", str);
|
||||
}
|
||||
|
||||
/* If we don't have an ip only broadcast is allowed */
|
||||
if (!net_ip && dest != 0xffffffff)
|
||||
return ERR_PTR(-ENETDOWN);
|
||||
|
|
Loading…
Reference in New Issue