9
0
Fork 0

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:
Sascha Hauer 2010-06-11 14:12:12 +02:00
parent 7867ceb8dc
commit e7048e1862
1 changed files with 10 additions and 1 deletions

View File

@ -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);