From e7048e1862a16866766a3584fe946012a206c110 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 11 Jun 2010 14:12:12 +0200 Subject: net: use a random mac address if the current device does not have a valid address Signed-off-by: Sascha Hauer --- net/net.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/net.c b/net/net.c index 4305c727f4..8d9959520c 100644 --- a/net/net.c +++ b/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); -- cgit v1.2.3